// ../kity-runtime/src/vendor/kity-formula-parser/assembly.ts
function registerAssemblyModule(context) {
  const { _p, window: window2 } = context;
  _p[0] = {
    value: function() {
      const kf = window2.kf;
      const CONSTRUCT_MAPPING = {};
      const CURSOR_CHAR = "\uF155";
      class Assembly {
        formula;
        constructor(formula) {
          this.formula = formula;
        }
        generateBy(data) {
          const tree = data.tree;
          const objTree = {};
          const selectInfo = {};
          const mapping = {};
          if (typeof tree === "string") {
            throw new Error("Unhandled string tree node");
          }
          this.formula.appendExpression(generateExpression(tree, deepCopy(tree), objTree, mapping, selectInfo));
          return {
            select: selectInfo,
            parsedTree: tree,
            tree: objTree,
            mapping
          };
        }
        regenerateBy(data) {
          this.formula.clearExpressions();
          return this.generateBy(data);
        }
      }
      function generateExpression(originTree, tree, objTree, mapping, selectInfo) {
        let currentOperand = null;
        let exp = null;
        const cursorLocation = [];
        const operand = tree.operand || [];
        let constructor = null;
        objTree.operand = [];
        if (tree.name.indexOf("text") === -1) {
          for (let i = 0, len = operand.length; i < len; i += 1) {
            currentOperand = operand[i];
            if (currentOperand === CURSOR_CHAR) {
              cursorLocation.push(i);
              if (!Object.prototype.hasOwnProperty.call(selectInfo, "startOffset")) {
                selectInfo.startOffset = i;
              }
              selectInfo.endOffset = i;
              if (tree.attr && tree.attr.id) {
                selectInfo.groupId = tree.attr.id;
              }
              continue;
            }
            if (!currentOperand) {
              operand[i] = createObject("empty");
              objTree.operand.push(operand[i]);
            } else if (typeof currentOperand === "string") {
              if (tree.name === "brackets" && i < 2) {
                operand[i] = currentOperand;
              } else if (tree.name === "function" && i === 0) {
                operand[i] = currentOperand;
              } else {
                operand[i] = createObject("text", currentOperand);
              }
              objTree.operand.push(operand[i]);
            } else {
              objTree.operand.push({});
              operand[i] = generateExpression(originTree.operand[i], currentOperand, objTree.operand[objTree.operand.length - 1], mapping, selectInfo);
            }
          }
          if (cursorLocation.length === 2) {
            selectInfo.endOffset -= 1;
          }
          while (cursorLocation.length) {
            const index = cursorLocation[cursorLocation.length - 1];
            operand.splice(index, 1);
            cursorLocation.pop();
            originTree.operand.splice(index, 1);
          }
        }
        constructor = getConstructor(tree.name);
        if (!constructor) {
          throw new Error(`operator type error: not found ${tree.operator}`);
        }
        exp = Object.create(constructor.prototype);
        constructor.apply(exp, operand);
        objTree.func = exp;
        for (const fn in tree.callFn) {
          if (!Object.prototype.hasOwnProperty.call(tree.callFn, fn) || !exp[fn]) {
            continue;
          }
          exp[fn].apply(exp, tree.callFn[fn]);
        }
        if (tree.attr) {
          if (tree.attr.id) {
            mapping[tree.attr.id] = {
              objGroup: exp,
              strGroup: originTree
            };
          }
          if (tree.attr["data-root"]) {
            mapping.root = {
              objGroup: exp,
              strGroup: originTree
            };
          }
          exp.setAttr(tree.attr);
        }
        return exp;
      }
      function createObject(type, value) {
        switch (type) {
          case "empty":
            return new kf.EmptyExpression();
          case "text":
            return new kf.TextExpression(value);
          default:
            throw new Error(`Unsupported assembly object type: ${type}`);
        }
      }
      function getConstructor(name) {
        return CONSTRUCT_MAPPING[name] || kf[name.replace(/^[a-z]/i, (match) => match.toUpperCase()).replace(/-([a-z])/gi, (_match, char) => char.toUpperCase()) + "Expression"];
      }
      function deepCopy(source) {
        if (!source || typeof source !== "object") {
          return source;
        }
        if (Array.isArray(source)) {
          return source.map((item) => deepCopy(item));
        }
        const target = {};
        for (const key in source) {
          if (Object.prototype.hasOwnProperty.call(source, key)) {
            target[key] = deepCopy(source[key]);
          }
        }
        return target;
      }
      return Assembly;
    }
  };
}

// ../kity-runtime/src/vendor/kity-formula-parser/bootstrap.ts
function bootstrapLegacyParserRuntime(context) {
  const { _p, window: window2 } = context;
  _p[44] = {
    value: function() {
      const Parser = _p.r(43).Parser;
      _p.r(25);
      window2.kf.Parser = Parser;
      window2.kf.Assembly = _p.r(0);
    }
  };
  _p.r(44);
}

// ../kity-runtime/src/vendor/kity-formula-parser/latex-parser.ts
function registerLatexParserModules(context) {
  const { _p } = context;
  _p[25] = {
    value: function(_require) {
      let Parser = _p.r(43).Parser, LatexUtils = _p.r(1), PRE_HANDLER = _p.r(8), serialization = _p.r(42), OP_DEFINE = _p.r(7), REVERSE_DEFINE = _p.r(9), SPECIAL_LIST = _p.r(10), Utils = _p.r(4);
      let leftChar = "\uFFF8", rightChar = "\uFFFC", clearCharPattern = new RegExp(leftChar + "|" + rightChar, "g"), leftCharPattern = new RegExp(leftChar, "g"), rightCharPattern = new RegExp(rightChar, "g");
      Parser.register("latex", Parser.implement({
        parse: function(data) {
          let units = this.split(this.format(data));
          units = this.parseToGroup(units);
          units = this.parseToStruct(units);
          return this.generateTree(units);
        },
        serialization: function(tree, options) {
          return serialization(tree, options);
        },
        expand: function(expandObj) {
          let parseObj = expandObj.parse, formatKey = null, preObj = expandObj.pre, reverseObj = expandObj.reverse;
          for (let key in parseObj) {
            if (!parseObj.hasOwnProperty(key)) {
              continue;
            }
            formatKey = key.replace(/\\/g, "");
            OP_DEFINE[formatKey] = parseObj[key];
          }
          for (let key in reverseObj) {
            if (!reverseObj.hasOwnProperty(key)) {
              continue;
            }
            REVERSE_DEFINE[key.replace(/\\/g, "")] = reverseObj[key];
          }
          if (preObj) {
            for (let key in preObj) {
              if (!preObj.hasOwnProperty(key)) {
                continue;
              }
              PRE_HANDLER[key.replace(/\\/g, "")] = preObj[key];
            }
          }
        },
        // Format input data
        format: function(input) {
          input = clearEmpty(input);
          input = input.replace(clearCharPattern, "").replace(/\\{/gi, leftChar).replace(/\\}/gi, rightChar);
          for (let key in PRE_HANDLER) {
            if (PRE_HANDLER.hasOwnProperty(key)) {
              input = PRE_HANDLER[key](input);
            }
          }
          return input;
        },
        split: function(data) {
          let units = [], pattern = /(?:\\[^a-z]\s*)|(?:\\[a-z]+\s*)|(?:[{}]\s*)|(?:[^\\{}]\s*)/gi, emptyPattern = /^\s+|\s+$/g, match = null;
          data = data.replace(emptyPattern, "");
          while (match = pattern.exec(data)) {
            match = match[0].replace(emptyPattern, "");
            if (match) {
              units.push(match);
            }
          }
          return units;
        },
        /**
        * Generate tree from parsed syntax units
        * @param units Units
        * @return Generated tree object
        */
        generateTree: function(units) {
          let tree = [], currentUnit = null;
          while (currentUnit = units.shift()) {
            if (Utils.isArray(currentUnit)) {
              tree.push(this.generateTree(currentUnit));
            } else {
              tree.push(currentUnit);
            }
          }
          tree = LatexUtils.toRPNExpression(tree);
          return LatexUtils.generateTree(tree);
        },
        parseToGroup: function(units) {
          let group = [], groupStack = [group], groupCount = 0, bracketsCount = 0;
          for (let i = 0, len = units.length; i < len; i++) {
            switch (units[i]) {
              case "{":
                groupCount++;
                groupStack.push(group);
                group.push([]);
                group = group[group.length - 1];
                break;
              case "}":
                groupCount--;
                group = groupStack.pop();
                break;
              // left-right grouping
              case "\\left":
                bracketsCount++;
                groupStack.push(group);
                group.push([[]]);
                group = group[group.length - 1][0];
                group.type = "brackets";
                i++;
                group.leftBrackets = units[i].replace(leftCharPattern, "{").replace(rightCharPattern, "}");
                break;
              case "\\right":
                bracketsCount--;
                i++;
                group.rightBrackets = units[i].replace(leftCharPattern, "{").replace(rightCharPattern, "}");
                group = groupStack.pop();
                break;
              default:
                group.push(units[i].replace(leftCharPattern, "\\{").replace(rightCharPattern, "\\}"));
                break;
            }
          }
          if (groupCount !== 0) {
            throw new Error("Group Error!");
          }
          if (bracketsCount !== 0) {
            throw new Error("Brackets Error!");
          }
          return groupStack[0];
        },
        parseToStruct: function(units) {
          let structs = [];
          for (let i = 0, len = units.length; i < len; i++) {
            if (Utils.isArray(units[i])) {
              if (units[i].type === "brackets") {
                structs.push(Utils.getBracketsDefine(units[i].leftBrackets, units[i].rightBrackets));
                structs.push(this.parseToStruct(units[i]));
              } else {
                structs.push(this.parseToStruct(units[i]));
              }
            } else {
              structs.push(parseStruct(units[i]));
            }
          }
          return structs;
        }
      }));
      function parseStruct(str) {
        if (isSpecialCharacter(str)) {
          return str.substring(1);
        }
        switch (Utils.getLatexType(str)) {
          case "operator":
            return Utils.getDefine(str);
          case "function":
            return Utils.getFuncDefine(str);
          default:
            return transformSpecialCharacters(str);
        }
      }
      function transformSpecialCharacters(char) {
        if (char.indexOf("\\") === 0) {
          return char + "\\";
        }
        return char;
      }
      function isSpecialCharacter(char) {
        if (char.indexOf("\\") === 0) {
          return !!SPECIAL_LIST[char.substring(1)];
        }
        return false;
      }
      function clearEmpty(data) {
        return data.replace(/\\\s+/, "").replace(/\s*([^a-z0-9\s])\s*/gi, function(match, symbol) {
          return symbol;
        });
      }
    }
  };
  _p[26] = {
    value: function() {
      return function(input) {
        return input.replace(/\\(i+)nt(\b|[^a-zA-Z])/g, function(match, sign, suffix) {
          return "\\int " + sign.length + suffix;
        });
      };
    }
  };
  _p[27] = {
    value: function() {
      return function(input) {
        return input.replace(/``/g, '"');
      };
    }
  };
  _p[28] = {
    value: function() {
      return function(operands) {
        if (operands[0] === "{" || operands[0] === "}") {
          operands[0] = "\\" + operands[0];
        }
        if (operands[1] === "{" || operands[1] === "}") {
          operands[1] = "\\" + operands[1];
        }
        return ["\\left", operands[0], operands[2], "\\right", operands[1]].join(" ");
      };
    }
  };
  _p[29] = {
    value: function() {
      return function(operands) {
        if (this.attr["data-root"] || this.attr["data-placeholder"]) {
          return operands.join("");
        }
        return "{" + operands.join("") + "}";
      };
    }
  };
  _p[30] = {
    value: function() {
      return function(operands) {
        return "\\frac " + operands[0] + " " + operands[1];
      };
    }
  };
  _p[31] = {
    value: function() {
      return function(operands) {
        let result = ["\\" + operands[0]];
        if (operands[2]) {
          result.push("^" + operands[2]);
        }
        if (operands[3]) {
          result.push("_" + operands[3]);
        }
        if (operands[1]) {
          result.push(" " + operands[1]);
        }
        return result.join("");
      };
    }
  };
  _p[32] = {
    value: function() {
      return function(operands) {
        let result = ["\\int "];
        if (this.callFn && this.callFn.setType) {
          result = ["\\"];
          for (let i = 0, len = this.callFn.setType; i < len; i++) {
            result.push("i");
          }
          result.push("nt ");
        }
        if (operands[1]) {
          result.push("^" + operands[1]);
        }
        if (operands[2]) {
          result.push("_" + operands[2]);
        }
        if (operands[0]) {
          result.push(" " + operands[0]);
        }
        return result.join("");
      };
    }
  };
  _p[33] = {
    value: function() {
      return function(operands) {
        return "\\mathbb{" + operands[0] + "}";
      };
    }
  };
  _p[34] = {
    value: function() {
      return function(operands) {
        return "\\mathcal{" + operands[0] + "}";
      };
    }
  };
  _p[35] = {
    value: function() {
      return function(operands) {
        return "\\mathfrak{" + operands[0] + "}";
      };
    }
  };
  _p[36] = {
    value: function() {
      return function(operands) {
        return "\\mathrm{" + operands[0] + "}";
      };
    }
  };
  _p[37] = {
    value: function() {
      return function(operands) {
        return operands[0] + "^" + operands[1] + "_" + operands[2];
      };
    }
  };
  _p[38] = {
    value: function() {
      return function(operands) {
        let result = ["\\sqrt"];
        if (operands[1]) {
          result.push("[" + operands[1] + "]");
        }
        result.push(" " + operands[0]);
        return result.join("");
      };
    }
  };
  _p[39] = {
    value: function() {
      return function(operands) {
        return operands[0] + "_" + operands[1];
      };
    }
  };
  _p[40] = {
    value: function() {
      return function(operands) {
        let result = ["\\sum "];
        if (operands[1]) {
          result.push("^" + operands[1]);
        }
        if (operands[2]) {
          result.push("_" + operands[2]);
        }
        if (operands[0]) {
          result.push(" " + operands[0]);
        }
        return result.join("");
      };
    }
  };
  _p[41] = {
    value: function() {
      return function(operands) {
        return operands[0] + "^" + operands[1];
      };
    }
  };
  _p[42] = {
    value: function(_require) {
      let reverseHandlerTable = _p.r(9), SPECIAL_LIST = _p.r(10), specialCharPattern = /(\\(?:[\w]+)|(?:[^a-z]))\\/gi;
      return function(tree, options) {
        return reverseParse(tree, options);
      };
      function reverseParse(tree, options) {
        let operands = [], reverseHandlerName = null, originalOperands = null;
        if (typeof tree !== "object") {
          if (isSpecialCharacter(tree)) {
            return "\\" + tree + " ";
          }
          return tree.replace(specialCharPattern, function(match, group) {
            return group + " ";
          });
        }
        if (tree.name === "combination" && tree.operand.length === 1 && tree.operand[0].name === "combination") {
          tree = tree.operand[0];
        }
        originalOperands = tree.operand;
        for (let i = 0, len = originalOperands.length; i < len; i++) {
          if (originalOperands[i]) {
            operands.push(reverseParse(originalOperands[i]));
          } else {
            operands.push(originalOperands[i]);
          }
        }
        if (tree.attr && tree.attr._reverse) {
          reverseHandlerName = tree.attr._reverse;
        } else {
          reverseHandlerName = tree.name;
        }
        return reverseHandlerTable[reverseHandlerName].call(tree, operands, options);
      }
      function isSpecialCharacter(char) {
        return !!SPECIAL_LIST[char];
      }
    }
  };
}

// ../kity-runtime/src/vendor/kity-formula-parser/latex-support.ts
function registerLatexSupportModules(context) {
  const { _p } = context;
  _p[1] = {
    value: function(_require) {
      return {
        toRPNExpression: _p.r(2),
        generateTree: _p.r(3)
      };
    }
  };
  _p[2] = {
    value: function(_require) {
      let Utils = _p.r(4);
      function rpn(units) {
        let signStack = [], currentUnit = null;
        units = processFunction(units);
        while (currentUnit = units.shift()) {
          if (currentUnit.name === "combination" && currentUnit.operand.length === 1 && currentUnit.operand[0].name === "brackets") {
            currentUnit = currentUnit.operand[0];
          }
          if (Utils.isArray(currentUnit)) {
            signStack.push(rpn(currentUnit));
            continue;
          }
          signStack.push(currentUnit);
        }
        return signStack;
      }
      function processFunction(units) {
        let processed = [], currentUnit = null;
        while ((currentUnit = units.pop()) !== void 0) {
          if (currentUnit && typeof currentUnit === "object" && (currentUnit.sign === false || currentUnit.name === "function")) {
            let tt = currentUnit.handler(currentUnit, [], processed.reverse());
            processed.unshift(tt);
            processed.reverse();
          } else {
            processed.push(currentUnit);
          }
        }
        return processed.reverse();
      }
      return rpn;
    }
  };
  _p[3] = {
    value: function(_require) {
      let mergeHandler = _p.r(13), Utils = _p.r(4);
      function generateTree(units) {
        let currentUnit = null, tree = [];
        for (let i = 0, len = units.length; i < len; i++) {
          if (Utils.isArray(units[i])) {
            units[i] = generateTree(units[i]);
          }
        }
        while (currentUnit = units.shift()) {
          if (typeof currentUnit === "object" && currentUnit.handler) {
            tree.push(currentUnit.handler(currentUnit, tree, units));
          } else {
            tree.push(currentUnit);
          }
        }
        return mergeHandler(tree);
      }
      return generateTree;
    }
  };
  _p[4] = {
    value: function(_require) {
      let OPERATOR_LIST = _p.r(7), FUNCTION_LIST = _p.r(6), FUNCTION_HANDLER = _p.r(15), Utils = {
        // Detect the kf type based on input latex string
        getLatexType: function(str) {
          str = str.replace(/^\\/, "");
          if (OPERATOR_LIST[str]) {
            return "operator";
          }
          if (FUNCTION_LIST[str]) {
            return "function";
          }
          return "text";
        },
        isArray: function(obj) {
          return obj && Object.prototype.toString.call(obj) === "[object Array]";
        },
        getDefine: function(str) {
          return Utils.extend({}, OPERATOR_LIST[str.replace("\\", "")]);
        },
        getFuncDefine: function(str) {
          return {
            name: "function",
            params: str.replace(/^\\/, ""),
            handler: FUNCTION_HANDLER
          };
        },
        getBracketsDefine: function(leftBrackets, rightBrackets) {
          return Utils.extend({
            params: [leftBrackets, rightBrackets]
          }, OPERATOR_LIST.brackets);
        },
        extend: function(target, sources) {
          for (let key in sources) {
            if (sources.hasOwnProperty(key)) {
              target[key] = sources[key];
            }
          }
          return target;
        }
      };
      return Utils;
    }
  };
  _p[5] = {
    value: function() {
      let t = true;
      return {
        ".": t,
        "{": t,
        "}": t,
        "[": t,
        "]": t,
        "(": t,
        ")": t,
        "|": t
      };
    }
  };
  _p[6] = {
    value: function() {
      return {
        sin: 1,
        cos: 1,
        arccos: 1,
        cosh: 1,
        det: 1,
        inf: 1,
        limsup: 1,
        Pr: 1,
        tan: 1,
        arcsin: 1,
        cot: 1,
        dim: 1,
        ker: 1,
        ln: 1,
        sec: 1,
        tanh: 1,
        arctan: 1,
        coth: 1,
        exp: 1,
        lg: 1,
        log: 1,
        arg: 1,
        csc: 1,
        gcd: 1,
        lim: 1,
        max: 1,
        sinh: 1,
        deg: 1,
        hom: 1,
        liminf: 1,
        min: 1,
        sup: 1
      };
    }
  };
  _p[7] = {
    value: function(_require) {
      let scriptHandler = _p.r(22), TYPE = _p.r(11);
      return {
        "^": {
          name: "superscript",
          type: TYPE.OP,
          handler: scriptHandler
        },
        _: {
          name: "subscript",
          type: TYPE.OP,
          handler: scriptHandler
        },
        frac: {
          name: "fraction",
          type: TYPE.FN,
          sign: false,
          handler: _p.r(14)
        },
        sqrt: {
          name: "radical",
          type: TYPE.FN,
          sign: false,
          handler: _p.r(23)
        },
        sum: {
          name: "summation",
          type: TYPE.FN,
          traversal: "rtl",
          handler: _p.r(24)
        },
        "int": {
          name: "integration",
          type: TYPE.FN,
          traversal: "rtl",
          handler: _p.r(16)
        },
        brackets: {
          name: "brackets",
          type: TYPE.FN,
          handler: _p.r(12)
        },
        mathcal: {
          name: "mathcal",
          type: TYPE.FN,
          sign: false,
          handler: _p.r(19)
        },
        mathfrak: {
          name: "mathfrak",
          type: TYPE.FN,
          sign: false,
          handler: _p.r(20)
        },
        mathbb: {
          name: "mathbb",
          type: TYPE.FN,
          sign: false,
          handler: _p.r(18)
        },
        mathrm: {
          name: "mathrm",
          type: TYPE.FN,
          sign: false,
          handler: _p.r(21)
        }
      };
    }
  };
  _p[8] = {
    value: function(_require) {
      return {
        // Integration preprocessor
        "int": _p.r(26),
        // Quote preprocessor
        quot: _p.r(27)
      };
    }
  };
  _p[9] = {
    value: function(_require) {
      return {
        combination: _p.r(29),
        fraction: _p.r(30),
        "function": _p.r(31),
        integration: _p.r(32),
        subscript: _p.r(39),
        superscript: _p.r(41),
        script: _p.r(37),
        radical: _p.r(38),
        summation: _p.r(40),
        brackets: _p.r(28),
        mathcal: _p.r(34),
        mathfrak: _p.r(35),
        mathbb: _p.r(33),
        mathrm: _p.r(36)
      };
    }
  };
  _p[10] = {
    value: function() {
      return {
        "#": 1,
        $: 1,
        "%": 1,
        _: 1,
        "&": 1,
        "{": 1,
        "}": 1,
        "^": 1,
        "~": 1
      };
    }
  };
  _p[11] = {
    value: function() {
      return {
        OP: 1,
        FN: 2
      };
    }
  };
  _p[12] = {
    value: function(_require) {
      let BRACKETS_TYPE = _p.r(5);
      return function(info, processedStack, unprocessedStack) {
        for (let i = 0, len = info.params.length; i < len; i++) {
          if (!(info.params[i] in BRACKETS_TYPE)) {
            throw new Error("Brackets: invalid params");
          }
        }
        info.operand = info.params;
        info.params[2] = unprocessedStack.shift();
        delete info.handler;
        delete info.params;
        return info;
      };
    }
  };
  _p[13] = {
    value: function() {
      return function() {
        return {
          name: "combination",
          operand: arguments[0] || []
        };
      };
    }
  };
  _p[14] = {
    value: function() {
      return function(info, processedStack, unprocessedStack) {
        let numerator = unprocessedStack.shift(), denominator = unprocessedStack.shift();
        if (numerator === void 0 || denominator === void 0) {
          throw new Error("Frac: Syntax Error");
        }
        info.operand = [numerator, denominator];
        delete info.handler;
        return info;
      };
    }
  };
  _p[15] = {
    value: function(_require) {
      let ScriptExtractor = _p.r(17);
      return function(info, processedStack, unprocessedStack) {
        let params = ScriptExtractor.exec(unprocessedStack);
        info.operand = [info.params, params.expr, params.superscript, params.subscript];
        delete info.params;
        delete info.handler;
        return info;
      };
    }
  };
  _p[16] = {
    value: function(_require) {
      let ScriptExtractor = _p.r(17), FN_TYPE = _p.r(11).FN;
      return function(info, processedStack, unprocessedStack) {
        let count = unprocessedStack.shift(), params = ScriptExtractor.exec(unprocessedStack);
        if (params.expr && params.expr.type === FN_TYPE && params.expr.handler) {
          params.expr = params.expr.handler(params.expr, processedStack, unprocessedStack);
        }
        info.operand = [params.expr, params.superscript, params.subscript];
        info.callFn = {
          setType: [count | 0]
        };
        delete info.handler;
        return info;
      };
    }
  };
  _p[17] = {
    value: function() {
      return {
        exec: function(stack) {
          let result = extractScript(stack), expr = stack.shift();
          if (expr && expr.name && expr.name.indexOf("script") !== -1) {
            throw new Error("Script: syntax error!");
          }
          result.expr = expr || null;
          return result;
        }
      };
      function extractScript(stack) {
        let scriptGroup = extract(stack), nextGroup = null, result = {
          superscript: null,
          subscript: null
        };
        if (scriptGroup) {
          nextGroup = extract(stack);
        } else {
          return result;
        }
        result[scriptGroup.type] = scriptGroup.value || null;
        if (nextGroup) {
          if (nextGroup.type === scriptGroup.type) {
            throw new Error("Script: syntax error!");
          }
          result[nextGroup.type] = nextGroup.value || null;
        }
        return result;
      }
      function extract(stack) {
        let forward = stack.shift();
        if (!forward) {
          return null;
        }
        if (forward.name === "subscript" || forward.name === "superscript") {
          return {
            type: forward.name,
            value: stack.shift()
          };
        }
        stack.unshift(forward);
        return null;
      }
    }
  };
  _p[18] = {
    value: function() {
      return function(info, processedStack, unprocessedStack) {
        let chars = unprocessedStack.shift();
        if (typeof chars === "object" && chars.name === "combination") {
          chars = chars.operand.join("");
        }
        info.name = "text";
        info.attr = {
          _reverse: "mathbb"
        };
        info.callFn = {
          setFamily: ["KF AMS BB"]
        };
        info.operand = [chars];
        delete info.handler;
        return info;
      };
    }
  };
  _p[19] = {
    value: function() {
      return function(info, processedStack, unprocessedStack) {
        let chars = unprocessedStack.shift();
        if (typeof chars === "object" && chars.name === "combination") {
          chars = chars.operand.join("");
        }
        info.name = "text";
        info.attr = {
          _reverse: "mathcal"
        };
        info.callFn = {
          setFamily: ["KF AMS CAL"]
        };
        info.operand = [chars];
        delete info.handler;
        return info;
      };
    }
  };
  _p[20] = {
    value: function() {
      return function(info, processedStack, unprocessedStack) {
        let chars = unprocessedStack.shift();
        if (typeof chars === "object" && chars.name === "combination") {
          chars = chars.operand.join("");
        }
        info.name = "text";
        info.attr = {
          _reverse: "mathfrak"
        };
        info.callFn = {
          setFamily: ["KF AMS FRAK"]
        };
        info.operand = [chars];
        delete info.handler;
        return info;
      };
    }
  };
  _p[21] = {
    value: function() {
      return function(info, processedStack, unprocessedStack) {
        let chars = unprocessedStack.shift();
        if (typeof chars === "object" && chars.name === "combination") {
          chars = chars.operand.join("");
        }
        info.name = "text";
        info.attr = {
          _reverse: "mathrm"
        };
        info.callFn = {
          setFamily: ["KF AMS ROMAN"]
        };
        info.operand = [chars];
        delete info.handler;
        return info;
      };
    }
  };
  _p[22] = {
    value: function() {
      return function(info, processedStack, unprocessedStack) {
        let base = processedStack.pop(), script = unprocessedStack.shift() || null;
        if (!script) {
          throw new Error("Missing script");
        }
        base = base || "";
        if (base.name === info.name || base.name === "script") {
          throw new Error("script error");
        }
        if (base.name === "subscript") {
          base.name = "script";
          base.operand[2] = base.operand[1];
          base.operand[1] = script;
          return base;
        } else if (base.name === "superscript") {
          base.name = "script";
          base.operand[2] = script;
          return base;
        }
        info.operand = [base, script];
        delete info.handler;
        return info;
      };
    }
  };
  _p[23] = {
    value: function(_require) {
      let mergeHandler = _p.r(13);
      return function(info, processedStack, unprocessedStack) {
        let exponent = unprocessedStack.shift(), tmp = null, radicand = null;
        if (exponent === "[") {
          exponent = [];
          while (tmp = unprocessedStack.shift()) {
            if (tmp === "]") {
              break;
            }
            exponent.push(tmp);
          }
          if (exponent.length === 0) {
            exponent = null;
          } else {
            exponent = mergeHandler(exponent);
          }
          radicand = unprocessedStack.shift();
        } else {
          radicand = exponent;
          exponent = null;
        }
        info.operand = [radicand, exponent];
        delete info.handler;
        return info;
      };
    }
  };
  _p[24] = {
    value: function(_require) {
      let ScriptExtractor = _p.r(17);
      return function(info, processedStack, unprocessedStack) {
        let params = ScriptExtractor.exec(unprocessedStack);
        info.operand = [params.expr, params.superscript, params.subscript];
        delete info.handler;
        return info;
      };
    }
  };
}

// ../kity-runtime/src/vendor/kity-formula-parser/parser-core.ts
function registerParserCoreModule(context) {
  const { _p } = context;
  _p[43] = {
    value: function(_require, _exports, module) {
      const CONF = {};
      const IMPL_POLL = {};
      const extend = (target, ...sources) => {
        for (const source of sources) {
          for (const key in source) {
            if (Object.prototype.hasOwnProperty.call(source, key)) {
              target[key] = source[key];
            }
          }
        }
        return target;
      };
      const setData = (container, key, value) => {
        if (typeof key === "string") {
          container[key] = value;
          return;
        }
        if (typeof key === "object") {
          for (const currentKey in key) {
            if (Object.prototype.hasOwnProperty.call(key, currentKey)) {
              container[currentKey] = key[currentKey];
            }
          }
          return;
        }
        throw new Error("invalid option");
      };
      class ParserInterface {
        constructor() {
          this.conf = {};
        }
        set(key, value) {
          extend(this.conf, key, value);
        }
        parse() {
          throw new Error("Abstract function");
        }
      }
      class ParserProxy {
        constructor(ParserImpl) {
          this.impl = new ParserImpl();
          this.conf = {};
        }
        config(key, value) {
          setData(this.conf, key, value);
          return this;
        }
        set(key, value) {
          this.impl.set(key, value);
          return this;
        }
        parse(data) {
          const result = {
            config: {},
            tree: this.impl.parse(data)
          };
          extend(result.config, CONF, this.conf);
          return result;
        }
        serialization(tree, options) {
          return this.impl.serialization(tree, options);
        }
        expand(obj) {
          this.impl.expand(obj);
          return this;
        }
      }
      const Parser = {
        use(type) {
          if (!IMPL_POLL[type]) {
            throw new Error("unknown parser type");
          }
          return this.proxy(IMPL_POLL[type]);
        },
        config(key, value) {
          setData(CONF, key, value);
          return this;
        },
        register(type, parserImpl) {
          IMPL_POLL[type.toLowerCase()] = parserImpl;
          return this;
        },
        implement(parser) {
          const parserDefinition = { ...parser };
          const parserConstructor = parserDefinition.constructor || function() {
          };
          delete parserDefinition.constructor;
          class ParserImplementation extends ParserInterface {
            constructor() {
              super();
              parserConstructor.call(this);
            }
          }
          extend(ParserImplementation.prototype, parserDefinition);
          return ParserImplementation;
        },
        proxy(parserImpl) {
          return new ParserProxy(parserImpl);
        }
      };
      module.exports = {
        Parser,
        ParserInterface
      };
    }
  };
}

// ../kity-runtime/src/vendor/kity-formula-parser/runtime.ts
function createLegacyParserModuleRegistry() {
  const modules = [];
  modules.r = function resolve(index) {
    if (modules[index].inited) {
      return modules[index].value;
    }
    if (typeof modules[index].value === "function") {
      const module = {
        exports: {}
      };
      const returnValue = modules[index].value(null, module.exports, module);
      modules[index].inited = true;
      modules[index].value = returnValue;
      if (returnValue !== void 0) {
        return returnValue;
      }
      for (const key in module.exports) {
        if (Object.prototype.hasOwnProperty.call(module.exports, key)) {
          modules[index].inited = true;
          modules[index].value = module.exports;
          return module.exports;
        }
      }
    } else {
      modules[index].inited = true;
      return modules[index].value;
    }
  };
  return modules;
}

// ../kity-runtime/src/vendor/kity-formula-parser/install.ts
var installed = false;
function installLegacyParserRuntime(target = window) {
  if (installed && target.kf?.Parser && target.kf?.Assembly) {
    return target.kf;
  }
  target.kf = target.kf ?? {};
  const context = {
    _p: createLegacyParserModuleRegistry(),
    window: target
  };
  registerAssemblyModule(context);
  registerLatexSupportModules(context);
  registerLatexParserModules(context);
  registerParserCoreModule(context);
  bootstrapLegacyParserRuntime(context);
  installed = true;
  return target.kf;
}
var install_default = installLegacyParserRuntime;
export {
  install_default as default,
  installLegacyParserRuntime
};
/*!
 * Reverse parsing handler: brackets
 */
/*!
 * Reverse parsing handler: combination
 */
/*!
 * Reverse parsing handler: fraction
 */
/*!
 * Reverse parsing handler: func
 */
/*!
 * Reverse parsing handler: integration
 */
/*!
 * Reverse parsing handler: mathbb
 */
/*!
 * Reverse parsing handler: mathcal (mathscr)
 */
/*!
 * Reverse parsing handler: mathfrak
 */
/*!
 * Reverse parsing handler: mathrm
 */
/*!
 * Reverse parsing handler: script
 */
/*!
 * Reverse parsing handler: sqrt
 */
/*!
 * Reverse parsing handler: subscript
 */
/*!
 * Reverse parsing handler: summation
 */
/*!
 * Reverse parsing handler: superscript
 */
/*!
 * Kity Formula formula representation parser interface
 */
/*!
 * Reverse parsing mapping table
 */
/*!
 * Special character definition
 */
/*!
 * Bracket processor
 */
/*!
 * Merge processing (special processing function)
 */
/*!
 * Fraction function processor
 */
/*!
 * Function expression processor
 */
/*!
 * Integration function processor
 */
/*!
 * Common superscript/subscript extractor
 */
/*!
 * Double-struck processing
 */
/*!
 * Script/Cursive style processing
 */
/*!
 * Fraktur/Old German style processing
 */
/*!
 * Roman style processing
 */
/*!
 * Superscript/subscript operator function processing
 */
/*!
 * Square root function processor
 */
/*!
 * Summation function processor
 */
//# sourceMappingURL=install-XVTKACEN.js.map