/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/

var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/main.ts
var main_exports = {};
__export(main_exports, {
  default: () => EasyTypingPlugin
});
module.exports = __toCommonJS(main_exports);
var import_obsidian3 = require("obsidian");
var import_state = require("@codemirror/state");

// src/core.ts
var import_obsidian = require("obsidian");

// src/utils.ts
var DEBUG = true;
var print = (message, ...optionalParams) => {
  if (DEBUG) {
    console.log(message, ...optionalParams);
  }
};
function offsetToPos(doc, offset) {
  let line = doc.lineAt(offset);
  return { line: line.number - 1, ch: offset - line.from };
}
function getTypeStrOfTransac(tr) {
  let TransacTypeArray = [
    "EasyTyping.change",
    "EasyTyping.paste",
    "input.type.compose",
    "input.type",
    "input.paste",
    "input.drop",
    "input.complete",
    "input",
    "delete.selection",
    "delete.forward",
    "delete.backward",
    "delete.cut",
    "delete",
    "move.drop",
    "undo",
    "redo",
    "select.pointer"
  ];
  for (let i = 0; i < TransacTypeArray.length; i++) {
    if (tr.isUserEvent(TransacTypeArray[i]))
      return TransacTypeArray[i];
  }
  return "none";
}
function string2pairstring(s) {
  let cursorIdx = s.indexOf("|");
  let left = s.substring(0, cursorIdx);
  let right = s.substring(cursorIdx + 1);
  return { left, right };
}
function ruleStringList2RuleList(list) {
  let res = [];
  for (let i in list) {
    res[i] = { before: string2pairstring(list[i][0]), after: string2pairstring(list[i][1]) };
  }
  return res;
}
function stringDeleteAt(str, index) {
  return str.substring(0, index) + str.substring(index + 1);
}
function stringInsertAt(str, index, s) {
  return str.substring(0, index) + s + str.substring(index);
}
function isParamDefined(param) {
  return typeof param !== "undefined";
}
function showString(s) {
  return s.replace(/\n/g, "\\n");
}
function getHiddenObsidianConfig(app) {
  return app.vault.config;
}
var ObsidianSettings = class {
  constructor(app) {
    this.app = app;
  }
  isLegacyEditorEnabled() {
    const config = {
      legacyEditor: false,
      ...getHiddenObsidianConfig(this.app)
    };
    return config.legacyEditor;
  }
  isDefaultThemeEnabled() {
    const config = {
      cssTheme: "",
      ...getHiddenObsidianConfig(this.app)
    };
    return config.cssTheme === "";
  }
  getTabsSettings() {
    return {
      useTab: true,
      tabSize: 4,
      ...getHiddenObsidianConfig(this.app)
    };
  }
  getFoldSettings() {
    return {
      foldIndent: true,
      ...getHiddenObsidianConfig(this.app)
    };
  }
  getDefaultIndentChars() {
    const { useTab, tabSize } = this.getTabsSettings();
    return useTab ? "	" : new Array(tabSize).fill(" ").join("");
  }
};

// src/core.ts
var import_language = require("@codemirror/language");
var LineFormater = class {
  constructor() {
  }
  syntaxTreeNodeNameType(name) {
    if (name.contains("code") && !name.contains("link")) {
      return "code" /* code */;
    } else if (name.contains("math")) {
      return "formula" /* formula */;
    } else {
      return "text" /* text */;
    }
  }
  parseLineWithSyntaxTree(state, lineNum, regRegExp) {
    let linePartsOfTxtCodeFormula = [];
    let line = state.doc.line(lineNum);
    const tree = (0, import_language.syntaxTree)(state);
    let pos = line.from;
    let prevNodeType = "none" /* none */;
    let prevBeginIdx = 0;
    while (pos < line.to) {
      let node = tree.resolve(pos, 1);
      let curNodeType = this.syntaxTreeNodeNameType(node.name);
      if (prevNodeType == "none" /* none */) {
        prevNodeType = curNodeType;
        prevBeginIdx = 0;
      } else if (prevNodeType == curNodeType) {
      } else {
        linePartsOfTxtCodeFormula.push({
          content: line.text.substring(prevBeginIdx, pos - line.from),
          type: prevNodeType,
          begin: prevBeginIdx,
          end: pos - line.from,
          leftSpaceRequire: 0 /* none */,
          rightSpaceRequire: 0 /* none */
        });
        prevNodeType = curNodeType;
        prevBeginIdx = pos - line.from;
      }
      if (curNodeType == "text" /* text */) {
        pos++;
      } else {
        pos = node.to;
      }
      if (pos == line.to) {
        linePartsOfTxtCodeFormula.push({
          content: line.text.substring(prevBeginIdx, pos - line.from),
          type: prevNodeType,
          begin: prevBeginIdx,
          end: pos - line.from,
          leftSpaceRequire: 0 /* none */,
          rightSpaceRequire: 0 /* none */
        });
      }
    }
    let retArray = [];
    for (let i = 0; i < linePartsOfTxtCodeFormula.length; i++) {
      if (linePartsOfTxtCodeFormula[i].type != "text" /* text */) {
        retArray.push(linePartsOfTxtCodeFormula[i]);
      } else {
        let tempArray;
        if (isParamDefined(regRegExp))
          tempArray = splitTextWithLinkAndUserDefined(linePartsOfTxtCodeFormula[i].content, regRegExp);
        else
          tempArray = splitTextWithLinkAndUserDefined(linePartsOfTxtCodeFormula[i].content);
        tempArray.forEach((item) => {
          item.begin += linePartsOfTxtCodeFormula[i].begin;
          item.end += linePartsOfTxtCodeFormula[i].begin;
          retArray.push(item);
        });
      }
    }
    return retArray;
  }
  formatLineOfDoc(state, settings, fromB, toB, insertedStr) {
    let doc = state.doc;
    let line = doc.lineAt(fromB).text;
    let res = null;
    if (insertedStr.contains("\n")) {
      res = this.formatLine(state, doc.lineAt(fromB).number, settings, offsetToPos(doc, fromB).ch, offsetToPos(doc, fromB).ch);
    } else {
      res = this.formatLine(state, doc.lineAt(fromB).number, settings, offsetToPos(doc, toB).ch, offsetToPos(doc, fromB).ch);
    }
    if (res === null || res[2].length == 0)
      return null;
    let newline = stringInsertAt(res[0], res[1], "|");
    let changes = [];
    let offset = doc.lineAt(fromB).from;
    for (let changeItem of res[2]) {
      changes.push({
        changes: { from: offset + changeItem.begin, to: offset + changeItem.end, insert: changeItem.text },
        userEvent: "EasyTyping.change"
      });
    }
    if (insertedStr.contains("\n")) {
      console.log("insertStr", insertedStr);
      res[1] += insertedStr.length;
    }
    return [changes, { selection: { anchor: offset + res[1] }, userEvent: "EasyTyping.change" }];
  }
  formatLine(state, lineNum, settings, curCh, prevCh) {
    let line = state.doc.line(lineNum).text;
    let regNull = /^\s*$/g;
    if (regNull.test(line))
      return [line, curCh, []];
    let lineParts = settings.UserDefinedRegSwitch ? this.parseLineWithSyntaxTree(state, lineNum, settings.UserDefinedRegExp) : this.parseLineWithSyntaxTree(state, lineNum);
    if (settings.debug)
      console.log("line parts\n", lineParts);
    let linePartsOrigin = JSON.parse(JSON.stringify(lineParts));
    let inlineChangeList = [];
    let cursorLinePartIndex = -1;
    let cursorRelativeIndex = -1;
    let resultCursorCh = 0;
    for (let i = 0; i < lineParts.length; i++) {
      if (curCh > lineParts[i].begin && curCh <= lineParts[i].end) {
        cursorLinePartIndex = i;
        cursorRelativeIndex = curCh - lineParts[i].begin;
        if (lineParts[i].type === "text" /* text */) {
          lineParts[i].content = stringInsertAt(lineParts[i].content, cursorRelativeIndex, "\0");
        }
        break;
      }
    }
    let resultLine = "";
    let offset = 0;
    let prevPartType = "none" /* none */;
    let prevTextEndSpaceState = 0 /* none */;
    for (let i = 0; i < lineParts.length; i++) {
      if (i === 0 && lineParts[i].type === "text" /* text */ && settings.AutoCapital) {
        if (isParamDefined(prevCh) && cursorLinePartIndex != 0) {
        } else {
          let regFirstSentence = /^\s*(\- (\[[x ]\] )?)?“?[a-z\u0401\u0451\u0410-\u044f]/g;
          let regHeaderSentence = /^(#+ |>+ ?|“)[a-z\u0401\u0451\u0410-\u044f]/g;
          let textcopy = lineParts[0].content;
          let match = regFirstSentence.exec(textcopy);
          let matchHeader = regHeaderSentence.exec(textcopy);
          let dstCharIndex = -1;
          if (match) {
            dstCharIndex = regFirstSentence.lastIndex - 1;
          } else if (matchHeader) {
            dstCharIndex = regHeaderSentence.lastIndex - 1;
          }
          if (settings.AutoCapitalMode == "global" /* Globally */ || isParamDefined(prevCh) && dstCharIndex >= prevCh && dstCharIndex < curCh) {
          } else {
            dstCharIndex = -1;
          }
          if (dstCharIndex != -1) {
            lineParts[0].content = textcopy.substring(0, dstCharIndex) + textcopy.charAt(dstCharIndex).toUpperCase() + textcopy.substring(dstCharIndex + 1);
          }
        }
      }
      switch (lineParts[i].type) {
        case "text" /* text */:
          let insertSpace = function(content2, reg2, prevCh2, curCh2, offset2) {
            while (true) {
              let match = reg2.exec(content2);
              if (!match)
                break;
              let tempIndex = reg2.lastIndex - 1;
              if (isParamDefined(prevCh2) && tempIndex >= prevCh2 - offset2 && tempIndex < curCh2 - offset2) {
                content2 = content2.substring(0, tempIndex) + " " + content2.substring(tempIndex);
                curCh2 += 1;
              }
            }
            return [content2, curCh2];
          };
          let content = lineParts[i].content;
          if (settings.AutoCapital) {
            var reg = /[\.\?\!。！？]([\s]*)[a-z\u0401\u0451\u0410-\u044f]/g;
            while (true) {
              let match = reg.exec(content);
              if (!match)
                break;
              let tempIndex = reg.lastIndex - 1;
              let isSpaceDot = tempIndex - 2 < 0 || content.substring(tempIndex - 2, tempIndex) == " .";
              if (settings.AutoCapitalMode == "global" /* Globally */ && !isSpaceDot) {
                lineParts[i].content = content.substring(0, tempIndex) + content.charAt(tempIndex).toUpperCase() + content.substring(reg.lastIndex);
                content = lineParts[i].content;
              } else if (isParamDefined(prevCh) && tempIndex >= prevCh - offset && tempIndex < curCh - offset && !isSpaceDot) {
                lineParts[i].content = content.substring(0, tempIndex) + content.charAt(tempIndex).toUpperCase() + content.substring(reg.lastIndex);
                content = lineParts[i].content;
              }
            }
          }
          if (settings.ChineseEnglishSpace) {
            let reg1 = /([A-Za-z])([\u4e00-\u9fa5])/gi;
            let reg2 = /([\u4e00-\u9fa5])([A-Za-z])/gi;
            [content, curCh] = insertSpace(content, reg1, prevCh, curCh, offset);
            [content, curCh] = insertSpace(content, reg2, prevCh, curCh, offset);
          }
          if (settings.ChineseNumberSpace) {
            let reg2 = /([0-9])([\u4e00-\u9fa5])/g;
            let reg1 = /([\u4e00-\u9fa5])([0-9])/g;
            [content, curCh] = insertSpace(content, reg2, prevCh, curCh, offset);
            [content, curCh] = insertSpace(content, reg1, prevCh, curCh, offset);
          }
          if (settings.EnglishNumberSpace) {
            let reg2 = /([A-Za-z])(\d)/g;
            let reg1 = /(\d)([A-Za-z])/g;
            [content, curCh] = insertSpace(content, reg2, prevCh, curCh, offset);
            [content, curCh] = insertSpace(content, reg1, prevCh, curCh, offset);
          }
          if (settings.ChineseNoSpace) {
            let reg2 = /([\u4e00-\u9fa5，。、！；‘’《》]+)(\s+)([\u4e00-\u9fa5，。、！；‘’《》]+)/g;
            while (reg2.exec(content)) {
              lineParts[i].content = content.replace(reg2, "$1$3");
              content = lineParts[i].content;
            }
          }
          if (settings.PunctuationSpace) {
            {
              let reg2 = /([,\.;\?\!\)])([0-9A-Za-z\u0401\u0451\u0410-\u044f\u4e00-\u9fa5])|([A-Za-z0-9\u4e00-\u9fa5:,\.\?\!'"]+)(\()|[,\.;\?:!][\u4e00-\u9fa5]/gi;
              while (true) {
                let match = reg2.exec(content);
                if (!match)
                  break;
                let tempIndex = reg2.lastIndex - 1;
                let isSpaceDot = "!.?;,".contains(content.charAt(tempIndex - 1)) && (tempIndex - 2 < 0 && i == 0 || content.charAt(tempIndex - 2) == " ");
                let isNumPuncNum = /[,.]\d/.test(content.substring(tempIndex - 1, tempIndex + 1)) && (tempIndex - 2 < 0 || /\d/.test(content.charAt(tempIndex - 2)));
                if (settings.PunctuationSpaceMode == "global" /* Globally */ && !isSpaceDot && !isNumPuncNum) {
                  content = content.substring(0, tempIndex) + " " + content.substring(tempIndex);
                } else if (isParamDefined(prevCh) && tempIndex >= prevCh - offset && tempIndex < curCh - offset && !isSpaceDot && !isNumPuncNum) {
                  content = content.substring(0, tempIndex) + " " + content.substring(tempIndex);
                  curCh += 1;
                }
              }
              let reg22 = /(:)([A-Za-z0-9_]+[ ,\.\?\\\/;'"，。？；‘“”’、\[\]\-\{\}])/gi;
              lineParts[i].content = content.replace(reg22, "$1 $2");
              content = lineParts[i].content;
              let reg3 = /(:)(["'])/g;
              lineParts[i].content = content.replace(reg3, "$1 $2");
              content = lineParts[i].content;
            }
          }
          let regStrictSpaceStart = /^\0?\s/;
          let regStrictSpaceEnd = /\s\0?$/;
          let regStartWithSpace = /^\0?[\s,\.;\?\!，。；》？：:！~\*、（）"”\[\]\)\{\}]/;
          let regEndWithSpace = /[\s，。、：；？！（）~\*"《“\[\]\(\{\}]\0?$/;
          let txtStartSpaceSate = 0 /* none */;
          let txtEndSpaceState = 0 /* none */;
          if (regStartWithSpace.test(content) || content.startsWith("<br>")) {
            if (regStrictSpaceStart.test(content))
              txtStartSpaceSate = 2 /* strict */;
            else
              txtStartSpaceSate = 1 /* soft */;
          }
          if (regEndWithSpace.test(content) || content.endsWith("<br>")) {
            if (regStrictSpaceEnd.test(content))
              txtEndSpaceState = 2 /* strict */;
            else
              txtEndSpaceState = 1 /* soft */;
          }
          switch (prevPartType) {
            case "none" /* none */:
              break;
            case "code" /* code */:
              if (settings.InlineCodeSpaceMode > txtStartSpaceSate) {
                lineParts[i].content = " " + content;
                content = lineParts[i].content;
              }
              break;
            case "formula" /* formula */:
              if (settings.InlineFormulaSpaceMode > txtStartSpaceSate) {
                lineParts[i].content = " " + content;
                content = lineParts[i].content;
              }
              break;
            case "wikilink" /* wikilink */:
            case "mdlink" /* mdlink */:
              if (!settings.InlineLinkSmartSpace && settings.InlineLinkSpaceMode > txtStartSpaceSate) {
                lineParts[i].content = " " + content;
                content = lineParts[i].content;
              } else if (settings.InlineLinkSmartSpace && txtStartSpaceSate == 0 /* none */) {
                let charAtTextBegin = content.charAt(0);
                let regMdLinkEnd = /\]/;
                let charAtLinkEndIndex = lineParts[i - 1].content.search(regMdLinkEnd) - 1;
                let charAtLinkEnd = lineParts[i - 1].content.charAt(charAtLinkEndIndex);
                if (charAtLinkEnd === "[")
                  break;
                let twoNeighborChars = charAtLinkEnd + charAtTextBegin;
                let regNotNeedSpace = /[\u4e00-\u9fa5，。？：；”“’‘-）}][\u4e00-\u9fa5]/g;
                if (!regNotNeedSpace.test(twoNeighborChars)) {
                  lineParts[i].content = " " + content;
                  content = lineParts[i].content;
                }
              }
              break;
            case "user-defined" /* user */:
              if (lineParts[i - 1].rightSpaceRequire > txtStartSpaceSate) {
                lineParts[i].content = " " + content;
                content = lineParts[i].content;
              }
              break;
          }
          if (i === cursorLinePartIndex) {
            let reg2 = "\0";
            let n = content.search(reg2);
            resultCursorCh = offset + n;
            lineParts[i].content = stringDeleteAt(content, n);
          }
          resultLine += lineParts[i].content;
          offset += lineParts[i].content.length;
          prevPartType = "text" /* text */;
          prevTextEndSpaceState = txtEndSpaceState;
          break;
        case "code" /* code */:
          switch (prevPartType) {
            case "none" /* none */:
              break;
            case "text" /* text */:
              if (settings.InlineCodeSpaceMode > prevTextEndSpaceState) {
                lineParts[i - 1].content += " ";
                resultLine += " ";
                offset += 1;
              }
              break;
            case "code" /* code */:
              if (settings.InlineCodeSpaceMode > 0 /* none */) {
                inlineChangeList.push({
                  text: " ",
                  begin: lineParts[i].begin,
                  end: lineParts[i].begin,
                  origin: ""
                });
                resultLine += " ";
                offset += 1;
              }
              break;
            case "formula" /* formula */:
              if (settings.InlineCodeSpaceMode > 0 /* none */ || settings.InlineFormulaSpaceMode > 0 /* none */) {
                inlineChangeList.push({
                  text: " ",
                  begin: lineParts[i].begin,
                  end: lineParts[i].begin,
                  origin: ""
                });
                resultLine += " ";
                offset += 1;
              }
              break;
            case "mdlink" /* mdlink */:
            case "wikilink" /* wikilink */:
              if (settings.InlineCodeSpaceMode > 0 /* none */ || settings.InlineLinkSpaceMode > 0 /* none */) {
                inlineChangeList.push({
                  text: " ",
                  begin: lineParts[i].begin,
                  end: lineParts[i].begin,
                  origin: ""
                });
                resultLine += " ";
                offset += 1;
              }
              break;
            case "user-defined" /* user */:
              if (settings.InlineCodeSpaceMode > 0 /* none */ && lineParts[i - 1].rightSpaceRequire > 0 /* none */) {
                inlineChangeList.push({
                  text: " ",
                  begin: lineParts[i].begin,
                  end: lineParts[i].begin,
                  origin: ""
                });
                resultLine += " ";
                offset += 1;
              }
              break;
          }
          if (i === cursorLinePartIndex) {
            resultCursorCh = offset + cursorRelativeIndex;
          }
          resultLine += lineParts[i].content;
          offset += lineParts[i].content.length;
          prevPartType = "code" /* code */;
          prevTextEndSpaceState = 0 /* none */;
          break;
        case "formula" /* formula */:
          if (lineParts[i].content == "$\\qquad$") {
            prevPartType = "text" /* text */;
            prevTextEndSpaceState = 2 /* strict */;
            break;
          }
          switch (prevPartType) {
            case "none" /* none */:
              break;
            case "text" /* text */:
              if (settings.InlineFormulaSpaceMode > prevTextEndSpaceState) {
                lineParts[i - 1].content += " ";
                resultLine += " ";
                offset += 1;
              }
              break;
            case "code" /* code */:
              if (settings.InlineFormulaSpaceMode > 0 /* none */ || settings.InlineCodeSpaceMode > 0 /* none */) {
                inlineChangeList.push({
                  text: " ",
                  begin: lineParts[i].begin,
                  end: lineParts[i].begin,
                  origin: ""
                });
                resultLine += " ";
                offset += 1;
              }
              break;
            case "formula" /* formula */:
              if (settings.InlineCodeSpaceMode > 0 /* none */) {
                inlineChangeList.push({
                  text: " ",
                  begin: lineParts[i].begin,
                  end: lineParts[i].begin,
                  origin: ""
                });
                resultLine += " ";
                offset += 1;
              }
              break;
            case "mdlink" /* mdlink */:
            case "wikilink" /* wikilink */:
              if (settings.InlineFormulaSpaceMode > 0 /* none */ || settings.InlineLinkSpaceMode > 0 /* none */) {
                inlineChangeList.push({
                  text: " ",
                  begin: lineParts[i].begin,
                  end: lineParts[i].begin,
                  origin: ""
                });
                resultLine += " ";
                offset += 1;
              }
              break;
            case "user-defined" /* user */:
              if (settings.InlineFormulaSpaceMode > 0 /* none */ && lineParts[i - 1].rightSpaceRequire > 0 /* none */) {
                inlineChangeList.push({
                  text: " ",
                  begin: lineParts[i].begin,
                  end: lineParts[i].begin,
                  origin: ""
                });
                resultLine += " ";
                offset += 1;
              }
              break;
          }
          if (i === cursorLinePartIndex) {
            resultCursorCh = offset + cursorRelativeIndex;
          }
          resultLine += lineParts[i].content;
          offset += lineParts[i].content.length;
          prevPartType = "formula" /* formula */;
          prevTextEndSpaceState = 0 /* none */;
          break;
        case "mdlink" /* mdlink */:
        case "wikilink" /* wikilink */:
          switch (prevPartType) {
            case "none" /* none */:
              break;
            case "text" /* text */:
              if (prevTextEndSpaceState > settings.InlineLinkSpaceMode)
                break;
              if (settings.InlineLinkSpaceMode == 2 /* strict */ && prevTextEndSpaceState < 2 /* strict */) {
                lineParts[i - 1].content += " ";
                resultLine += " ";
                offset += 1;
              } else if (settings.InlineLinkSmartSpace && prevTextEndSpaceState == 0 /* none */) {
                let regNoNeedSpace = /[\u4e00-\u9fa5][\u4e00-\u9fa5]/g;
                let charAtTextEnd = lineParts[i - 1].content.charAt(lineParts[i - 1].content.length - 1);
                let charAtLinkBegin = "";
                if (lineParts[i].type == "wikilink" /* wikilink */) {
                  let regAlias = /\|/;
                  let charOfAliasBegin = lineParts[i].content.search(regAlias);
                  let beginIndex = 2;
                  if (lineParts[i].content.charAt(0) === "!")
                    beginIndex = 3;
                  if (charOfAliasBegin != -1) {
                    beginIndex = charOfAliasBegin + 1;
                  } else if (lineParts[i].content.charAt(beginIndex) == "#") {
                    beginIndex += 1;
                  }
                  charAtLinkBegin = lineParts[i].content.charAt(beginIndex);
                  if (charAtLinkBegin == "]")
                    break;
                } else {
                  let regMdLinkBegin = /\[/;
                  let charAtLinkBeginIndex = lineParts[i].content.search(regMdLinkBegin) + 1;
                  charAtLinkBegin = lineParts[i].content.charAt(charAtLinkBeginIndex);
                  if (charAtLinkBegin === "]")
                    break;
                }
                let twoNeighborChars = charAtTextEnd + charAtLinkBegin;
                if (!regNoNeedSpace.test(twoNeighborChars)) {
                  lineParts[i - 1].content += " ";
                  resultLine += " ";
                  offset += 1;
                }
              } else if (!settings.InlineLinkSmartSpace && settings.InlineLinkSpaceMode > prevTextEndSpaceState) {
                lineParts[i - 1].content += " ";
                resultLine += " ";
                offset += 1;
              }
              break;
            case "code" /* code */:
              if (settings.InlineLinkSpaceMode > 0 /* none */ || settings.InlineCodeSpaceMode > 0 /* none */) {
                inlineChangeList.push({
                  text: " ",
                  begin: lineParts[i].begin,
                  end: lineParts[i].begin,
                  origin: ""
                });
                resultLine += " ";
                offset += 1;
              }
              break;
            case "formula" /* formula */:
              if (settings.InlineLinkSpaceMode > 0 /* none */ || settings.InlineFormulaSpaceMode > 0 /* none */) {
                inlineChangeList.push({
                  text: " ",
                  begin: lineParts[i].begin,
                  end: lineParts[i].begin,
                  origin: ""
                });
                resultLine += " ";
                offset += 1;
              }
              break;
            case "mdlink" /* mdlink */:
            case "wikilink" /* wikilink */:
              if (settings.InlineLinkSpaceMode > 0 /* none */) {
                inlineChangeList.push({
                  text: " ",
                  begin: lineParts[i].begin,
                  end: lineParts[i].begin,
                  origin: ""
                });
                resultLine += " ";
                offset += 1;
              }
              break;
            case "user-defined" /* user */:
              if (lineParts[i - 1].rightSpaceRequire > 0 /* none */ && settings.InlineLinkSpaceMode > 0 /* none */) {
                inlineChangeList.push({
                  text: " ",
                  begin: lineParts[i].begin,
                  end: lineParts[i].begin,
                  origin: ""
                });
                resultLine += " ";
                offset += 1;
              }
          }
          if (i === cursorLinePartIndex) {
            resultCursorCh = offset + cursorRelativeIndex;
          }
          resultLine += lineParts[i].content;
          offset += lineParts[i].content.length;
          prevPartType = lineParts[i].type;
          prevTextEndSpaceState = 0 /* none */;
          break;
        case "user-defined" /* user */:
          switch (prevPartType) {
            case "none" /* none */:
              break;
            case "text" /* text */:
              if (lineParts[i].leftSpaceRequire > prevTextEndSpaceState) {
                lineParts[i - 1].content += " ";
                resultLine += " ";
                offset += 1;
              }
              break;
            case "code" /* code */:
              if (lineParts[i].leftSpaceRequire > 0 /* none */ && settings.InlineCodeSpaceMode > 0 /* none */) {
                inlineChangeList.push({
                  text: " ",
                  begin: lineParts[i].begin,
                  end: lineParts[i].begin,
                  origin: ""
                });
                resultLine += " ";
                offset += 1;
              }
              break;
            case "formula" /* formula */:
              if (lineParts[i].leftSpaceRequire > 0 /* none */ && settings.InlineFormulaSpaceMode > 0 /* none */) {
                inlineChangeList.push({
                  text: " ",
                  begin: lineParts[i].begin,
                  end: lineParts[i].begin,
                  origin: ""
                });
                resultLine += " ";
                offset += 1;
              }
              break;
            case "mdlink" /* mdlink */:
            case "wikilink" /* wikilink */:
              if (lineParts[i].leftSpaceRequire > 0 /* none */ && settings.InlineLinkSpaceMode > 0 /* none */) {
                inlineChangeList.push({
                  text: " ",
                  begin: lineParts[i].begin,
                  end: lineParts[i].begin,
                  origin: ""
                });
                resultLine += " ";
                offset += 1;
              }
              break;
            case "user-defined" /* user */:
              if (lineParts[i].leftSpaceRequire > 0 /* none */ && lineParts[i - 1].rightSpaceRequire > 0 /* none */) {
                inlineChangeList.push({
                  text: " ",
                  begin: lineParts[i].begin,
                  end: lineParts[i].begin,
                  origin: ""
                });
                resultLine += " ";
                offset += 1;
              }
              break;
          }
          if (i === cursorLinePartIndex) {
            resultCursorCh = offset + cursorRelativeIndex;
          }
          resultLine += lineParts[i].content;
          offset += lineParts[i].content.length;
          prevPartType = "user-defined" /* user */;
          prevTextEndSpaceState = 0 /* none */;
          break;
      }
    }
    for (let i = 0; i < lineParts.length; i++) {
      if (lineParts[i].type === "text" /* text */ && lineParts[i].content != linePartsOrigin[i].content) {
        inlineChangeList.push({
          text: lineParts[i].content,
          begin: linePartsOrigin[i].begin,
          end: linePartsOrigin[i].end,
          origin: linePartsOrigin[i].content
        });
      }
    }
    inlineChangeList = inlineChangeList.sort((a, b) => a.begin - b.begin);
    return [resultLine, resultCursorCh, inlineChangeList];
  }
};
function matchWithReg(text, regExp, type, inlineTypeArray, checkArray = false, leftSpaceRe = 0 /* none */, rightSpaceRe = 0 /* none */) {
  let retArray = inlineTypeArray;
  let matchArray = [];
  retArray = retArray.sort((a, b) => a.begin - b.begin);
  while (true) {
    let match = regExp.exec(text);
    if (!match)
      break;
    let valid = true;
    if (checkArray) {
      for (let i = 0; i < retArray.length; i++) {
        if (regExp.lastIndex > retArray[i].begin && retArray[i].end > match.index) {
          valid = false;
          break;
        }
      }
    }
    if (!valid)
      continue;
    matchArray.push({
      content: match[0],
      type,
      begin: match.index,
      end: regExp.lastIndex,
      leftSpaceRequire: leftSpaceRe,
      rightSpaceRequire: rightSpaceRe
    });
  }
  retArray = retArray.concat(matchArray);
  return retArray;
}
function matchWithAbbr(text, type, inlineTypeArray, checkArray = false) {
  let retArray = inlineTypeArray;
  let matchArray = [];
  retArray = retArray.sort((a, b) => a.begin - b.begin);
  let regAbbr = /([a-zA-Z]\.)+/g;
  while (true) {
    let match = regAbbr.exec(text);
    if (!match)
      break;
    let valid = true;
    let isInBlockBegin = match.index == 0;
    if (checkArray) {
      for (let i = 0; i < retArray.length; i++) {
        if (match.index == retArray[i].end) {
          isInBlockBegin = true;
        }
        if (regAbbr.lastIndex > retArray[i].begin && retArray[i].end > match.index) {
          valid = false;
          break;
        }
      }
    }
    if (!isInBlockBegin && valid) {
      let regChar = /[a-zA-Z0-9]/;
      if (regChar.test(text.charAt(match.index - 1))) {
        valid = false;
      }
    }
    if (!valid)
      continue;
    matchArray.push({
      content: match[0],
      type,
      begin: match.index,
      end: regAbbr.lastIndex,
      leftSpaceRequire: 0 /* none */,
      rightSpaceRequire: 0 /* none */
    });
  }
  retArray = retArray.concat(matchArray);
  return retArray;
}
function splitTextWithLinkAndUserDefined(text, regExps) {
  let retArray = [];
  let regWikiLink = /\!{0,2}\[\[[^\[\]]*?\]\]/g;
  let regMdLink = /\!{0,2}\[[^\[\]]*?\]\([^\s\)\(\[\]\{\}']*\)/g;
  retArray = matchWithReg(text, regWikiLink, "wikilink" /* wikilink */, retArray);
  retArray = matchWithReg(text, regMdLink, "mdlink" /* mdlink */, retArray);
  let regExpList = [];
  let leftSRequireList = [];
  let rightSRequireList = [];
  let regNull = /^\s*$/g;
  let regSRequire = /\|[\-=\+][\-=\+]$/;
  if (regExps) {
    let regs = regExps.split("\n");
    for (let i = 0; i < regs.length; i++) {
      if (regNull.test(regs[i]))
        continue;
      if (!regSRequire.test(regs[i]) || regs[i].length <= 3) {
        new import_obsidian.Notice("EasyTyping: \u7B2C" + String(i) + "\u884C\u81EA\u5B9A\u4E49\u6B63\u5219\u4E0D\u7B26\u5408\u89C4\u8303\n" + regs[i]);
        continue;
      }
      let regItem = regs[i].substring(0, regs[i].length - 3);
      let spaceReqString = regs[i].substring(regs[i].length - 3);
      let isValidReg = true;
      try {
        let regTemp = new RegExp(regItem, "g");
      } catch (error) {
        isValidReg = false;
        if (this.settings.debug) {
          new import_obsidian.Notice("EasuTyping: Bad RegExp:\n" + regItem);
        }
      }
      if (isValidReg) {
        regExpList.push(new RegExp(regItem, "g"));
        leftSRequireList.push(str2SpaceState(spaceReqString.charAt(1)));
        rightSRequireList.push(str2SpaceState(spaceReqString.charAt(2)));
      }
    }
    let regLen = regExpList.length;
    for (let i = 0; i < regLen; i++) {
      retArray = matchWithReg(text, regExpList[i], "user-defined" /* user */, retArray, true, leftSRequireList[i], rightSRequireList[i]);
    }
  }
  retArray = matchWithReg(text, /\d{1,2}:\d{1,2}(:\d{0,2}){0,1}/g, "user-defined" /* user */, retArray, true, 1 /* soft */, 0 /* none */);
  retArray = matchWithAbbr(text, "user-defined" /* user */, retArray, true);
  retArray = retArray.sort((a, b) => a.begin - b.begin);
  let textArray = [];
  let textBegin = 0;
  let textEnd = 0;
  for (let i = 0; i < retArray.length; i++) {
    if (textBegin < retArray[i].begin) {
      textEnd = retArray[i].begin;
      textArray.push({
        content: text.substring(textBegin, textEnd),
        type: "text" /* text */,
        begin: textBegin,
        end: textEnd,
        leftSpaceRequire: 0 /* none */,
        rightSpaceRequire: 0 /* none */
      });
    }
    textBegin = retArray[i].end;
  }
  if (textBegin != text.length) {
    textArray.push({
      content: text.substring(textBegin, text.length),
      type: "text" /* text */,
      begin: textBegin,
      end: text.length,
      leftSpaceRequire: 0 /* none */,
      rightSpaceRequire: 0 /* none */
    });
  }
  retArray = retArray.concat(textArray);
  retArray = retArray.sort((a, b) => a.begin - b.begin);
  return retArray;
}
function str2SpaceState(s) {
  switch (s) {
    case "+":
      return 2 /* strict */;
    case "=":
      return 1 /* soft */;
    case "-":
    default:
      return 0 /* none */;
  }
}
function string2SpaceState(s) {
  if (Number(s) == 0 /* none */)
    return 0 /* none */;
  if (Number(s) == 1 /* soft */)
    return 1 /* soft */;
  if (Number(s) == 2 /* strict */)
    return 2 /* strict */;
  return 0 /* none */;
}
function getPosLineType(state, pos) {
  const line = state.doc.lineAt(pos);
  let line_number = line.number;
  const tree = (0, import_language.ensureSyntaxTree)(state, line.to);
  const token = tree.resolve(line.from, 1).name;
  if (token.contains("table")) {
    return "table" /* table */;
  }
  if (token.contains("hmd-frontmatter")) {
    return "frontmatter" /* frontmatter */;
  }
  if (token.contains("math")) {
    for (let p = line.from + 1; p < line.to; p += 1) {
      if (!tree.resolve(p, 1).name.contains("math")) {
        return "text" /* text */;
      }
    }
    return "formula" /* formula */;
  } else if (token.contains("code") && token.contains("block")) {
    for (let p = line.from + 1; p < line.to; p += 1) {
      let t = tree.resolve(p, 1).name;
      if (!(t.contains("code") && t.contains("block"))) {
        return "text" /* text */;
      }
    }
    return "codeblock" /* codeblock */;
  } else if (token.contains("quote") && !token.contains("callout")) {
    let callout_start_line = -1;
    for (let l = line_number - 1; l >= 1; l -= 1) {
      let l_line = state.doc.line(l);
      let l_token = tree.resolve(l_line.from, 1).name;
      if (!l_token.contains("quote")) {
        break;
      }
      if (l_token.contains("callout")) {
        callout_start_line = l;
        break;
      }
    }
    if (callout_start_line == -1)
      return "text" /* text */;
    let is_code_block = false;
    let reset = false;
    let reg_code_begin = /^>+ ```/;
    let reg_code_end = /^>+ ```$/;
    for (let l = callout_start_line + 1; l <= line_number; l += 1) {
      let l_line = state.doc.line(l);
      if (reset) {
        is_code_block = false;
        reset = false;
      }
      if (is_code_block && reg_code_end.test(l_line.text)) {
        is_code_block = true;
        reset = true;
      } else if (!is_code_block && reg_code_begin.test(l_line.text)) {
        is_code_block = true;
      }
    }
    if (is_code_block) {
      return "codeblock" /* codeblock */;
    } else
      return "text" /* text */;
  } else if (token.contains("list")) {
    for (let p = line.from + 1; p < line.to; p += 1) {
      let t = tree.resolve(p, 1).name;
      if (t.contains("code") && t.contains("block")) {
        return "codeblock" /* codeblock */;
      }
    }
  }
  return "text" /* text */;
}
function getPosLineType2(state, pos) {
  const line = state.doc.lineAt(pos);
  const tree = (0, import_language.syntaxTree)(state);
  const token = tree.resolve(line.from, 1).name;
  if (token.contains("hmd-frontmatter")) {
    return "frontmatter" /* frontmatter */;
  }
  if (token.contains("math")) {
    for (let p = line.from + 1; p < line.to; p += 1) {
      if (!tree.resolve(p, 1).name.contains("math")) {
        return "text" /* text */;
      }
    }
    return "formula" /* formula */;
  } else if (token.contains("code") && token.contains("block")) {
    for (let p = line.from + 1; p < line.to; p += 1) {
      let t = tree.resolve(p, 1).name;
      if (!(t.contains("code") && t.contains("block"))) {
        return "text" /* text */;
      }
    }
    return "codeblock" /* codeblock */;
  }
  for (let p = line.from; p < line.to; p += 1) {
    if (tree.resolve(p, 1).name.contains("list")) {
      return "list" /* list */;
    } else if (tree.resolve(p, 1).name.contains("callout")) {
      return "callout_title" /* callout_title */;
    }
  }
  if (token.contains("quote")) {
    return "quote" /* quote */;
  }
  return "text" /* text */;
}

// src/settings.ts
var import_obsidian2 = require("obsidian");
var DEFAULT_SETTINGS = {
  Tabout: true,
  SelectionEnhance: true,
  IntrinsicSymbolPairs: true,
  BaseObEditEnhance: true,
  FW2HWEnhance: true,
  BetterCodeEdit: true,
  AutoFormat: true,
  ExcludeFiles: "",
  ChineseEnglishSpace: true,
  ChineseNumberSpace: true,
  EnglishNumberSpace: true,
  ChineseNoSpace: true,
  PunctuationSpace: true,
  AutoCapital: true,
  AutoCapitalMode: "typing" /* OnlyWhenTyping */,
  PunctuationSpaceMode: "typing" /* OnlyWhenTyping */,
  InlineCodeSpaceMode: 1 /* soft */,
  InlineFormulaSpaceMode: 1 /* soft */,
  InlineLinkSpaceMode: 1 /* soft */,
  InlineLinkSmartSpace: true,
  UserDefinedRegSwitch: true,
  UserDefinedRegExp: "{{.*?}}|++\n<.*?>|--\n\\[\\!.*?\\][-+]{0,1}|-+\n(file:///|https?://|ftp://|obsidian://|zotero://|www.)[^\\s\uFF08\uFF09\u300A\u300B\u3002,\uFF0C\uFF01\uFF1F;\uFF1B\uFF1A\u201C\u201D\u2018\u2019\\)\\(\\[\\]\\{\\}']+|--\n\n[a-zA-Z0-9_\\-.]+@[a-zA-Z0-9_\\-.]+|++\n(?<!#)#[\\u4e00-\\u9fa5\\w-\\/]+|++",
  debug: false,
  userSelRepRuleTrigger: ["-", "#"],
  userSelRepRuleValue: [{ left: "~~", right: "~~" }, { left: "#", right: " " }],
  userDeleteRulesStrList: [["demo|", "|"]],
  userConvertRulesStrList: [[":)|", "\u{1F600}|"]],
  userSelRuleSettingsOpen: true,
  userDelRuleSettingsOpen: true,
  userCvtRuleSettingsOpen: true,
  EnterTwice: false,
  TryFixChineseIM: true,
  PuncRectify: false,
  FixMacOSContextMenu: false,
  TryFixMSIME: false
};
var EasyTypingSettingTab = class extends import_obsidian2.PluginSettingTab {
  constructor(app, plugin) {
    super(app, plugin);
    this.plugin = plugin;
  }
  display() {
    const { containerEl } = this;
    containerEl.empty();
    containerEl.createEl("h1", { text: "Obsidian EasyTyping Plugin" });
    containerEl.createEl("p", { text: "More detail is in Github: " }).createEl("a", {
      text: "easy-typing-obsidian",
      href: "https://github.com/Yaozhuwa/easy-typing-obsidian"
    });
    containerEl.createEl("h2", { text: "\u589E\u5F3A\u7F16\u8F91\u8BBE\u7F6E (Enhanced Editing Setting)" });
    new import_obsidian2.Setting(containerEl).setName("Symbol auto pair and delete with pair").setDesc("\u589E\u52A0\u591A\u79CD\u7B26\u53F7\u914D\u5BF9\u8F93\u5165\uFF0C\u914D\u5BF9\u5220\u9664\uFF0C\u5982\u300A\u300B, \u201C\u201D, \u300C\u300D, \u300E\u300F,\u3010\u3011\u7B49").addToggle((toggle) => {
      toggle.setValue(this.plugin.settings.IntrinsicSymbolPairs).onChange(async (value) => {
        this.plugin.settings.IntrinsicSymbolPairs = value;
        await this.plugin.saveSettings();
      });
    });
    new import_obsidian2.Setting(containerEl).setName("Selection Replace Enhancement").setDesc("\u9009\u4E2D\u6587\u672C\u60C5\u51B5\u4E0B\u7684\u7F16\u8F91\u589E\u5F3A\uFF0C\u6309\uFFE5\u2192$\u9009\u4E2D\u7684\u6587\u672C$, \u6309\xB7\u2192`\u9009\u4E2D\u7684\u6587\u672C`\uFF0C\u300A \u2192 \u300A\u9009\u4E2D\u7684\u6587\u672C\u300B\u7B49\u7B49").addToggle((toggle) => {
      toggle.setValue(this.plugin.settings.SelectionEnhance).onChange(async (value) => {
        this.plugin.settings.SelectionEnhance = value;
        await this.plugin.saveSettings();
      });
    });
    new import_obsidian2.Setting(containerEl).setName("Convert successive full width symbol to half width symbol").setDesc("\u8FDE\u7EED\u8F93\u5165\u5168\u89D2\u7B26\u53F7\u8F6C\u534A\u89D2\uFF0C\u3002\u3002\u2192 .\uFF0C\uFF01\uFF01\u2192 !\uFF0C \u300B\u300B\u2192 >").addToggle((toggle) => {
      toggle.setValue(this.plugin.settings.FW2HWEnhance).onChange(async (value) => {
        this.plugin.settings.FW2HWEnhance = value;
        await this.plugin.saveSettings();
      });
    });
    new import_obsidian2.Setting(containerEl).setName("Basic symbol input enhance for obsidian").setDesc("Obsidian \u7684\u57FA\u7840\u8F93\u5165\u589E\u5F3A\uFF0C\u5982\u3010\u3010| \u2192 [[|]]\uFF0C\u53E5\u9996\u7684\u3001\u2192 /\uFF0C\u53E5\u9996\u7684\u300B\u2192 >\uFF0C\xB7\xB7| \u2192 `|`\uFF0C `\xB7|` \u53D8\u6210\u4EE3	\u7801\u5757\uFF0C\uFFE5\uFFE5| \u2192 $|$").addToggle((toggle) => {
      toggle.setValue(this.plugin.settings.BaseObEditEnhance).onChange(async (value) => {
        this.plugin.settings.BaseObEditEnhance = value;
        await this.plugin.saveSettings();
      });
    });
    new import_obsidian2.Setting(containerEl).setName("Enhance codeblock edit").setDesc("Improve editing in codeblock(Tab, delete, paste, cmd/ctrl+A select). \u589E\u5F3A\u4EE3\u7801\u5757\u5185\u7684\u7F16\u8F91\uFF08Cmd/Ctrl+A \u9009\u4E2D\u3001Tab\u3001\u5220\u9664\u3001\u7C98\u8D34\uFF09").addToggle((toggle) => {
      toggle.setValue(this.plugin.settings.BetterCodeEdit).onChange(async (value) => {
        this.plugin.settings.BetterCodeEdit = value;
        await this.plugin.saveSettings();
      });
    });
    new import_obsidian2.Setting(containerEl).setName("Tabout").setDesc("Tabout inline code or paired symbols(when selected). Tab \u8DF3\u51FA\u884C\u5185\u4EE3\u7801\u5757\u6216\u914D\u5BF9\u7B26\u53F7\u5757(\u9009\u4E2D\u65F6)").addToggle((toggle) => {
      toggle.setValue(this.plugin.settings.Tabout).onChange(async (value) => {
        this.plugin.settings.Tabout = value;
        await this.plugin.saveSettings();
      });
    });
    containerEl.createEl("h2", { text: "\u81EA\u5B9A\u4E49\u7F16\u8F91\u8F6C\u6362\u89C4\u5219 (Customize Edit Convertion Rule)" });
    this.buildUserSelRepRuleSetting(this.containerEl.createEl("details", {
      cls: "easytyping-nested-settings",
      attr: {
        ...this.plugin.settings.userSelRuleSettingsOpen ? { open: true } : {}
      }
    }));
    this.buildUserDeleteRuleSetting(this.containerEl.createEl("details", {
      cls: "easytyping-nested-settings",
      attr: {
        ...this.plugin.settings.userDelRuleSettingsOpen ? { open: true } : {}
      }
    }));
    this.buildUserConvertRuleSetting(this.containerEl.createEl("details", {
      cls: "easytyping-nested-settings",
      attr: {
        ...this.plugin.settings.userCvtRuleSettingsOpen ? { open: true } : {}
      }
    }));
    containerEl.createEl("h2", { text: "\u81EA\u52A8\u683C\u5F0F\u5316\u8BBE\u7F6E (Autoformat Setting)" });
    new import_obsidian2.Setting(containerEl).setName("Auto formatting when typing").setDesc("\u662F\u5426\u5728\u7F16\u8F91\u6587\u6863\u65F6\u81EA\u52A8\u683C\u5F0F\u5316\u6587\u672C\uFF0C\u81EA\u52A8\u683C\u5F0F\u5316\u7684\u603B\u5F00\u5173").addToggle((toggle) => {
      toggle.setValue(this.plugin.settings.AutoFormat).onChange(async (value) => {
        this.plugin.settings.AutoFormat = value;
        await this.plugin.saveSettings();
      });
    });
    containerEl.createEl("p", { text: "Detailed Setting Below" });
    new import_obsidian2.Setting(containerEl).setName("Space between Chinese and English").setDesc("\u5728\u4E2D\u6587\u548C\u82F1\u6587\u95F4\u7A7A\u683C").addToggle((toggle) => {
      toggle.setValue(this.plugin.settings.ChineseEnglishSpace).onChange(async (value) => {
        this.plugin.settings.ChineseEnglishSpace = value;
        await this.plugin.saveSettings();
      });
    });
    new import_obsidian2.Setting(containerEl).setName("Space between Chinese and Number").setDesc("\u5728\u4E2D\u6587\u548C\u6570\u5B57\u95F4\u7A7A\u683C").addToggle((toggle) => {
      toggle.setValue(this.plugin.settings.ChineseNumberSpace).onChange(async (value) => {
        this.plugin.settings.ChineseNumberSpace = value;
        await this.plugin.saveSettings();
      });
    });
    new import_obsidian2.Setting(containerEl).setName("Space between Engilsh and Number").setDesc("\u5728\u82F1\u6587\u548C\u6570\u5B57\u95F4\u7A7A\u683C").addToggle((toggle) => {
      toggle.setValue(this.plugin.settings.EnglishNumberSpace).onChange(async (value) => {
        this.plugin.settings.EnglishNumberSpace = value;
        await this.plugin.saveSettings();
      });
    });
    new import_obsidian2.Setting(containerEl).setName("Delete the Space between Chinese characters").setDesc("\u5728\u4E2D\u6587\u5B57\u7B26\u95F4\u53BB\u9664\u7A7A\u683C").addToggle((toggle) => {
      toggle.setValue(this.plugin.settings.ChineseNoSpace).onChange(async (value) => {
        this.plugin.settings.ChineseNoSpace = value;
        await this.plugin.saveSettings();
      });
    });
    new import_obsidian2.Setting(containerEl).setName("Capitalize the first letter of every sentence").setDesc("\u82F1\u6587\u6BCF\u4E2A\u53E5\u9996\u5B57\u6BCD\u5927\u5199").addDropdown((dropdown) => {
      dropdown.addOption("typing" /* OnlyWhenTyping */, "\u8F93\u5165\u65F6\u751F\u6548(Only When Typing)");
      dropdown.addOption("global" /* Globally */, "\u5168\u5C40\u751F\u6548(Work Globally)");
      dropdown.setValue(this.plugin.settings.AutoCapitalMode);
      dropdown.onChange(async (v) => {
        this.plugin.settings.AutoCapitalMode = v;
        await this.plugin.saveSettings();
      });
    }).addToggle((toggle) => {
      toggle.setTooltip("\u529F\u80FD\u5F00\u5173(Switch)");
      toggle.setValue(this.plugin.settings.AutoCapital).onChange(async (value) => {
        this.plugin.settings.AutoCapital = value;
        await this.plugin.saveSettings();
      });
    });
    new import_obsidian2.Setting(containerEl).setName("Smartly insert space between text and punctuation").setDesc("\u5728\u6587\u672C\u548C\u6807\u70B9\u95F4\u6DFB\u52A0\u7A7A\u683C").addDropdown((dropdown) => {
      dropdown.addOption("typing" /* OnlyWhenTyping */, "\u8F93\u5165\u65F6\u751F\u6548(Only When Typing)");
      dropdown.addOption("global" /* Globally */, "\u5168\u5C40\u751F\u6548(Work Globally)");
      dropdown.setValue(this.plugin.settings.PunctuationSpaceMode);
      dropdown.onChange(async (v) => {
        this.plugin.settings.PunctuationSpaceMode = v;
        await this.plugin.saveSettings();
      });
    }).addToggle((toggle) => {
      toggle.setValue(this.plugin.settings.PunctuationSpace).onChange(async (value) => {
        this.plugin.settings.PunctuationSpace = value;
        await this.plugin.saveSettings();
      });
    });
    new import_obsidian2.Setting(containerEl).setName("Space stategy between inline code and text").setDesc("\u5728 `\u884C\u5185\u4EE3\u7801` \u548C\u6587\u672C\u95F4\u7684\u7A7A\u683C\u7B56\u7565\u3002\u65E0\u8981\u6C42\uFF1A\u5BF9\u672C\u7C7B\u522B\u5757\u4E0E\u5DE6\u53F3\u6587\u672C\u6CA1\u6709\u7A7A\u683C\u7684\u8981\u6C42\uFF0C\u8F6F\u7A7A\u683C\uFF1A\u5BF9\u672C\u7C7B\u522B\u5757\u4E0E\u5468\u56F4\u533A\u5757\u53EA\u8981\u6C42\u6709\u8F6F\u7A7A\u683C\uFF0C\u8F6F\u7A7A\u683C\u5982\u5F53\u524D\u5757\u5DE6\u8FB9\u7684\u4E34\u8FD1\u6587\u672C\u4E3A\u3002\uFF0C\uFF1B\uFF1F\u7B49\u5168\u89D2\u6807\u70B9\uFF0C\u5F53\u524D\u5757\u53F3\u8FB9\u7684\u4E34\u8FD1\u6587\u672C\u4E3A\u6240\u6709\u5168\u534A\u89D2\u6807\u70B9\uFF0C\u4E25\u683C\u7A7A\u683C\uFF1A\u5F53\u524D\u5757\u4E0E\u4E34\u8FD1\u6587\u672C\u4E4B\u95F4\u4E25\u683C\u6DFB\u52A0\u7A7A\u683C\u3002").addDropdown((dropdown) => {
      dropdown.addOption(String(0 /* none */), "\u65E0\u8981\u6C42(No Require)");
      dropdown.addOption(String(1 /* soft */), "\u8F6F\u7A7A\u683C(Soft Space)");
      dropdown.addOption(String(2 /* strict */), "\u4E25\u683C\u7A7A\u683C(Strict Space)");
      dropdown.setValue(String(this.plugin.settings.InlineCodeSpaceMode));
      dropdown.onChange(async (v) => {
        this.plugin.settings.InlineCodeSpaceMode = string2SpaceState(v);
        await this.plugin.saveSettings();
      });
    });
    new import_obsidian2.Setting(containerEl).setName("Space stategy between inline formula and text").setDesc("\u5728 $\u884C\u5185\u516C\u5F0F$ \u548C\u6587\u672C\u95F4\u7684\u7A7A\u683C\u7B56\u7565").addDropdown((dropdown) => {
      dropdown.addOption(String(0 /* none */), "\u65E0\u8981\u6C42(No Require)");
      dropdown.addOption(String(1 /* soft */), "\u8F6F\u7A7A\u683C(Soft Space)");
      dropdown.addOption(String(2 /* strict */), "\u4E25\u683C\u7A7A\u683C(Strict Space)");
      dropdown.setValue(String(this.plugin.settings.InlineFormulaSpaceMode));
      dropdown.onChange(async (v) => {
        this.plugin.settings.InlineFormulaSpaceMode = string2SpaceState(v);
        await this.plugin.saveSettings();
      });
    });
    new import_obsidian2.Setting(containerEl).setName("Space strategy between link and text").setDesc("\u5728 [[wikilink]] [mdlink](...) \u548C\u6587\u672C\u95F4\u7A7A\u683C\u7B56\u7565\u3002\u667A\u80FD\u7A7A\u683C\u6A21\u5F0F\u4E0B\u5219\u4F1A\u8003\u8651\u8BE5\u94FE\u63A5\u5757\u7684\u663E\u793A\u5185\u5BB9\uFF08\u5982wiki\u94FE\u63A5\u7684\u522B\u540D\uFF09\u6765\u4E0E\u4E34\u8FD1\u6587\u672C\u8FDB\u884C\u7A7A\u683C\u3002").addDropdown((dropdown) => {
      dropdown.addOption("dummy", "\u5446\u7A7A\u683C(dummy)");
      dropdown.addOption("smart", "\u667A\u80FD\u7A7A\u683C(Smart)");
      dropdown.setValue(this.plugin.settings.InlineLinkSmartSpace ? "smart" : "dummy");
      dropdown.onChange(async (v) => {
        this.plugin.settings.InlineLinkSmartSpace = v == "smart" ? true : false;
        await this.plugin.saveSettings();
      });
    }).addDropdown((dropdown) => {
      dropdown.addOption(String(0 /* none */), "\u65E0\u8981\u6C42(No Require)");
      dropdown.addOption(String(1 /* soft */), "\u8F6F\u7A7A\u683C(Soft Space)");
      dropdown.addOption(String(2 /* strict */), "\u4E25\u683C\u7A7A\u683C(Strict Space)");
      dropdown.setValue(String(this.plugin.settings.InlineLinkSpaceMode));
      dropdown.onChange(async (v) => {
        this.plugin.settings.InlineLinkSpaceMode = string2SpaceState(v);
        await this.plugin.saveSettings();
      });
    });
    containerEl.createEl("h2", { text: "\u81EA\u5B9A\u4E49\u6B63\u5219\u533A\u5757 (Custom regular expressions block)" });
    new import_obsidian2.Setting(containerEl).setName("User Defined RegExp Switch").setDesc("\u81EA\u5B9A\u4E49\u6B63\u5219\u8868\u8FBE\u5F0F\u5F00\u5173\uFF0C\u5339\u914D\u5230\u7684\u5185\u5BB9\u4E0D\u8FDB\u884C\u683C\u5F0F\u5316\uFF0C\u4E14\u53EF\u4EE5\u8BBE\u7F6E\u5339\u914D\u5230\u7684\u5185\u5BB9\u5757\u4E0E\u5176\u4ED6\u5185\u5BB9\u4E4B\u95F4\u7684\u7A7A\u683C\u7B56\u7565").addToggle((toggle) => {
      toggle.setValue(this.plugin.settings.UserDefinedRegSwitch).onChange(async (value) => {
        this.plugin.settings.UserDefinedRegSwitch = value;
        await this.plugin.saveSettings();
      });
    });
    containerEl.createEl("p", { text: "\u6B63\u5219\u8868\u8FBE\u5F0F\u76F8\u5173\u77E5\u8BC6\uFF0C\u89C1 " }).createEl("a", {
      text: "\u300A\u962E\u4E00\u5CF0\uFF1A\u6B63\u5219\u8868\u8FBE\u5F0F\u7B80\u660E\u6559\u7A0B\u300B",
      href: "https://javascript.ruanyifeng.com/stdlib/regexp.html#"
    });
    containerEl.createEl("p", { text: "\u6B63\u5219\u8868\u8FBE\u5F0F\u89C4\u5219\u4F7F\u7528\u8BF4\u660E\u4E0E\u793A\u4F8B\uFF1A" }).createEl("a", {
      text: "\u81EA\u5B9A\u4E49\u6B63\u5219\u8868\u8FBE\u5F0F\u89C4\u5219",
      href: "https://github.com/Yaozhuwa/easy-typing-obsidian/blob/master/UserDefinedRegExp.md"
    });
    const regContentAreaSetting = new import_obsidian2.Setting(containerEl);
    regContentAreaSetting.settingEl.setAttribute("style", "display: grid; grid-template-columns: 1fr;");
    regContentAreaSetting.setName("User-defined Regular Expression, one expression per line").setDesc("\u7528\u6237\u81EA\u5B9A\u4E49\u6B63\u5219\u8868\u8FBE\u5F0F\uFF0C\u5339\u914D\u5230\u7684\u5185\u5BB9\u4E0D\u8FDB\u884C\u683C\u5F0F\u5316\uFF0C\u6BCF\u884C\u4E00\u4E2A\u8868\u8FBE\u5F0F\uFF0C\u884C\u5C3E\u4E0D\u8981\u968F\u610F\u52A0\u7A7A\u683C\u3002\u6BCF\u884C\u672B\u5C3E3\u4E2A\u5B57\u7B26\u7684\u56FA\u5B9A\u4E3A|\u548C\u4E24\u4E2A\u7A7A\u683C\u7B56\u7565\u7B26\u53F7\uFF0C\u7A7A\u683C\u7B56\u7565\u7B26\u53F7\u4E3A-=+\uFF0C\u5206\u522B\u4EE3\u8868\u4E0D\u8981\u6C42\u7A7A\u683C(-)\uFF0C\u8F6F\u7A7A\u683C(=)\uFF0C\u4E25\u683C\u7A7A\u683C(+)\u3002\u8FD9\u4E24\u4E2A\u7A7A\u683C\u7B56\u7565\u7B26\u53F7\u5206\u522B\u4E3A\u5339\u914D\u533A\u5757\u7684\u5DE6\u53F3\u4E24\u8FB9\u7684\u7A7A\u683C\u7B56\u7565");
    const regContentArea = new import_obsidian2.TextAreaComponent(regContentAreaSetting.controlEl);
    setAttributes(regContentArea.inputEl, {
      style: "margin-top: 12px; width: 100%;  height: 30vh;"
    });
    regContentArea.setValue(this.plugin.settings.UserDefinedRegExp).onChange(async (value) => {
      this.plugin.settings.UserDefinedRegExp = value;
      this.plugin.saveSettings();
    });
    containerEl.createEl("h2", { text: "\u6307\u5B9A\u6587\u4EF6\u4E0D\u81EA\u52A8\u683C\u5F0F\u5316 (Exclude Folders/Files)" });
    new import_obsidian2.Setting(containerEl).setName("Exclude Folders/Files").setDesc("This plugin will parse each line as a exlude folder or file. For example: DailyNote/, DailyNote/WeekNotes/, DailyNote/test.md").addTextArea((text) => text.setValue(this.plugin.settings.ExcludeFiles).onChange(async (value) => {
      this.plugin.settings.ExcludeFiles = value;
      this.plugin.saveSettings();
    }));
    containerEl.createEl("h2", { text: "Experimental Features" });
    new import_obsidian2.Setting(containerEl).setName("Fix MacOS context-menu cursor position(Need to restart Obsidian)").setDesc("\u4FEE\u590D MacOS \u9F20\u6807\u53F3\u952E\u547C\u51FA\u83DC\u5355\u65F6\u5149\u6807\u8DF3\u5230\u4E0B\u4E00\u884C\u7684\u95EE\u9898(\u9700\u8981\u91CD\u542FObsidian\u751F\u6548)").addToggle((toggle) => {
      toggle.setValue(this.plugin.settings.FixMacOSContextMenu).onChange(async (value) => {
        this.plugin.settings.FixMacOSContextMenu = value;
        await this.plugin.saveSettings();
      });
    });
    new import_obsidian2.Setting(containerEl).setName("Fix MicroSoft Input Method Issue").setDesc("\u9002\u914D\u65E7\u7248\u5FAE\u8F6F\u8F93\u5165\u6CD5").addToggle((toggle) => {
      toggle.setValue(this.plugin.settings.TryFixMSIME).onChange(async (value) => {
        this.plugin.settings.TryFixMSIME = value;
        await this.plugin.saveSettings();
      });
    });
    new import_obsidian2.Setting(containerEl).setName("Strict Line breaks Mode Enter Twice").setDesc("\u4E25\u683C\u6362\u884C\u7684\u8BBE\u7F6E\u4E0B\uFF0C\u5728\u666E\u901A\u6587\u672C\u884C\u8FDB\u884C\u4E00\u6B21\u56DE\u8F66\u4F1A\u4EA7\u751F\u4E24\u4E2A\u6362\u884C\u7B26").addToggle((toggle) => {
      toggle.setValue(this.plugin.settings.EnterTwice).onChange(async (value) => {
        this.plugin.settings.EnterTwice = value;
        await this.plugin.saveSettings();
      });
    });
    new import_obsidian2.Setting(containerEl).setName("Punc rectify").setDesc("\u4EC5\u5728\u8F93\u5165\u8FC7\u7A0B\u4E2D\uFF0C\u4E2D\u6587\u95F4\u7684\u82F1\u6587\u6807\u70B9\uFF08,.?!\uFF09\u81EA\u52A8\u8F6C\u6362\u4E3A\u5168\u89D2\uFF08\u53EF\u64A4\u9500\uFF09").addToggle((toggle) => {
      toggle.setValue(this.plugin.settings.PuncRectify).onChange(async (value) => {
        this.plugin.settings.PuncRectify = value;
        await this.plugin.saveSettings();
      });
    });
    new import_obsidian2.Setting(containerEl).setName("Print debug info in console").setDesc("\u5728\u63A7\u5236\u53F0\u8F93\u51FA\u8C03\u8BD5\u4FE1\u606F").addToggle((toggle) => {
      toggle.setValue(this.plugin.settings.debug).onChange(async (value) => {
        this.plugin.settings.debug = value;
        await this.plugin.saveSettings();
      });
    });
  }
  buildUserSelRepRuleSetting(containerEl) {
    containerEl.empty();
    containerEl.ontoggle = async () => {
      this.plugin.settings.userSelRuleSettingsOpen = containerEl.open;
      await this.plugin.saveSettings();
    };
    const summary = containerEl.createEl("summary", { cls: "easytyping-nested-settings" });
    summary.setText("\u81EA\u5B9A\u4E49\u9009\u4E2D\u6587\u672C\u7F16\u8F91\u589E\u5F3A\u89C4\u5219 (Customize Selection Replace Rule)");
    const selectionRuleSetting = new import_obsidian2.Setting(containerEl);
    selectionRuleSetting.setName("Selection Replece Rule");
    const replaceRuleTrigger = new import_obsidian2.TextComponent(selectionRuleSetting.controlEl);
    replaceRuleTrigger.setPlaceholder("Triggr Symbol");
    const replaceLeftString = new import_obsidian2.TextAreaComponent(selectionRuleSetting.controlEl);
    replaceLeftString.setPlaceholder("New Left Side String");
    const replaceRightString = new import_obsidian2.TextAreaComponent(selectionRuleSetting.controlEl);
    replaceRightString.setPlaceholder("New Right Side String");
    selectionRuleSetting.addButton((button) => {
      button.setButtonText("+").setTooltip("Add Rule").onClick(async (buttonEl) => {
        let trigger = replaceRuleTrigger.inputEl.value;
        let left = replaceLeftString.inputEl.value;
        let right = replaceRightString.inputEl.value;
        if (trigger && (left || right)) {
          if (trigger.length != 1 && trigger != "\u2014\u2014" && trigger != "\u2026\u2026") {
            new import_obsidian2.Notice("Inlvalid trigger, trigger must be a symbol of length 1 or symbol \u2014\u2014, \u2026\u2026");
            return;
          }
          if (this.plugin.addUserSelectionRepRule(trigger, left, right)) {
            await this.plugin.saveSettings();
            this.display();
          } else {
            new import_obsidian2.Notice("warning! Trigger " + trigger + " is already exist!");
          }
        } else {
          new import_obsidian2.Notice("missing input");
        }
      });
    });
    for (let i = 0; i < this.plugin.settings.userSelRepRuleTrigger.length; i++) {
      let trigger = this.plugin.settings.userSelRepRuleTrigger[i];
      let left_s = this.plugin.settings.userSelRepRuleValue[i].left;
      let right_s = this.plugin.settings.userSelRepRuleValue[i].right;
      let showStr = "Trigger: " + trigger + " \u2192 " + showString(left_s) + "selected" + showString(right_s);
      new import_obsidian2.Setting(containerEl).setName(showStr).addExtraButton((button) => {
        button.setIcon("gear").setTooltip("Edit rule").onClick(() => {
          new SelectRuleEditModal(this.app, trigger, left_s, right_s, async (new_left, new_right) => {
            this.plugin.updateUserSelectionRepRule(i, new_left, new_right);
            await this.plugin.saveSettings();
            this.display();
          }).open();
        });
      }).addExtraButton((button) => {
        button.setIcon("trash").setTooltip("Remove rule").onClick(async () => {
          this.plugin.deleteUserSelectionRepRule(i);
          await this.plugin.saveSettings();
          this.display();
        });
      });
    }
  }
  buildUserDeleteRuleSetting(containerEl) {
    containerEl.empty();
    containerEl.ontoggle = async () => {
      this.plugin.settings.userDelRuleSettingsOpen = containerEl.open;
      await this.plugin.saveSettings();
    };
    const summary = containerEl.createEl("summary", { cls: "easytyping-nested-settings" });
    summary.setText("\u81EA\u5B9A\u4E49\u5220\u9664\u7F16\u8F91\u589E\u5F3A\u89C4\u5219 (Customize Delete Rule)");
    const deleteRuleSetting = new import_obsidian2.Setting(containerEl);
    deleteRuleSetting.setName("Delete Rule").setDesc("\u89C4\u5219\uFF1A\u7528|\u4EE3\u8868\u5149\u6807\u4F4D\u7F6E\uFF0C\u5FC5\u987B\u5305\u542B\u5149\u6807\u3002 Tips: Using | to indicate the cursor position.");
    const patternBefore = new import_obsidian2.TextAreaComponent(deleteRuleSetting.controlEl);
    patternBefore.setPlaceholder("Before Delete");
    const patternAfter = new import_obsidian2.TextAreaComponent(deleteRuleSetting.controlEl);
    patternAfter.setPlaceholder("New Pattern");
    deleteRuleSetting.addButton((button) => {
      button.setButtonText("+").setTooltip("Add Rule").onClick(async (buttonEl) => {
        let before = patternBefore.inputEl.value;
        let after = patternAfter.inputEl.value;
        if (before && after) {
          let regRule = /\|/g;
          if (before.search(regRule) == -1 || after.search(regRule) == -1) {
            new import_obsidian2.Notice("Inlvalid trigger, pattern must contain symbol | which indicate cursor position");
            return;
          } else {
            this.plugin.addUserDeleteRule(before, after);
            await this.plugin.saveSettings();
            this.display();
          }
        } else {
          new import_obsidian2.Notice("missing input");
        }
      });
    });
    for (let i = 0; i < this.plugin.settings.userDeleteRulesStrList.length; i++) {
      let before = this.plugin.settings.userDeleteRulesStrList[i][0];
      let after = this.plugin.settings.userDeleteRulesStrList[i][1];
      let showStr = '"' + showString(before) + '"  delete.backwards  \u2192 "' + showString(after) + '"';
      new import_obsidian2.Setting(containerEl).setName(showStr).addExtraButton((button) => {
        button.setIcon("gear").setTooltip("Edit rule").onClick(() => {
          new EditConvertRuleModal(this.app, "Delete Rule" /* delete */, before, after, async (new_before, new_after) => {
            this.plugin.updateUserDeleteRule(i, new_before, new_after);
            await this.plugin.saveSettings();
            this.display();
          }).open();
        });
      }).addExtraButton((button) => {
        button.setIcon("trash").setTooltip("Remove rule").onClick(async () => {
          this.plugin.deleteUserDeleteRule(i);
          await this.plugin.saveSettings();
          this.display();
        });
      });
    }
  }
  buildUserConvertRuleSetting(containerEl) {
    containerEl.empty();
    containerEl.ontoggle = async () => {
      this.plugin.settings.userCvtRuleSettingsOpen = containerEl.open;
      await this.plugin.saveSettings();
    };
    const summary = containerEl.createEl("summary", { cls: "easytyping-nested-settings" });
    summary.setText("\u81EA\u5B9A\u4E49\u7F16\u8F91\u8F6C\u6362\u89C4\u5219 (Customize Convert Rule)");
    const convertRuleSetting = new import_obsidian2.Setting(containerEl);
    convertRuleSetting.setName("Convert Rule").setDesc("\u89C4\u5219\uFF1A\u7528|\u4EE3\u8868\u5149\u6807\u4F4D\u7F6E\uFF0C\u5FC5\u987B\u5305\u542B\u5149\u6807\u3002 Tips: Using | to indicate the cursor position.");
    const patternBefore = new import_obsidian2.TextAreaComponent(convertRuleSetting.controlEl);
    patternBefore.setPlaceholder("Before Convert");
    const patternAfter = new import_obsidian2.TextAreaComponent(convertRuleSetting.controlEl);
    patternAfter.setPlaceholder("New Pattern");
    convertRuleSetting.addButton((button) => {
      button.setButtonText("+").setTooltip("Add Rule").onClick(async (buttonEl) => {
        let before = patternBefore.inputEl.value;
        let after = patternAfter.inputEl.value;
        if (before && after) {
          let regRule = /\|/g;
          if (before.search(regRule) == -1 || after.search(regRule) == -1) {
            new import_obsidian2.Notice("Inlvalid trigger, pattern must contain symbol | which indicate cursor position");
            return;
          } else {
            this.plugin.addUserConvertRule(before, after);
            await this.plugin.saveSettings();
            this.display();
          }
        } else {
          new import_obsidian2.Notice("missing input");
        }
      });
    });
    for (let i = 0; i < this.plugin.settings.userConvertRulesStrList.length; i++) {
      let before = this.plugin.settings.userConvertRulesStrList[i][0];
      let after = this.plugin.settings.userConvertRulesStrList[i][1];
      let showStr = '"' + showString(before) + '"  auto convert to "' + showString(after) + '"';
      new import_obsidian2.Setting(containerEl).setName(showStr).addExtraButton((button) => {
        button.setIcon("gear").setTooltip("Edit rule").onClick(() => {
          new EditConvertRuleModal(this.app, "Convert Rule" /* convert */, before, after, async (new_before, new_after) => {
            this.plugin.updateUserConvertRule(i, new_before, new_after);
            await this.plugin.saveSettings();
            this.display();
          }).open();
        });
      }).addExtraButton((button) => {
        button.setIcon("trash").setTooltip("Remove rule").onClick(async () => {
          this.plugin.deleteUserConvertRule(i);
          await this.plugin.saveSettings();
          this.display();
        });
      });
    }
  }
};
function setAttributes(element, attributes) {
  for (let key in attributes) {
    element.setAttribute(key, attributes[key]);
  }
}
var SelectRuleEditModal = class extends import_obsidian2.Modal {
  constructor(app, trigger, left, right, onSubmit) {
    super(app);
    this.trigger = trigger;
    this.old_left = left;
    this.old_right = right;
    this.new_left = left;
    this.new_right = right;
    this.onSubmit = onSubmit;
  }
  onOpen() {
    const { contentEl } = this;
    contentEl.createEl("h1", { text: "Edit Selection Replace Rule" });
    new import_obsidian2.Setting(contentEl).setName("Trigger").addText((text) => {
      text.setValue(this.trigger);
      text.setDisabled(true);
    });
    new import_obsidian2.Setting(contentEl).setName("Left").addTextArea((text) => {
      text.setValue(this.old_left);
      text.onChange((value) => {
        this.new_left = value;
      });
    });
    new import_obsidian2.Setting(contentEl).setName("Right").addTextArea((text) => {
      text.setValue(this.old_right);
      text.onChange((value) => {
        this.new_right = value;
      });
    });
    new import_obsidian2.Setting(contentEl).addButton((btn) => btn.setButtonText("Update").setCta().onClick(() => {
      this.close();
      this.onSubmit(this.new_left, this.new_right);
    }));
  }
  onClose() {
    let { contentEl } = this;
    contentEl.empty();
  }
};
var EditConvertRuleModal = class extends import_obsidian2.Modal {
  constructor(app, type, before, after, onSubmit) {
    super(app);
    this.type = type;
    this.old_before = before;
    this.old_after = after;
    this.new_before = before;
    this.new_after = after;
    this.onSubmit = onSubmit;
  }
  onOpen() {
    const { contentEl } = this;
    contentEl.createEl("h1", { text: "Edit " + this.type });
    new import_obsidian2.Setting(contentEl).setName("Old Pattern").addTextArea((text) => {
      text.setValue(this.old_before);
      text.onChange((value) => {
        this.new_before = value;
      });
    });
    new import_obsidian2.Setting(contentEl).setName("New Pattern").addTextArea((text) => {
      text.setValue(this.old_after);
      text.onChange((value) => {
        this.new_after = value;
      });
    });
    new import_obsidian2.Setting(contentEl).addButton((btn) => btn.setButtonText("Update").setCta().onClick(() => {
      if (this.checkConvertPatternString(this.new_before, this.new_after)) {
        this.close();
        this.onSubmit(this.new_before, this.new_after);
      } else {
        new import_obsidian2.Notice("Invalid pattern string!");
      }
    }));
  }
  checkConvertPatternString(before, after) {
    let regRule = /\|/g;
    if (before.search(regRule) == -1 || after.search(regRule) == -1)
      return false;
    return true;
  }
  onClose() {
    let { contentEl } = this;
    contentEl.empty();
  }
};

// src/main.ts
var import_view = require("@codemirror/view");
var import_language2 = require("@codemirror/language");
var EasyTypingPlugin = class extends import_obsidian3.Plugin {
  constructor() {
    super(...arguments);
    this.transactionFilterPlugin = (tr) => {
      const changes = [];
      if (!tr.docChanged)
        return tr;
      let selected = tr.startState.selection.asSingle().main.anchor != tr.startState.selection.asSingle().main.head;
      let changeTypeStr = getTypeStrOfTransac(tr);
      tr.changes.iterChanges((fromA, toA, fromB, toB, inserted) => {
        var _a, _b;
        let changedStr = tr.startState.sliceDoc(fromA, toA);
        let changestr_ = changedStr.replace(/\s/g, "0");
        let insertedStr = inserted.sliceString(0);
        if (this.settings.debug) {
          console.log("[TransactionFilter] type, fromA, toA, changed, fromB, toB, inserted");
          console.log(changeTypeStr, fromA, toA, changedStr, fromB, toB, insertedStr);
        }
        if (getPosLineType(tr.startState, fromA) == "table" /* table */)
          return tr;
        if (this.settings.SelectionEnhance) {
          if ((changeTypeStr == "input.type" || changeTypeStr == "input.type.compose") && fromA != toA && (fromB + 1 === toB || insertedStr == "\u2014\u2014" || insertedStr == "\u2026\u2026")) {
            if (this.SelectionReplaceMap.has(insertedStr)) {
              changes.push({ changes: { from: fromA, insert: (_a = this.SelectionReplaceMap.get(insertedStr)) == null ? void 0 : _a.left }, userEvent: "EasyTyping.change" });
              changes.push({ changes: { from: toA, insert: (_b = this.SelectionReplaceMap.get(insertedStr)) == null ? void 0 : _b.right }, userEvent: "EasyTyping.change" });
              tr = tr.startState.update(...changes);
              return tr;
            }
          }
        }
        if (this.settings.BetterCodeEdit && changeTypeStr.contains("paste") && fromA == fromB && getPosLineType(tr.state, fromB) == "codeblock" /* codeblock */) {
          print("\u68C0\u6D4B\u5230\u5728\u4EE3\u7801\u5757\u4E2D\u7C98\u8D34");
          let line = tr.startState.doc.lineAt(fromB).text;
          let indent_space = line.match(/^\s*/)[0].length;
          let inserted_lines = insertedStr.split("\n");
          if (inserted_lines.length > 1) {
            let first_line = inserted_lines[0].trimStart();
            let rest_lines = inserted_lines.slice(1);
            let min_indent_space = Infinity;
            for (let line2 of rest_lines) {
              let indent = line2.match(/^\s*/)[0].length;
              if (indent < min_indent_space)
                min_indent_space = indent;
            }
            let new_rest_lines = rest_lines.map((line2) => line2.substring(min_indent_space));
            new_rest_lines = new_rest_lines.map((line2) => line2.replace(/[\t]/g, this.obsidianSettings.getDefaultIndentChars()));
            let final_rest_lines = new_rest_lines.map((line2) => " ".repeat(indent_space) + line2);
            let new_insertedStr = first_line + "\n" + final_rest_lines.join("\n");
            changes.push({
              changes: { from: fromA, to: toA, insert: new_insertedStr },
              selection: { anchor: fromA + new_insertedStr.length },
              userEvent: "EasyTyping.change"
            });
            tr = tr.startState.update(...changes);
            return tr;
          }
        }
        if (selected)
          return tr;
        if (this.settings.TryFixMSIME && changeTypeStr == "input.type.compose" && changedStr == "" && /^[\u4e00-\u9fa5]+$/.test(insertedStr)) {
          print("MS-IME Compose detected:", insertedStr);
          tr = tr.startState.update(...changes);
          return tr;
        }
        if (this.settings.BetterCodeEdit && changeTypeStr == "delete.backward" && !selected && getPosLineType(tr.startState, toA) == "codeblock" /* codeblock */ && (tr.startState.sliceDoc(fromA, toA) != "`" || getPosLineType(tr.state, fromA) == "codeblock" /* codeblock */)) {
          let line_number = tr.startState.doc.lineAt(toA).number;
          let cur_line = tr.startState.doc.lineAt(toA);
          let list_code = false;
          let list_code_indent = 0;
          for (let i = line_number - 1; i >= 1; i--) {
            let line = tr.startState.doc.line(i);
            if (/^\s+```/.test(line.text)) {
              list_code = true;
              list_code_indent = line.text.match(/^\s*/)[0].length;
              break;
            } else if (/^```/.test(line.text))
              break;
            else
              continue;
          }
          if (list_code) {
            print("list_code, indent: ", list_code_indent);
            if (toA == cur_line.from + list_code_indent) {
              changes.push({ changes: { from: tr.startState.doc.line(line_number - 1).to, to: toA, insert: "" }, userEvent: "EasyTyping.change" });
              tr = tr.startState.update(...changes);
              return tr;
            }
            if (fromA >= cur_line.from && fromA < cur_line.from + list_code_indent && toA > cur_line.from + list_code_indent) {
              changes.push({ changes: { from: cur_line.from + list_code_indent, to: toA, insert: "" }, userEvent: "EasyTyping.change" });
              tr = tr.startState.update(...changes);
              return tr;
            }
          }
        }
        if (changeTypeStr == "delete.backward") {
          for (let rule of this.UserDeleteRules) {
            let left = tr.startState.doc.sliceString(toA - rule.before.left.length, toA);
            let right = tr.startState.doc.sliceString(toA, toA + rule.before.right.length);
            if (left === rule.before.left && right === rule.before.right) {
              changes.push({
                changes: {
                  from: toA - rule.before.left.length,
                  to: toA + rule.before.right.length,
                  insert: rule.after.left + rule.after.right
                },
                selection: { anchor: toA - rule.before.left.length + rule.after.left.length },
                userEvent: "EasyTyping.change"
              });
              tr = tr.startState.update(...changes);
              return tr;
            }
          }
        }
        if (changeTypeStr === "delete.backward" && this.settings.IntrinsicSymbolPairs) {
          if (this.SymbolPairsMap.has(changedStr) && this.SymbolPairsMap.get(changedStr) === tr.startState.sliceDoc(toA, toA + 1)) {
            changes.push({ changes: { from: fromA, to: toA + 1 }, userEvent: "EasyTyping.change" });
            tr = tr.startState.update(...changes);
            return tr;
          }
          let line_content = tr.startState.doc.lineAt(toA).text;
          let next_line_content = tr.startState.doc.sliceString(toA, toA + line_content.length + 1);
          if (/^\s*```$/.test(line_content) && "\n" + line_content == next_line_content) {
            changes.push({
              changes: {
                from: toA - 3,
                to: toA + line_content.length + 1,
                insert: ""
              },
              selection: { anchor: toA - 3 },
              userEvent: "EasyTyping.change"
            });
            tr = tr.startState.update(...changes);
            return tr;
          }
          for (let rule of this.IntrinsicDeleteRules) {
            let left = tr.startState.doc.sliceString(toA - rule.before.left.length, toA);
            let right = tr.startState.doc.sliceString(toA, toA + rule.before.right.length);
            if (left === rule.before.left && right === rule.before.right) {
              changes.push({
                changes: {
                  from: toA - rule.before.left.length,
                  to: toA + rule.before.right.length,
                  insert: rule.after.left + rule.after.right
                },
                selection: { anchor: toA - rule.before.left.length + rule.after.left.length },
                userEvent: "EasyTyping.change"
              });
              tr = tr.startState.update(...changes);
              return tr;
            }
          }
        }
        if (changeTypeStr == "input.type" && insertedStr == "`\n```" && this.settings.BaseObEditEnhance) {
          const line_content = tr.startState.doc.lineAt(fromA).text;
          if (/^\s*``$/.test(line_content)) {
            changes.push({
              changes: { from: fromA, to: toA, insert: "`\n" + line_content + "`" },
              selection: { anchor: fromA + 1 },
              userEvent: "EasyTyping.change"
            });
            tr = tr.startState.update(...changes);
            return tr;
          }
        }
        if ((changeTypeStr == "input.type" || changeTypeStr == "input.type.compose") && fromA === toA && fromB + 1 === toB) {
          if (this.settings.BaseObEditEnhance) {
            if (insertedStr === "`" && toA - tr.startState.doc.lineAt(toA).from > 2 && tr.startState.sliceDoc(toA - 1, toA) === "`" && tr.startState.sliceDoc(toA - 2, toA - 1) != "`") {
              changes.push({
                changes: { from: toA, insert: "`" },
                selection: { anchor: toA },
                userEvent: "EasyTyping.change"
              });
              tr = tr.startState.update(...changes);
              return tr;
            }
            if (insertedStr == "\xB7") {
              let line_content = tr.startState.doc.lineAt(fromA).text;
              let ch_pos = fromA - tr.startState.doc.lineAt(fromA).from;
              if (/^\s*``$/.test(line_content) && ch_pos == line_content.length - 1) {
                changes.push({
                  changes: { from: fromA + 1, to: toA + 1, insert: "`\n" + line_content + "`" },
                  selection: { anchor: fromA + 2 },
                  userEvent: "EasyTyping.change"
                });
                tr = tr.startState.update(...changes);
                return tr;
              }
            }
            for (let rule of this.BasicConvRules) {
              if (insertedStr != rule.before.left.charAt(rule.before.left.length - 1))
                continue;
              if (rule.before.left.charAt(0) === "\n" && offsetToPos(tr.state.doc, fromA).line === 0 && toB - rule.before.left.length + 1 === 0) {
                let left = tr.state.doc.sliceString(toB - rule.before.left.length + 1, toB);
                let right = tr.state.doc.sliceString(toB, toB + rule.before.right.length);
                if (left === rule.before.left.substring(1) && right === rule.before.right) {
                  changes.push({
                    changes: {
                      from: toA - rule.before.left.length + 2,
                      to: toA + rule.before.right.length,
                      insert: rule.after.left.substring(1) + rule.after.right
                    },
                    selection: { anchor: toA - rule.before.left.length + rule.after.left.length + 1 },
                    userEvent: "EasyTyping.change"
                  });
                  tr = tr.startState.update(...changes);
                  return tr;
                }
              } else {
                let left = tr.state.doc.sliceString(toB - rule.before.left.length, toB);
                let right = tr.state.doc.sliceString(toB, toB + rule.before.right.length);
                if (left === rule.before.left && right === rule.before.right) {
                  changes.push({
                    changes: {
                      from: toA - rule.before.left.length + 1,
                      to: toA + rule.before.right.length,
                      insert: rule.after.left + rule.after.right
                    },
                    selection: { anchor: toA - rule.before.left.length + rule.after.left.length + 1 },
                    userEvent: "EasyTyping.change"
                  });
                  tr = tr.startState.update(...changes);
                  return tr;
                }
              }
            }
          }
          if (this.settings.FW2HWEnhance) {
            for (let rule of this.FW2HWSymbolRules) {
              if (insertedStr != rule.before.left.charAt(rule.before.left.length - 1))
                continue;
              let left = tr.state.doc.sliceString(toB - rule.before.left.length, toB);
              let right = tr.state.doc.sliceString(toB, toB + rule.before.right.length);
              if (left === rule.before.left && right === rule.before.right) {
                changes.push({
                  changes: {
                    from: toA - rule.before.left.length + 1,
                    to: toA + rule.before.right.length,
                    insert: rule.after.left + rule.after.right
                  },
                  selection: { anchor: toA - rule.before.left.length + rule.after.left.length + 1 },
                  userEvent: "EasyTyping.change"
                });
                tr = tr.startState.update(...changes);
                return tr;
              }
            }
          }
          if (this.settings.IntrinsicSymbolPairs) {
            for (let rule of this.IntrinsicAutoPairRulesPatch) {
              if (insertedStr != rule.before.left.charAt(rule.before.left.length - 1))
                continue;
              let left = tr.state.doc.sliceString(toB - rule.before.left.length, toB);
              let right = tr.state.doc.sliceString(toB, toB + rule.before.right.length);
              if (left === rule.before.left && right === rule.before.right) {
                changes.push({
                  changes: {
                    from: toA - rule.before.left.length + 1,
                    to: toA + rule.before.right.length,
                    insert: rule.after.left + rule.after.right
                  },
                  selection: { anchor: toA - rule.before.left.length + rule.after.left.length + 1 },
                  userEvent: "EasyTyping.change"
                });
                tr = tr.startState.update(...changes);
                return tr;
              }
            }
            if (this.SymbolPairsMap.has(insertedStr) && insertedStr != "'") {
              changes.push({
                changes: { from: fromA, to: toA, insert: insertedStr + this.SymbolPairsMap.get(insertedStr) },
                selection: { anchor: fromA + 1 },
                userEvent: "EasyTyping.change"
              });
              tr = tr.startState.update(...changes);
              return tr;
            } else if (insertedStr === "'") {
              let charBeforeCursor = tr.startState.sliceDoc(fromA - 1, fromA);
              if (["", " ", "\n"].includes(charBeforeCursor)) {
                changes.push({
                  changes: { from: fromA, to: toA, insert: "''" },
                  selection: { anchor: fromA + 1 },
                  userEvent: "EasyTyping.change"
                });
                tr = tr.startState.update(...changes);
                return tr;
              }
            }
            if (insertedStr === "\u201D" || insertedStr === "\u2019") {
              let tempStr = insertedStr === "\u201D" ? "\u201C\u201D" : "\u2018\u2019";
              changes.push({
                changes: { from: fromA, to: toA, insert: tempStr },
                selection: { anchor: fromA + 1 },
                userEvent: "EasyTyping.change"
              });
              tr = tr.startState.update(...changes);
              return tr;
            }
          }
        }
      });
      return tr;
    };
    this.viewUpdatePlugin = (update) => {
      if (this.onFormatArticle === true)
        return;
      let notSelected = true;
      let mainSelection = update.view.state.selection.asSingle().main;
      if (mainSelection.anchor != mainSelection.head)
        notSelected = false;
      if (!update.docChanged)
        return;
      let isExcludeFile = this.isCurrentFileExclude();
      let tr = update.transactions[0];
      let changeType = getTypeStrOfTransac(tr);
      tr.changes.iterChanges((fromA, toA, fromB, toB, inserted) => {
        let insertedStr = inserted.sliceString(0);
        let changedStr = tr.startState.doc.sliceString(fromA, toA);
        if (this.settings.debug) {
          console.log("[ViewUpdate] type, fromA, toA, changed, fromB, toB, inserted");
          console.log(changeType, fromA, toA, changedStr, fromB, toB, insertedStr);
          console.log("==>[Composing]", update.view.composing);
        }
        if (getPosLineType(update.view.state, fromB) == "table" /* table */) {
          return;
        }
        let cursor = update.view.state.selection.asSingle().main;
        if (update.view.composing) {
          if (this.compose_need_handle) {
            this.compose_end_pos = cursor.anchor;
          } else {
            this.compose_need_handle = true;
            this.compose_begin_pos = fromA;
            this.compose_end_pos = cursor.anchor;
          }
          return;
        }
        let change_from = fromB;
        let change_to = toB;
        if (this.compose_need_handle) {
          this.compose_need_handle = false;
          change_from = this.compose_begin_pos;
          change_to = this.compose_end_pos;
        }
        if (changeType.contains("EasyTyping") || changeType == "undo" || changeType == "redo")
          return;
        if (changeType != "none" && notSelected && !changeType.includes("delete")) {
          if (this.triggerUserCvtRule(update.view, mainSelection.anchor))
            return;
          if (this.triggerPuncRectify(update.view, change_from))
            return;
          if (this.settings.AutoFormat && notSelected && !isExcludeFile && (changeType != "none" || insertedStr == "\n")) {
            if (getPosLineType(update.view.state, change_from) == "text" /* text */ || getPosLineType(update.view.state, change_from) == "table" /* table */) {
              let changes = this.Formater.formatLineOfDoc(update.state, this.settings, change_from, cursor.anchor, insertedStr);
              if (changes != null) {
                update.view.dispatch(...changes[0]);
                update.view.dispatch(changes[1]);
                return;
              }
            }
          }
        }
        if (this.settings.AutoFormat && !isExcludeFile && changeType == "input.paste" && !import_obsidian3.Platform.isIosApp) {
          let updateLineStart = update.state.doc.lineAt(fromB).number;
          let updateLineEnd = update.state.doc.lineAt(toB).number;
          if (updateLineStart == updateLineEnd && getPosLineType(update.view.state, toB) == "text" /* text */) {
            let changes = this.Formater.formatLineOfDoc(update.state, this.settings, fromB, toB, insertedStr);
            if (changes != null) {
              update.view.dispatch(...changes[0]);
              return;
            }
          } else {
            let all_changes = [];
            let inserted_array = insertedStr.split("\n");
            let update_start = fromB;
            for (let i = updateLineStart; i <= updateLineEnd; i++) {
              let real_inserted = inserted_array[i - updateLineStart];
              let changes = this.Formater.formatLineOfDoc(update.state, this.settings, update_start, update_start + real_inserted.length, real_inserted);
              if (changes != null) {
                all_changes.push(...changes[0]);
              }
              update_start += real_inserted.length + 1;
            }
            if (all_changes.length > 0) {
              update.view.dispatch(...all_changes);
              return;
            }
          }
        }
      });
    };
    this.handleTabDown = (view) => {
      if (!this.settings.Tabout)
        return false;
      let state = view.state;
      let doc = state.doc;
      const tree = (0, import_language2.syntaxTree)(state);
      const s = view.state.selection;
      if (s.ranges.length > 1)
        return false;
      const pos = s.main.to;
      let line = doc.lineAt(pos);
      if (s.main.from == s.main.to && getPosLineType(view.state, s.main.from) == "codeblock" /* codeblock */) {
        view.dispatch({
          changes: {
            from: s.main.from,
            insert: this.obsidianSettings.getDefaultIndentChars()
          },
          selection: {
            anchor: s.main.from + this.obsidianSettings.getDefaultIndentChars().length
          }
        });
        return true;
      }
      if (this.settings.BetterCodeEdit && pos - line.from != 0 && tree.resolve(pos - 1, 1).name.contains("inline-code")) {
        if (tree.resolve(pos, 1).name.contains("formatting-code_inline-code")) {
          view.dispatch({
            selection: { anchor: pos + 1, head: pos + 1 }
          });
          return true;
        }
        for (let p = pos + 1; p < line.to && tree.resolve(p, 1).name.contains("inline-code"); p += 1) {
          if (tree.resolve(p, 1).name.contains("formatting-code_inline-code")) {
            view.dispatch({
              selection: { anchor: p, head: p }
            });
            return true;
          }
          if (p == line.to - 1 && tree.resolve(p, 1).name.contains("inline-code")) {
            view.dispatch({
              selection: { anchor: p + 1, head: p + 1 }
            });
            return true;
          }
        }
      }
      let selection = view.state.selection.asSingle().main;
      let selected = selection.anchor != selection.head;
      if (selected) {
        let new_anchor = selection.anchor < selection.head ? selection.anchor : selection.head;
        let new_head = selection.anchor > selection.head ? selection.anchor : selection.head;
        for (let pstr of this.TaboutPairStrs) {
          if (doc.sliceString(new_anchor - pstr.left.length, new_anchor) == pstr.left && doc.sliceString(new_head, new_head + pstr.right.length) == pstr.right) {
            view.dispatch({
              selection: { anchor: new_head + pstr.right.length, head: new_head + pstr.right.length }
            });
            return true;
          }
        }
      }
      return false;
    };
    this.handleEnter = (view) => {
      if (!this.settings.EnterTwice)
        return false;
      let strictLineBreaks = this.app.vault.getConfig("strictLineBreaks");
      if (!strictLineBreaks)
        return false;
      let state = view.state;
      let doc = state.doc;
      const tree = (0, import_language2.syntaxTree)(state);
      const s = view.state.selection;
      if (s.ranges.length > 1)
        return false;
      const pos = s.main.to;
      let line = doc.lineAt(pos);
      if (/^\s*$/.test(line.text))
        return false;
      else if (getPosLineType2(state, pos) == "text" /* text */) {
        view.dispatch({
          changes: {
            from: pos,
            to: pos,
            insert: "\n\n"
          },
          selection: { anchor: pos + 2 },
          userEvent: "EasyTyping.change"
        });
        return true;
      }
      return false;
    };
    this.handleModAInCodeBlock = (view) => {
      if (!this.settings.BetterCodeEdit)
        return false;
      let selected = false;
      let mainSelection = view.state.selection.asSingle().main;
      if (mainSelection.anchor != mainSelection.head)
        selected = true;
      if (selected)
        return false;
      let cursor_pos = mainSelection.anchor;
      if (getPosLineType(view.state, cursor_pos) != "codeblock" /* codeblock */)
        return false;
      let cursor_line = view.state.doc.lineAt(cursor_pos).number;
      let code_start_line = cursor_line;
      let code_end_line = cursor_line;
      for (let i = cursor_line - 1; i >= 1; i--) {
        if (getPosLineType(view.state, view.state.doc.line(i).from) != "codeblock" /* codeblock */)
          break;
        code_start_line = i;
      }
      for (let i = cursor_line + 1; i <= view.state.doc.lines; i++) {
        if (getPosLineType(view.state, view.state.doc.line(i).from) != "codeblock" /* codeblock */)
          break;
        code_end_line = i;
      }
      let anchor = view.state.doc.line(code_start_line + 1).from;
      let offset = 0;
      let start_line_string = view.state.doc.line(code_start_line + 1).text;
      if (!/^\s+$/.test(start_line_string)) {
        let reg_spaces = /^\s+/;
        let new_line_string = start_line_string.replace(reg_spaces, "");
        offset = start_line_string.length - new_line_string.length;
      }
      view.dispatch({
        selection: {
          anchor: anchor + offset,
          head: view.state.doc.line(code_end_line - 1).to
        }
      });
      return true;
    };
    this.onKeyup = (event, view) => {
      if (this.settings.debug) {
        console.log("Keyup:", event.key);
      }
      this.handleEndComposeTypeKey(event, view);
    };
    this.triggerUserCvtRule = (view, cursor_pos) => {
      for (let rule of this.UserConvertRules) {
        let left = view.state.doc.sliceString(cursor_pos - rule.before.left.length, cursor_pos);
        let right = view.state.doc.sliceString(cursor_pos, cursor_pos + rule.before.right.length);
        let inserted = rule.after.left + rule.after.right;
        let anchor = cursor_pos - rule.before.left.length + rule.after.left.length;
        let from = cursor_pos - rule.before.left.length;
        let to = cursor_pos + rule.before.right.length;
        if (rule.before.left.charAt(0) === "\n" && rule.after.left.charAt(0) === "\n" && cursor_pos - rule.before.left.length + 1 == 0) {
          left = "\n" + left;
          inserted = inserted.substring(1);
          from = 0;
        }
        if (left === rule.before.left && right === rule.before.right) {
          view.dispatch({
            changes: {
              from,
              to,
              insert: inserted
            },
            selection: { anchor },
            userEvent: "EasyTyping.change"
          });
          return true;
        }
      }
      return false;
    };
    this.triggerPuncRectify = (view, change_from_pos) => {
      if (this.settings.PuncRectify && /[,.?!]/.test(view.state.doc.sliceString(change_from_pos - 1, change_from_pos))) {
        let punc = view.state.doc.sliceString(change_from_pos - 1, change_from_pos);
        if (change_from_pos > 2 && /[\s\n\w]/.test(view.state.doc.sliceString(change_from_pos - 2, change_from_pos - 1))) {
        } else {
          view.dispatch({
            changes: {
              from: change_from_pos - 1,
              to: change_from_pos,
              insert: this.halfToFullSymbolMap.get(punc)
            },
            userEvent: "EasyTyping.change"
          });
          return true;
        }
      }
      return false;
    };
    this.handleEndComposeTypeKey = (event, view) => {
      if ((["Enter", "Process", " ", "Shift"].contains(event.key) || /\d/.test(event.key)) && this.compose_need_handle) {
        let cursor = view.state.selection.asSingle().main;
        if (getPosLineType(view.state, cursor.anchor) != "text" /* text */)
          return;
        if (cursor.head != cursor.anchor)
          return;
        let insertedStr = view.state.doc.sliceString(this.compose_begin_pos, cursor.anchor);
        this.compose_need_handle = false;
        if (this.triggerUserCvtRule(view, cursor.anchor))
          return;
        if (this.triggerPuncRectify(view, this.compose_begin_pos))
          return;
        if (this.settings.AutoFormat && !this.isCurrentFileExclude()) {
          let changes = this.Formater.formatLineOfDoc(view.state, this.settings, this.compose_begin_pos, cursor.anchor, insertedStr);
          if (changes != null) {
            view.dispatch(...changes[0]);
            view.dispatch(changes[1]);
            return;
          }
        }
      }
    };
    this.formatArticle = (editor, view) => {
      const editorView = editor.cm;
      const tree = (0, import_language2.ensureSyntaxTree)(editorView.state, editorView.state.doc.length);
      if (!tree) {
        new import_obsidian3.Notice("EasyTyping: Syntax tree is not ready yet, please wait a moment and try again later!", 5e3);
        return;
      }
      this.onFormatArticle = true;
      let lineCount = editor.lineCount();
      let new_article = "";
      let cs = editor.getCursor();
      let ch = 0;
      for (let i = 0; i < lineCount; i++) {
        if (i != 0)
          new_article += "\n";
        if (i != cs.line) {
          new_article += this.preFormatOneLine(editor, i + 1)[0];
        } else {
          let newData = this.preFormatOneLine(editor, i + 1, cs.ch);
          new_article += newData[0];
          ch = newData[1];
        }
      }
      editor.setValue(new_article);
      editor.setCursor({ line: cs.line, ch });
      this.onFormatArticle = false;
      new import_obsidian3.Notice("EasyTyping: Format Article Done!");
    };
    this.formatSelectionOrCurLine = (editor, view) => {
      if (!editor.somethingSelected() || editor.getSelection() === "") {
        let lineNumber = editor.getCursor().line;
        let newLineData = this.preFormatOneLine(editor, lineNumber + 1, editor.getCursor().ch);
        editor.replaceRange(newLineData[0], { line: lineNumber, ch: 0 }, { line: lineNumber, ch: editor.getLine(lineNumber).length });
        editor.setSelection({ line: lineNumber, ch: newLineData[1] });
        return;
      }
      let selection = editor.listSelections()[0];
      let begin = selection.anchor.line;
      let end = selection.head.line;
      if (begin > end) {
        let temp = begin;
        begin = end;
        end = temp;
      }
      let new_lines = "";
      for (let i = begin; i <= end; i++) {
        if (i != begin)
          new_lines += "\n";
        new_lines += this.preFormatOneLine(editor, i + 1)[0];
      }
      editor.replaceRange(new_lines, { line: begin, ch: 0 }, { line: end, ch: editor.getLine(end).length });
      if (selection.anchor.line < selection.head.line) {
        editor.setSelection({ line: selection.anchor.line, ch: 0 }, { line: selection.head.line, ch: editor.getLine(selection.head.line).length });
      } else {
        editor.setSelection({ line: selection.anchor.line, ch: editor.getLine(selection.anchor.line).length }, { line: selection.head.line, ch: 0 });
      }
    };
    this.formatOneLine = (editor, lineNumber) => {
      const editorView = editor.cm;
      let state = editorView.state;
      let line = state.doc.line(lineNumber);
      if (getPosLineType(state, line.from) == "text" /* text */ || getPosLineType(state, line.from) == "table" /* table */) {
        let oldLine = line.text;
        let newLine = this.Formater.formatLine(state, lineNumber, this.settings, oldLine.length, 0)[0];
        if (oldLine != newLine) {
          editor.replaceRange(newLine, { line: lineNumber - 1, ch: 0 }, { line: lineNumber - 1, ch: oldLine.length });
          editor.setCursor({ line: lineNumber - 1, ch: editor.getLine(lineNumber - 1).length });
        }
      }
      return;
    };
    this.preFormatOneLine = (editor, lineNumber, ch = -1) => {
      const editorView = editor.cm;
      let state = editorView.state;
      let line = state.doc.line(lineNumber);
      let newLine = line.text;
      let newCh = 0;
      let curCh = line.text.length;
      if (ch != -1) {
        curCh = ch;
      }
      if (getPosLineType(state, line.from) == "text" /* text */ || getPosLineType(state, line.from) == "table" /* table */) {
        let newLineData = this.Formater.formatLine(state, lineNumber, this.settings, curCh, 0);
        newLine = newLineData[0];
        newCh = newLineData[1];
      }
      return [newLine, newCh];
    };
    this.deleteBlankLines = (editor) => {
      if (this.settings.debug) {
        console.log(this.app.vault.getConfig("strictLineBreaks"));
      }
      let strictLineBreaks = this.app.vault.getConfig("strictLineBreaks");
      const editorView = editor.cm;
      let state = editorView.state;
      let doc = state.doc;
      const tree = (0, import_language2.ensureSyntaxTree)(state, doc.length);
      if (!tree) {
        new import_obsidian3.Notice("EasyTyping: Syntax tree is not ready yet, please wait a moment and try again later!", 5e3);
        return;
      }
      let start_line = 1;
      let end_line = doc.lines;
      let line_num = doc.lines;
      const selected = editor.somethingSelected() && editor.getSelection() != "";
      if (selected) {
        let selection = editor.listSelections()[0];
        let begin = selection.anchor.line + 1;
        let end = selection.head.line + 1;
        if (begin > end) {
          let temp = begin;
          begin = end;
          end = temp;
        }
        start_line = begin;
        end_line = end;
      }
      let delete_index = [];
      let blank_reg = /^\s*$/;
      let remain_next_blank = false;
      if (start_line != 1) {
        let node = tree.resolve(doc.line(start_line - 1).from, 1);
        if (node.name.contains("list") || node.name.contains("quote") || node.name.contains("blockid")) {
          remain_next_blank = true;
        }
      }
      if (end_line != line_num && !blank_reg.test(doc.line(end_line + 1).text)) {
        end_line += 1;
      }
      for (let i = start_line; i <= end_line; i++) {
        let line = doc.line(i);
        let pos = line.from;
        let node = tree.resolve(pos, 1);
        if (blank_reg.test(line.text) && !remain_next_blank) {
          delete_index.push(i);
          continue;
        } else if (blank_reg.test(line.text) && remain_next_blank) {
          remain_next_blank = false;
          continue;
        }
        if (node.name.contains("hr") && delete_index[delete_index.length - 1] == i - 1) {
          delete_index.pop();
        } else if (node.name.contains("list") || node.name.contains("quote") || node.name.contains("blockid")) {
          remain_next_blank = true;
        } else {
          remain_next_blank = false;
        }
      }
      let newContent = "";
      for (let i = 1; i < line_num; i++) {
        if (!delete_index.contains(i)) {
          newContent += doc.line(i).text + "\n";
        }
      }
      if (!delete_index.contains(line_num)) {
        newContent += doc.line(line_num).text;
      }
      editor.setValue(newContent);
    };
    this.getEditor = () => {
      let editor = null;
      let markdownView = this.app.workspace.getActiveViewOfType(import_obsidian3.MarkdownView);
      if (markdownView) {
        editor = markdownView.editor;
      }
      if (editor === null)
        console.log("can't get editor");
      return editor;
    };
  }
  async onload() {
    await this.loadSettings();
    this.selectionReplaceMapInitalData = [
      ["\u3010", { left: "[", right: "]" }],
      ["\uFFE5", { left: "$", right: "$" }],
      ["\xB7", { left: "`", right: "`" }],
      ["\xA5", { left: "$", right: "$" }],
      ["\u300A", { left: "\u300A", right: "\u300B" }],
      ["\u201C", { left: "\u201C", right: "\u201D" }],
      ["\u201D", { left: "\u201C", right: "\u201D" }],
      ["\uFF08", { left: "\uFF08", right: "\uFF09" }],
      ["<", { left: "<", right: ">" }]
    ];
    this.refreshSelectionReplaceRule();
    this.SymbolPairsMap = /* @__PURE__ */ new Map();
    let SymbolPairs = ["\u3010\u3011", "\uFF08\uFF09", "\u300A\u300B", "\u201C\u201D", "\u2018\u2019", "\u300C\u300D", "\u300E\u300F", "[]", "()", "{}", '""', "''"];
    for (let pairStr of SymbolPairs)
      this.SymbolPairsMap.set(pairStr.charAt(0), pairStr.charAt(1));
    this.halfToFullSymbolMap = /* @__PURE__ */ new Map([
      [".", "\u3002"],
      [",", "\uFF0C"],
      ["?", "\uFF1F"],
      ["!", "\uFF01"]
    ]);
    let BasicConvRuleStringList = [
      ["\xB7\xB7|", "`|`"],
      ["\uFF01\u3010\u3010|\u3011", "![[|]]"],
      ["\uFF01\u3010\u3010|", "![[|]]"],
      ["\u3010\u3010|\u3011", "[[|]]"],
      ["\u3010\u3010|", "[[|]]"],
      ["\uFFE5\uFFE5|", "$|$"],
      ["$\uFFE5|$", "$$\n|\n$$"],
      ["\xA5\xA5|", "$|$"],
      ["$\xA5|$", "$$\n|\n$$"],
      ["$$|$", "$$\n|\n$$"],
      ["$$|", "$|$"],
      [">\u300B|", ">>|"],
      ["\n\u300B|", "\n>|"],
      [" \u300B|", " >|"],
      ["\n\u3001|", "\n/|"]
    ];
    this.BasicConvRules = ruleStringList2RuleList(BasicConvRuleStringList);
    let FW2HWSymbolRulesStrList = [
      ["\u3002\u3002|", ".|"],
      ["\uFF01\uFF01|", "!|"],
      ["\uFF1B\uFF1B|", ";|"],
      ["\uFF0C\uFF0C|", ",|"],
      ["\uFF1A\uFF1A|", ":|"],
      ["\uFF1F\uFF1F|", "?|"],
      ["\uFF08\uFF08|\uFF09", "(|)"],
      ["\uFF08\uFF08|", "(|)"],
      ["\u201C\u201C|\u201D", '"|"'],
      ["\u201C\u201D|\u201D", '"|"'],
      ["\u2018\u2018|\u2019", "'|'"],
      ["\u2018\u2019|\u2019", "'|'"],
      ["\u300B\u300B|", ">|"],
      ["\u300A\u300A|\u300B", "<|"],
      ["\u300A\u300A|", "<|"]
    ];
    this.FW2HWSymbolRules = ruleStringList2RuleList(FW2HWSymbolRulesStrList);
    let fw2hw_rule_0 = { before: { left: "\uFF5C\uFF5C", right: "" }, after: { left: "|", right: "" } };
    this.FW2HWSymbolRules.push(fw2hw_rule_0);
    let DeleteRulesStrList = [["$|$", "|"], ["==|==", "|"], ["$$\n|\n$$", "|"]];
    this.IntrinsicDeleteRules = ruleStringList2RuleList(DeleteRulesStrList);
    let autoPairRulesPatchStrList = [
      ["\u3010\u3011|\u3011", "\u3010\u3011|"],
      ["\uFF08\uFF09|\uFF09", "\uFF08\uFF09|"],
      ["<>|>", "<>|"],
      ["\u300A\u300B|\u300B", "\u300A\u300B|"],
      ["\u300C\u300D|\u300D", "\u300C\u300D|"],
      ["\u300E\u300F|\u300F", "\u300E\u300F|"],
      ["()|)", "()|"],
      ["[]|]", "[]|"],
      ["{}|}", "{}|"],
      ["''|'", "''|"],
      ['""|"', '""|']
    ];
    this.IntrinsicAutoPairRulesPatch = ruleStringList2RuleList(autoPairRulesPatchStrList);
    let TaboutPairStrs = [
      "\u3010|\u3011",
      "\uFF08|\uFF09",
      "\u300A|\u300B",
      "\u201C|\u201D",
      "\u2018|\u2019",
      "\u300C|\u300D",
      "\u300E|\u300F",
      "'|'",
      '"|"',
      "$$|$$",
      "$|$",
      "__|__",
      "_|_",
      "==|==",
      "~~|~~",
      "**|**",
      "*|*",
      "[[|]]",
      "[|]",
      "{|}",
      "(|)",
      "<|>"
    ];
    this.TaboutPairStrs = TaboutPairStrs.map((s) => string2pairstring(s));
    this.refreshUserDeleteRule();
    this.refreshUserConvertRule();
    this.CurActiveMarkdown = "";
    this.compose_need_handle = false;
    this.Formater = new LineFormater();
    this.onFormatArticle = false;
    this.obsidianSettings = new ObsidianSettings(this.app);
    this.registerEditorExtension([
      import_state.EditorState.transactionFilter.of(this.transactionFilterPlugin),
      import_view.EditorView.updateListener.of(this.viewUpdatePlugin),
      import_state.Prec.highest(import_view.EditorView.domEventHandlers({
        "keyup": this.onKeyup
      }))
    ]);
    this.registerEditorExtension(import_state.Prec.highest(import_view.keymap.of([
      {
        key: "Tab",
        run: (view) => {
          const success = this.handleTabDown(view);
          return success;
        }
      },
      {
        key: "Enter",
        run: (view) => {
          const success = this.handleEnter(view);
          return success;
        }
      },
      {
        key: "Mod-a",
        run: (view) => {
          const success = this.handleModAInCodeBlock(view);
          return success;
        }
      }
    ])));
    this.lang = window.localStorage.getItem("language");
    let command_name_map = this.getCommandNameMap();
    this.addCommand({
      id: "easy-typing-format-article",
      name: command_name_map.get("format_article"),
      editorCallback: (editor, view) => {
        this.formatArticle(editor, view);
      },
      hotkeys: [{
        modifiers: ["Ctrl", "Shift"],
        key: "s"
      }]
    });
    this.addCommand({
      id: "easy-typing-format-selection",
      name: command_name_map.get("format_selection"),
      editorCallback: (editor, view) => {
        this.formatSelectionOrCurLine(editor, view);
      },
      hotkeys: [{
        modifiers: ["Ctrl", "Shift"],
        key: "l"
      }]
    });
    this.addCommand({
      id: "easy-typing-delete-blank-line",
      name: command_name_map.get("delete_blank_line"),
      editorCallback: (editor, view) => {
        this.deleteBlankLines(editor);
      },
      hotkeys: [{
        modifiers: ["Ctrl", "Shift"],
        key: "k"
      }]
    });
    this.addCommand({
      id: "easy-typing-insert-codeblock",
      name: command_name_map.get("insert_codeblock"),
      editorCallback: (editor, view) => {
        this.convert2CodeBlock(editor);
      },
      hotkeys: [{
        modifiers: ["Ctrl", "Shift"],
        key: "n"
      }]
    });
    this.addCommand({
      id: "easy-typing-format-switch",
      name: command_name_map.get("switch_autoformat"),
      callback: () => this.switchAutoFormatting(),
      hotkeys: [{
        modifiers: ["Ctrl"],
        key: "tab"
      }]
    });
    this.addCommand({
      id: "easy-typing-paste-without-format",
      name: command_name_map.get("paste_wo_format"),
      editorCallback: (editor) => this.normalPaste(editor),
      hotkeys: [
        {
          modifiers: ["Mod", "Shift"],
          key: "v"
        }
      ]
    });
    this.addSettingTab(new EasyTypingSettingTab(this.app, this));
    this.registerEvent(this.app.workspace.on("active-leaf-change", (leaf) => {
      if (leaf.view.getViewType() == "markdown") {
        let file = this.app.workspace.getActiveFile();
        if (file != null && this.CurActiveMarkdown != file.path) {
          this.CurActiveMarkdown = file.path;
          if (this.settings.debug)
            new import_obsidian3.Notice("new md-file open: " + file.path);
        }
      }
    }));
    if (import_obsidian3.Platform.isMacOS && this.settings.FixMacOSContextMenu) {
      this.registerEvent(this.app.workspace.on("editor-menu", (menu, editor, view) => {
        if (editor.listSelections().length != 1)
          return;
        let selection = editor.listSelections()[0];
        let selected = editor.getSelection();
        if (selected == "\n") {
          editor.setSelection(selection.anchor, selection.anchor);
        }
      }));
    }
    console.log("Easy Typing Plugin loaded.");
  }
  onunload() {
    console.log("Easy Typing Plugin unloaded.");
  }
  async normalPaste(editor) {
    let clipboardText = await navigator.clipboard.readText();
    if (clipboardText === null || clipboardText === "")
      return;
    if (this.settings.debug)
      console.log("Normal Paste!!");
    const editorView = editor.cm;
    let mainSelection = editorView.state.selection.asSingle().main;
    editorView.dispatch({
      changes: { from: mainSelection.from, to: mainSelection.to, insert: clipboardText },
      selection: { anchor: mainSelection.from + clipboardText.length },
      userEvent: "EasyTyping.paste"
    });
  }
  isCurrentFileExclude() {
    if (this.CurActiveMarkdown == "") {
      let file = this.app.workspace.getActiveFile();
      if (file != null && this.CurActiveMarkdown != file.path) {
        this.CurActiveMarkdown = file.path;
      } else {
        return true;
      }
    }
    let excludePaths = this.settings.ExcludeFiles.split("\n");
    for (let epath of excludePaths) {
      if (epath.charAt(0) == "/")
        epath = epath.substring(1);
      if (this.CurActiveMarkdown == epath)
        return true;
      let len = epath.length;
      if (this.CurActiveMarkdown.substring(0, len) == epath && (this.CurActiveMarkdown.charAt(len) == "/" || this.CurActiveMarkdown.charAt(len) == "\\" || epath.charAt(len - 1) == "/" || epath.charAt(len - 1) == "\\")) {
        return true;
      }
    }
    return false;
  }
  switchAutoFormatting() {
    this.settings.AutoFormat = !this.settings.AutoFormat;
    let status = this.settings.AutoFormat ? "on" : "off";
    new import_obsidian3.Notice("EasyTyping: Autoformat is " + status + "!");
  }
  convert2CodeBlock(editor) {
    if (this.settings.debug)
      console.log("----- EasyTyping: insert code block-----");
    if (editor.somethingSelected && editor.getSelection() != "") {
      let selected = editor.getSelection();
      let selectedRange = editor.listSelections()[0];
      let anchor = selectedRange.anchor;
      let head = selectedRange.head;
      let replacement = "```\n" + selected + "\n```";
      if (anchor.line > head.line || anchor.line == head.line && anchor.ch > head.ch) {
        let temp = anchor;
        anchor = head;
        head = temp;
      }
      let dstLine = anchor.line;
      if (anchor.ch != 0) {
        replacement = "\n" + replacement;
        dstLine += 1;
      }
      if (head.ch != editor.getLine(head.line).length) {
        replacement = replacement + "\n";
      }
      editor.replaceSelection(replacement);
      editor.setCursor({ line: dstLine, ch: 3 });
    } else {
      let cs = editor.getCursor();
      let replace = "```\n```";
      let dstLine = cs.line;
      if (cs.ch != 0) {
        replace = "\n" + replace;
        dstLine += 1;
      }
      if (cs.ch != editor.getLine(cs.line).length) {
        replace = replace + "\n";
      }
      editor.replaceRange(replace, cs);
      editor.setCursor({ line: dstLine, ch: 3 });
    }
  }
  refreshSelectionReplaceRule() {
    this.SelectionReplaceMap = new Map(this.selectionReplaceMapInitalData);
    for (let i = 0; i < this.settings.userSelRepRuleTrigger.length; i++) {
      let trigger = this.settings.userSelRepRuleTrigger[i];
      let lefts = this.settings.userSelRepRuleValue[i].left;
      let rights = this.settings.userSelRepRuleValue[i].right;
      this.SelectionReplaceMap.set(trigger, { left: lefts, right: rights });
    }
  }
  addUserSelectionRepRule(trigger, left, right) {
    if (this.settings.userSelRepRuleTrigger.includes(trigger))
      return false;
    this.settings.userSelRepRuleTrigger.push(trigger);
    this.settings.userSelRepRuleValue.push({ left, right });
    this.refreshSelectionReplaceRule();
    return true;
  }
  deleteUserSelectionRepRule(idx) {
    if (idx < 0 || idx >= this.settings.userSelRepRuleTrigger.length)
      return;
    this.settings.userSelRepRuleTrigger.splice(idx, 1);
    this.settings.userSelRepRuleValue.splice(idx, 1);
    this.refreshSelectionReplaceRule();
  }
  updateUserSelectionRepRule(idx, left, right) {
    if (idx < 0 || idx >= this.settings.userSelRepRuleTrigger.length)
      return;
    this.settings.userSelRepRuleValue[idx].left = left;
    this.settings.userSelRepRuleValue[idx].right = right;
    this.refreshSelectionReplaceRule();
  }
  refreshUserDeleteRule() {
    this.UserDeleteRules = ruleStringList2RuleList(this.settings.userDeleteRulesStrList);
  }
  addUserDeleteRule(before, after) {
    this.settings.userDeleteRulesStrList.push([before, after]);
    this.refreshUserDeleteRule();
  }
  deleteUserDeleteRule(idx) {
    if (idx >= this.settings.userDeleteRulesStrList.length || idx < 0)
      return;
    this.settings.userDeleteRulesStrList.splice(idx, 1);
    this.refreshUserDeleteRule();
  }
  updateUserDeleteRule(idx, before, after) {
    if (idx >= this.settings.userDeleteRulesStrList.length || idx < 0)
      return;
    this.settings.userDeleteRulesStrList[idx][0] = before;
    this.settings.userDeleteRulesStrList[idx][1] = after;
    this.refreshUserDeleteRule();
  }
  refreshUserConvertRule() {
    this.UserConvertRules = ruleStringList2RuleList(this.settings.userConvertRulesStrList);
  }
  addUserConvertRule(before, after) {
    this.settings.userConvertRulesStrList.push([before, after]);
    this.refreshUserConvertRule();
  }
  deleteUserConvertRule(idx) {
    if (idx >= this.settings.userConvertRulesStrList.length || idx < 0)
      return;
    this.settings.userConvertRulesStrList.splice(idx, 1);
    this.refreshUserConvertRule();
  }
  getCommandNameMap() {
    const lang = window.localStorage.getItem("language");
    let command_name_map_en = /* @__PURE__ */ new Map([
      ["format_article", "Format current article"],
      ["format_selection", "Format selected text or current line"],
      ["delete_blank_line", "Delete blank lines of the selected or whole article"],
      ["insert_codeblock", "Insert code block w/wo selection"],
      ["switch_autoformat", "Switch autoformat"],
      ["paste_wo_format", "Paste without format"]
    ]);
    let command_name_map_zh_TW = /* @__PURE__ */ new Map([
      ["format_article", "\u683C\u5F0F\u5316\u5168\u6587"],
      ["format_selection", "\u683C\u5F0F\u5316\u9078\u4E2D\u90E8\u5206/\u7576\u524D\u884C"],
      ["delete_blank_line", "\u522A\u9664\u9078\u4E2D\u90E8\u5206/\u5168\u6587\u7684\u591A\u9918\u7A7A\u767D\u884C"],
      ["insert_codeblock", "\u63D2\u5165\u4EE3\u78BC\u584A"],
      ["switch_autoformat", "\u5207\u63DB\u81EA\u52D5\u683C\u5F0F\u5316\u958B\u95DC"],
      ["paste_wo_format", "\u7121\u683C\u5F0F\u5316\u7C98\u8CBC"]
    ]);
    let command_name_map_zh = /* @__PURE__ */ new Map([
      ["format_article", "\u683C\u5F0F\u5316\u5168\u6587"],
      ["format_selection", "\u683C\u5F0F\u5316\u9009\u4E2D\u90E8\u5206/\u5F53\u524D\u884C"],
      ["delete_blank_line", "\u522A\u9664\u9009\u4E2D\u90E8\u5206/\u5168\u6587\u7684\u591A\u4F59\u7A7A\u767D\u884C"],
      ["insert_codeblock", "\u63D2\u5165\u4EE3\u7801\u5757"],
      ["switch_autoformat", "\u5207\u6362\u81EA\u52A8\u683C\u5F0F\u5316\u5F00\u5173"],
      ["paste_wo_format", "\u65E0\u683C\u5F0F\u5316\u7C98\u8D34"]
    ]);
    let command_name_map = command_name_map_en;
    if (lang == "zh") {
      command_name_map = command_name_map_zh;
    } else if (lang == "zh-TW") {
      command_name_map = command_name_map_zh_TW;
    }
    return command_name_map;
  }
  updateUserConvertRule(idx, before, after) {
    if (idx >= this.settings.userConvertRulesStrList.length || idx < 0)
      return;
    this.settings.userConvertRulesStrList[idx][0] = before;
    this.settings.userConvertRulesStrList[idx][1] = after;
    this.refreshUserConvertRule();
  }
  async loadSettings() {
    this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
  }
  async saveSettings() {
    await this.saveData(this.settings);
  }
};
//# sourceMappingURL=data:application/json;base64,[encoded data, 302900 characters]
