Socket
Socket
Sign inDemoInstall

mathkeyboardengine

Package Overview
Dependencies
0
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 1.1.0-alpha

89

dist/MathKeyboardEngine.d.ts
export declare function getEditModeLatex(k: KeyboardMemory, latexConfiguration: LatexConfiguration): string;
export declare function getViewModeLatex(x: TreeNode | Placeholder | KeyboardMemory, latexConfiguration: LatexConfiguration): string;
export declare function firstAfterOrNull<T>(array: T[], element: T): T | null;
export declare function getViewModeLatex(x: TreeNode | Placeholder | KeyboardMemory, latexConfiguration: LatexConfiguration): string;
export declare function last<T>(array: T[]): T;
export declare function firstBeforeOrNull<T>(array: T[], element: T): T | null;
export declare function remove<T>(array: T[], element: T): void;
export declare function last<T>(array: T[]): T;
export declare function lastOrNull<T>(array: T[]): T | null;
export declare function concatLatex(...latexArray: string[]): string;
export declare function firstBeforeOrNull<T>(array: T[], element: T): T | null;
export declare function endsWithLatexCommand(latex: string): boolean;
export declare function deleteLeft(k: KeyboardMemory): void;
export declare function concatLatex(...latexArray: string[]): string;
export declare function deleteRight(k: KeyboardMemory): void;
export declare function encapsulate(nodes: TreeNode[], encapsulatingPlaceholder: Placeholder): void;
export declare function isLetter(c: string): boolean;
export declare function deleteRight(k: KeyboardMemory): void;
export declare function deleteLeft(k: KeyboardMemory): void;
export declare function deleteSelection(k: KeyboardMemory): void;
export declare function encapsulateAllPartsOfNumberWithDigitsLeftOfIndex(exclusiveRightIndex: number, siblingNodes: TreeNode[], toPlaceholder: Placeholder): void;
export declare function deleteOuterBranchingNodeButNotItsContents(nonEmptyPlaceholder: Placeholder): void;
export declare function encapsulate(nodes: TreeNode[], encapsulatingPlaceholder: Placeholder): void;
export declare function deleteSelection(k: KeyboardMemory): void;

@@ -35,4 +37,2 @@ export declare function getFirstNonEmptyOnLeftOf(placeholderArray: Placeholder[], element: Placeholder): Placeholder | null;

export declare function encapsulateAllPartsOfNumberWithDigitsLeftOfIndex(exclusiveRightIndex: number, siblingNodes: TreeNode[], toPlaceholder: Placeholder): void;
export declare function insertWithEncapsulateCurrent(k: KeyboardMemory, newNode: BranchingNode, config?: {

@@ -48,21 +48,15 @@ deleteOuterRoundBracketsIfAny?: boolean;

export declare function moveRight(k: KeyboardMemory): void;
export declare function moveLeft(k: KeyboardMemory): void;
export declare function moveUp(k: KeyboardMemory): void;
export declare function moveRight(k: KeyboardMemory): void;
export declare function enterSelectionMode(k: KeyboardMemory): void;
export declare function popSelection(k: KeyboardMemory): TreeNode[];
export declare function setSelectionDiff(k: KeyboardMemory, diffWithCurrent: number): void;
export declare function leaveSelectionMode(k: KeyboardMemory): void;
export declare function inSelectionMode(k: KeyboardMemory): boolean;
export declare function enterSelectionMode(k: KeyboardMemory): void;
export declare function selectLeft(k: KeyboardMemory): void;
export declare function selectRight(k: KeyboardMemory): void;
export declare function leaveSelectionMode(k: KeyboardMemory): void;

@@ -77,2 +71,6 @@ export declare class KeyboardMemory {

export declare function moveUp(k: KeyboardMemory): void;
export declare function selectRight(k: KeyboardMemory): void;
export declare class LatexConfiguration {

@@ -89,12 +87,19 @@ activePlaceholderShape: string;

export declare abstract class LeafNode extends TreeNode {
export declare class LatexParserConfiguration {
additionalDigits: string[] | null;
decimalSeparator: string;
descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets: string[];
}
export declare abstract class BranchingNode extends TreeNode {
placeholders: Placeholder[];
constructor(leftToRight: Placeholder[]);
getMoveDownSuggestion(_fromPlaceholder: Placeholder): Placeholder | null;
getMoveUpSuggestion(_fromPlaceholder: Placeholder): Placeholder | null;
}
export declare function popSelection(k: KeyboardMemory): TreeNode[];
export declare function parseLatex(latex: string | null, latexConfiguration: LatexConfiguration, latexParserConfiguration: LatexParserConfiguration): KeyboardMemory;
type BracePairContent = {
content: string;
rest: string;
};
export declare function getBracketPairContent(opening: string, closingBracket: string, sWithOpening: string): BracePairContent;
export {};
export declare abstract class TreeNode {

@@ -106,2 +111,5 @@ parentPlaceholder: Placeholder;

export declare abstract class LeafNode extends TreeNode {
}
export declare class AscendingBranchingNode extends StandardBranchingNode {

@@ -112,2 +120,9 @@ getMoveDownSuggestion(fromPlaceholder: Placeholder): Placeholder | null;

export declare abstract class BranchingNode extends TreeNode {
placeholders: Placeholder[];
constructor(leftToRight: Placeholder[]);
getMoveDownSuggestion(_fromPlaceholder: Placeholder): Placeholder | null;
getMoveUpSuggestion(_fromPlaceholder: Placeholder): Placeholder | null;
}
export declare class DescendingBranchingNode extends StandardBranchingNode {

@@ -118,2 +133,6 @@ getMoveDownSuggestion(fromPlaceholder: Placeholder): Placeholder | null;

export declare class RoundBracketsNode extends StandardBranchingNode {
constructor(leftBracketLatex?: string, rightBracketLatex?: string);
}
export declare class MatrixNode extends BranchingNode {

@@ -130,6 +149,2 @@ private readonly matrixType;

export declare class RoundBracketsNode extends StandardBranchingNode {
constructor(leftBracketLatex?: string, rightBracketLatex?: string);
}
export declare class StandardBranchingNode extends BranchingNode {

@@ -146,11 +161,11 @@ private readonly before;

export declare class DecimalSeparatorNode extends PartOfNumberWithDigits {
export declare class DigitNode extends PartOfNumberWithDigits {
private readonly latex;
constructor(latex?: string | (() => string));
constructor(digit: string);
getLatexPart(_k: KeyboardMemory, _latexConfiguration: LatexConfiguration): string;
}
export declare class DigitNode extends PartOfNumberWithDigits {
export declare class DecimalSeparatorNode extends PartOfNumberWithDigits {
private readonly latex;
constructor(digit: string);
constructor(latex?: string | (() => string));
getLatexPart(_k: KeyboardMemory, _latexConfiguration: LatexConfiguration): string;

@@ -157,0 +172,0 @@ }

@@ -31,2 +31,3 @@ "use strict";

LatexConfiguration: () => LatexConfiguration,
LatexParserConfiguration: () => LatexParserConfiguration,
LeafNode: () => LeafNode,

@@ -55,2 +56,3 @@ MatrixNode: () => MatrixNode,

moveUp: () => moveUp,
parseLatex: () => parseLatex,
selectLeft: () => selectLeft,

@@ -677,2 +679,22 @@ selectRight: () => selectRight

// src/SyntaxTreeComponents/Nodes/BranchingNodes/AscendingBranchingNode.ts
var AscendingBranchingNode = class extends StandardBranchingNode {
getMoveDownSuggestion(fromPlaceholder) {
const currentPlaceholderIndex = this.placeholders.indexOf(fromPlaceholder);
if (currentPlaceholderIndex > 0) {
return this.placeholders[currentPlaceholderIndex - 1];
} else {
return null;
}
}
getMoveUpSuggestion(fromPlaceholder) {
const currentPlaceholderIndex = this.placeholders.indexOf(fromPlaceholder);
if (currentPlaceholderIndex < this.placeholders.length - 1) {
return this.placeholders[currentPlaceholderIndex + 1];
} else {
return null;
}
}
};
// src/SyntaxTreeComponents/Nodes/LeafNodes/DecimalSeparatorNode.ts

@@ -689,2 +711,22 @@ var DecimalSeparatorNode = class extends PartOfNumberWithDigits {

// src/SyntaxTreeComponents/Nodes/BranchingNodes/DescendingBranchingNode.ts
var DescendingBranchingNode = class extends StandardBranchingNode {
getMoveDownSuggestion(fromPlaceholder) {
const currentPlaceholderIndex = this.placeholders.indexOf(fromPlaceholder);
if (currentPlaceholderIndex < this.placeholders.length - 1) {
return this.placeholders[currentPlaceholderIndex + 1];
} else {
return null;
}
}
getMoveUpSuggestion(fromPlaceholder) {
const currentPlaceholderIndex = this.placeholders.indexOf(fromPlaceholder);
if (currentPlaceholderIndex > 0) {
return this.placeholders[currentPlaceholderIndex - 1];
} else {
return null;
}
}
};
// src/SyntaxTreeComponents/Nodes/LeafNodes/DigitNode.ts

@@ -712,2 +754,31 @@ var DigitNode = class extends PartOfNumberWithDigits {

// src/LatexParser/helpers/getBracketPairContent.ts
function getBracketPairContent(opening, closingBracket, sWithOpening) {
const openingBracket = opening.slice(-1);
const s = sWithOpening.slice(opening.length);
let level = 0;
for (let closingBracketIndex = 0; closingBracketIndex < s.length; closingBracketIndex++) {
if (s[closingBracketIndex] == closingBracket) {
if (level == 0) {
return { content: s.slice(0, closingBracketIndex), rest: s.slice(closingBracketIndex + 1) };
} else {
level--;
continue;
}
}
const toIgnores = ["\\" + openingBracket, "\\" + closingBracket, String.raw`\left` + openingBracket, String.raw`\right` + closingBracket];
const currentPosition = s.slice(closingBracketIndex);
for (const toIgnore of toIgnores) {
if (currentPosition.length >= toIgnore.length && currentPosition.startsWith(toIgnore)) {
closingBracketIndex += toIgnore.length;
continue;
}
}
if (s[closingBracketIndex] == openingBracket) {
level++;
}
}
throw `A closing ${closingBracket} is missing.`;
}
// src/SyntaxTreeComponents/Nodes/BranchingNodes/MatrixNode.ts

@@ -765,40 +836,179 @@ var MatrixNode = class extends BranchingNode {

// src/SyntaxTreeComponents/Nodes/BranchingNodes/AscendingBranchingNode.ts
var AscendingBranchingNode = class extends StandardBranchingNode {
getMoveDownSuggestion(fromPlaceholder) {
const currentPlaceholderIndex = this.placeholders.indexOf(fromPlaceholder);
if (currentPlaceholderIndex > 0) {
return this.placeholders[currentPlaceholderIndex - 1];
} else {
return null;
}
// src/LatexParser/parseLatex.ts
function parseLatex(latex, latexConfiguration, latexParserConfiguration) {
var _a;
let x = latex == null ? void 0 : latex.trim();
if (x == null || x == "") {
return new KeyboardMemory();
}
getMoveUpSuggestion(fromPlaceholder) {
const currentPlaceholderIndex = this.placeholders.indexOf(fromPlaceholder);
if (currentPlaceholderIndex < this.placeholders.length - 1) {
return this.placeholders[currentPlaceholderIndex + 1];
} else {
return null;
const k = new KeyboardMemory();
while (x != "") {
if (x[0] == " ") {
x = x.trimStart();
continue;
}
if (x.startsWith(latexParserConfiguration.decimalSeparator)) {
insert(k, new DecimalSeparatorNode(latexParserConfiguration.decimalSeparator));
x = x.slice(latexParserConfiguration.decimalSeparator.length);
continue;
}
if (["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"].includes(x[0]) || ((_a = latexParserConfiguration.additionalDigits) == null ? void 0 : _a.includes(x[0]))) {
insert(k, new DigitNode(x[0]));
x = x.slice(1);
continue;
}
let handled = false;
if (x.startsWith(String.raw`\begin{`)) {
const matrixTypeAndRest = getBracketPairContent(String.raw`\begin{`, "}", x);
if (!matrixTypeAndRest.content.endsWith("matrix") && !matrixTypeAndRest.content.endsWith("cases")) {
throw String.raw`Expected a word ending with 'matrix' or 'cases' after '\begin{'.`;
}
const matrixContent = matrixTypeAndRest.rest.slice(0, matrixTypeAndRest.rest.indexOf(String.raw`\end{${matrixTypeAndRest.content}}`));
const lines = matrixContent.split(String.raw`\\`);
insert(k, new MatrixNode(matrixTypeAndRest.content, lines[0].split("&").length, lines.length));
for (const line of lines) {
for (const latex2 of line.split("&")) {
const nodes = parseLatex(latex2, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
for (const node of nodes) {
insert(k, node);
k.current = node;
}
moveRight(k);
}
}
const matrixEnd = String.raw`\end{${matrixTypeAndRest.content}}`;
x = x.slice(x.indexOf(matrixEnd) + matrixEnd.length);
continue;
}
if (x.startsWith("\\")) {
for (const prefix of ["\\left\\", "\\right\\", String.raw`\left`, String.raw`\right`]) {
if (x.startsWith(prefix)) {
insert(k, new StandardLeafNode(prefix + x[prefix.length]));
x = x.slice(prefix.length + 1);
handled = true;
break;
}
}
if (handled) {
continue;
}
for (const commandWithBrackets of latexParserConfiguration.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets) {
const opening = commandWithBrackets.slice(0, -3);
const closingBracket1 = commandWithBrackets.slice(-3, -2);
const openingBracket2 = commandWithBrackets.slice(-2, -1);
const closingBracket2 = commandWithBrackets.slice(-1);
if (x.startsWith(opening)) {
const numeratorAndRest = getBracketPairContent(opening, closingBracket1, x);
if (numeratorAndRest.rest[0] != openingBracket2) {
continue;
}
const node = new DescendingBranchingNode(opening, closingBracket1 + openingBracket2, closingBracket2);
insert(k, node);
const numerator = parseLatex(numeratorAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
for (const node2 of numerator) {
insert(k, node2);
k.current = node2;
}
moveRight(k);
const denominatorAndRest = getBracketPairContent(openingBracket2, closingBracket2, numeratorAndRest.rest);
const denominator = parseLatex(denominatorAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
for (const node2 of denominator) {
insert(k, node2);
k.current = node2;
}
k.current = node;
x = denominatorAndRest.rest;
handled = true;
break;
}
}
if (handled) {
continue;
}
const textOpening = String.raw`\text{`;
if (x.startsWith(textOpening)) {
const bracketPairContentAndRest = getBracketPairContent(textOpening, "}", x);
const textNode = new StandardBranchingNode(textOpening, "}");
insert(k, textNode);
for (const character of bracketPairContentAndRest.content) {
insert(k, new StandardLeafNode(character));
}
k.current = textNode;
x = bracketPairContentAndRest.rest;
continue;
}
let command = "\\";
if (isLetter(x[1])) {
for (let i = 1; i < x.length; i++) {
const character = x[i];
if (isLetter(character)) {
command += character;
} else if (character == "{") {
command += character;
const opening = command;
const bracketPairContentAndRest = getBracketPairContent(opening, "}", x);
const placeholderContent = parseLatex(bracketPairContentAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
const branchingNode = new StandardBranchingNode(opening, "}");
insert(k, branchingNode);
for (const node of placeholderContent) {
insert(k, node);
k.current = node;
}
k.current = branchingNode;
x = bracketPairContentAndRest.rest;
handled = true;
break;
} else {
break;
}
}
if (handled) {
continue;
}
insert(k, new StandardLeafNode(command));
x = x.slice(command.length);
} else {
insert(k, new StandardLeafNode("\\" + x[1]));
x = x.slice(2);
}
continue;
}
const various = [
["^{", () => new AscendingBranchingNode("", "^{", "}")],
["_{", () => new DescendingBranchingNode("", "_{", "}")]
];
for (const opening_getTreeNode of various) {
const opening = opening_getTreeNode[0];
if (x.startsWith(opening)) {
const node = opening_getTreeNode[1]();
insertWithEncapsulateCurrent(k, node);
const bracketPairContentAndRest = getBracketPairContent(opening, "}", x);
const secondPlaceholderNodes = parseLatex(bracketPairContentAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
for (const node2 of secondPlaceholderNodes) {
insert(k, node2);
k.current = node2;
}
k.current = node;
x = bracketPairContentAndRest.rest;
handled = true;
break;
}
}
if (handled == true) {
continue;
}
insert(k, new StandardLeafNode(x[0]));
x = x.slice(1);
continue;
}
};
return k;
}
// src/SyntaxTreeComponents/Nodes/BranchingNodes/DescendingBranchingNode.ts
var DescendingBranchingNode = class extends StandardBranchingNode {
getMoveDownSuggestion(fromPlaceholder) {
const currentPlaceholderIndex = this.placeholders.indexOf(fromPlaceholder);
if (currentPlaceholderIndex < this.placeholders.length - 1) {
return this.placeholders[currentPlaceholderIndex + 1];
} else {
return null;
}
// src/LatexParser/LatexParserConfiguration.ts
var LatexParserConfiguration = class {
constructor() {
this.additionalDigits = null;
this.decimalSeparator = ".";
this.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets = [];
}
getMoveUpSuggestion(fromPlaceholder) {
const currentPlaceholderIndex = this.placeholders.indexOf(fromPlaceholder);
if (currentPlaceholderIndex > 0) {
return this.placeholders[currentPlaceholderIndex - 1];
} else {
return null;
}
}
};

@@ -805,0 +1015,0 @@

@@ -1,1 +0,1 @@

"use strict";var mke=(()=>{var H=Object.defineProperty;var ie=Object.getOwnPropertyDescriptor;var ce=Object.getOwnPropertyNames;var ae=Object.prototype.hasOwnProperty;var se=(e,o)=>{for(var r in o)H(e,r,{get:o[r],enumerable:!0})},de=(e,o,r,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of ce(o))!ae.call(e,n)&&n!==r&&H(e,n,{get:()=>o[n],enumerable:!(t=ie(o,n))||t.enumerable});return e};var pe=e=>de(H({},"__esModule",{value:!0}),e);var he={};se(he,{AscendingBranchingNode:()=>U,BranchingNode:()=>a,DecimalSeparatorNode:()=>I,DescendingBranchingNode:()=>_,DigitNode:()=>E,KeyboardMemory:()=>b,LatexConfiguration:()=>$,LeafNode:()=>P,MatrixNode:()=>A,Placeholder:()=>i,RoundBracketsNode:()=>O,StandardBranchingNode:()=>u,StandardLeafNode:()=>W,TreeNode:()=>s,deleteLeft:()=>j,deleteRight:()=>w,deleteSelection:()=>X,enterSelectionMode:()=>oe,getEditModeLatex:()=>V,getViewModeLatex:()=>G,inSelectionMode:()=>te,insert:()=>B,insertWithEncapsulateCurrent:()=>R,insertWithEncapsulateSelection:()=>Y,insertWithEncapsulateSelectionAndPrevious:()=>Z,leaveSelectionMode:()=>S,moveDown:()=>k,moveLeft:()=>ee,moveRight:()=>g,moveUp:()=>re,selectLeft:()=>ne,selectRight:()=>le});function V(e,o){return e.syntaxTreeRoot.getLatex(e,o)}function K(e){return e.toLowerCase()!=e.toUpperCase()}function z(e){if(e.length==0)return!1;if(K(e[e.length-1]))for(let o=e.length-2;o>=0;o--){let r=e[o];if(!K(r))return r=="\\"}return!1}function x(...e){let o="";for(let r=0;r<e.length;r++){let t=e[r];z(o)&&K(t[0])&&(o+=" "),o+=t}return o}var i=class{constructor(){this.parentNode=null;this.nodes=[]}getLatex(o,r){let t=()=>x(...this.nodes.map(n=>n.getLatex(o,r)));return o.inclusiveSelectionLeftBorder===this?x(r.selectionHightlightStart,t()):this===o.current?this.nodes.length==0?r.activePlaceholderLatex:x(r.activePlaceholderLatex,t()):this.nodes.length==0?r.passivePlaceholderLatex:t()}};var b=class{constructor(){this.syntaxTreeRoot=new i;this.current=this.syntaxTreeRoot;this.selectionDiff=null;this.inclusiveSelectionRightBorder=null;this.inclusiveSelectionLeftBorder=null}};var fe=new b;function G(e,o){return(e instanceof b?e.syntaxTreeRoot:e).getLatex(fe,o)}function J(e,o){let r=!1;for(let t=e.length-1;t>=0;t--){let n=e[t];if(!r){n===o&&(r=!0);continue}if(n.nodes.length>0)return n}return null}function m(e){return e.length==0?null:e[e.length-1]}function d(e,o){let r=e.indexOf(o);return r>0?e[r-1]:null}function h(e,o){let r=e.indexOf(o);e.splice(r,1)}var s=class{getLatex(o,r){let t=this.getLatexPart(o,r);return o.selectionDiff!=null&&o.selectionDiff!=0?(o.inclusiveSelectionLeftBorder===this&&(t=x(r.selectionHightlightStart,t)),o.inclusiveSelectionRightBorder===this&&(t=x(t,r.selectionHightlightEnd)),t):o.current===this?x(t,r.activePlaceholderLatex):t}};var a=class extends s{constructor(r){super();this.placeholders=r,this.placeholders.forEach(t=>{t.parentNode=this})}getMoveDownSuggestion(r){return null}getMoveUpSuggestion(r){return null}};function p(e){return e[e.length-1]}var P=class extends s{};var f=class extends P{};function C(e,o,r){for(let t=e-1;t>=0;t--){let n=o[t];if(n instanceof f)h(o,n),r.nodes.unshift(n),n.parentPlaceholder=r;else break}}function L(e){let o=e.parentNode,r=o.parentPlaceholder.nodes.indexOf(o);o.parentPlaceholder.nodes.splice(r,1,...e.nodes);for(let t of e.nodes)t.parentPlaceholder=o.parentPlaceholder}function j(e){var o;if(e.current instanceof i){if(e.current.parentNode==null||e.current.nodes.length>0)return;{let r=J(e.current.parentNode.placeholders,e.current);if(r)e.current.parentNode.placeholders.length==2&&e.current===e.current.parentNode.placeholders[1]&&e.current.nodes.length==0?(L(r),e.current=p(r.nodes)):(r.nodes.pop(),e.current=(o=m(r.nodes))!=null?o:r);else if(e.current.parentNode.placeholders.every(t=>t.nodes.length==0)){let t=e.current.parentNode.parentPlaceholder,n=d(t.nodes,e.current.parentNode);h(t.nodes,e.current.parentNode),e.current=n!=null?n:t}else if(e.current.parentNode.placeholders[0]===e.current&&e.current.nodes.length==0&&e.current.parentNode.placeholders.some(t=>t.nodes.length!=0)){let t=d(e.current.parentNode.parentPlaceholder.nodes,e.current.parentNode);if(t!=null)me(t,e.current),e.current=p(e.current.nodes);else{let n=e.current.parentNode.placeholders.filter(l=>l.nodes.length!=0);if(n.length==1){let l=n[0].nodes,c=e.current.parentNode.parentPlaceholder,v=c.nodes.indexOf(e.current.parentNode);for(let D of l)D.parentPlaceholder=c;c.nodes.splice(v,1,...l),e.current=p(l)}}}}}else if(e.current instanceof a&&e.current.placeholders[0].nodes.length>0&&e.current.placeholders.slice(1).every(r=>r.nodes.length==0)){let r=e.current.placeholders[0];L(r),e.current=p(r.nodes)}else if(e.current instanceof a&&e.current.placeholders.some(r=>r.nodes.length>0))e.current=p(e.current.placeholders.flatMap(r=>r.nodes)),j(e);else{let r=d(e.current.parentPlaceholder.nodes,e.current);h(e.current.parentPlaceholder.nodes,e.current),e.current=r!=null?r:e.current.parentPlaceholder}}function me(e,o){h(o.parentNode.parentPlaceholder.nodes,e),o.nodes.push(e);let r=e.parentPlaceholder;e.parentPlaceholder=o,e instanceof f&&C(r.nodes.length-1,r.nodes,o)}function y(e,o){let r=e.indexOf(o);return r!=-1&&r<e.length-1?e[r+1]:null}function w(e){var o;if(e.current instanceof i)if(e.current.parentNode!=null&&e.current.parentNode.placeholders.every(r=>r.nodes.length==0)){let r=d(e.current.parentNode.parentPlaceholder.nodes,e.current.parentNode);h(e.current.parentNode.parentPlaceholder.nodes,e.current.parentNode),e.current=r!=null?r:e.current.parentNode.parentPlaceholder}else{let r=e.current.nodes;if(r.length>0)Q(e,r[0]);else if(e.current.parentNode!=null){let t=e.current.parentNode,n=t.placeholders;if(n[0]==e.current&&n.length==2){let l=n[1];e.current=(o=d(t.parentPlaceholder.nodes,t))!=null?o:t.parentPlaceholder,L(l)}else for(let l=n.indexOf(e.current)+1;l<n.length;l++)if(n[l].nodes.length>0){e.current=n[l],w(e);return}}}else{let r=y(e.current.parentPlaceholder.nodes,e.current);r!=null&&Q(e,r)}}function Q(e,o){o instanceof a?o.placeholders.length==1&&o.placeholders[0].nodes.length>0?L(o.placeholders[0]):o.placeholders.length==2&&o.placeholders[0].nodes.length==0&&o.placeholders[1].nodes.length>0?L(o.placeholders[1]):(e.current=o.placeholders[0],w(e)):h(o.parentPlaceholder.nodes,o)}function S(e){e.selectionDiff=null,e.inclusiveSelectionRightBorder=null,e.inclusiveSelectionLeftBorder=null}function M(e){var r;if(e.selectionDiff==null)throw"Enter selection mode before calling this method.";if(e.selectionDiff==0)return S(e),[];let o=e.selectionDiff;if(e.current instanceof i)return S(e),e.current.nodes.splice(0,o);{let t=e.current.parentPlaceholder.nodes,n=t.indexOf(e.inclusiveSelectionLeftBorder);return e.current=(r=d(t,e.inclusiveSelectionLeftBorder))!=null?r:e.current.parentPlaceholder,S(e),t.splice(n,ue(o))}}function ue(e){return e<0?-e:e}function X(e){M(e)}function g(e){var o;if(e.current instanceof i)if(e.current.nodes.length>0){let r=e.current.nodes[0];e.current=r instanceof a?r.placeholders[0]:r}else{if(e.current.parentNode==null)return;e.current=(o=y(e.current.parentNode.placeholders,e.current))!=null?o:e.current.parentNode}else{let r=y(e.current.parentPlaceholder.nodes,e.current);if(r!=null)e.current=r instanceof a?r.placeholders[0]:r;else{let t=e.current.parentPlaceholder.parentNode;if(t!=null){let n=y(t.placeholders,e.current.parentPlaceholder);e.current=n!=null?n:t}}}}function B(e,o){if(e.current instanceof i)e.current.nodes.unshift(o),o.parentPlaceholder=e.current;else{let r=e.current.parentPlaceholder,t=r.nodes.indexOf(e.current);r.nodes.splice(t+1,0,o),o.parentPlaceholder=r}g(e)}var u=class extends a{constructor(r,t,...n){let l=n.length+1,c=new Array;for(let v=0;v<l;v++)c.push(new i);super(c);this.before=r,this.then=t,this.rest=n}getLatexPart(r,t){let n=this.before+this.placeholders[0].getLatex(r,t)+this.then;for(let l=0;l<this.rest.length;l++)n+=this.placeholders[l+1].getLatex(r,t)+this.rest[l];return n}};var O=class extends u{constructor(o=String.raw`\left(`,r=String.raw`\right)`){super(o,r)}};function T(e,o){for(let r of e)r.parentPlaceholder=o,o.nodes.push(r)}function R(e,o,r){var n;let t=o.placeholders[0];if(e.current instanceof s){let l=e.current.parentPlaceholder.nodes,c=l.indexOf(e.current);l[c]=o,o.parentPlaceholder=e.current.parentPlaceholder,e.current instanceof O&&(r!=null&&r.deleteOuterRoundBracketsIfAny)?(T(e.current.placeholders[0].nodes,t),e.current=(n=y(o.placeholders,t))!=null?n:o):e.current instanceof f?(t.nodes.push(e.current),e.current.parentPlaceholder=t,C(c,l,t),g(e)):(t.nodes.push(e.current),e.current.parentPlaceholder=t,g(e))}else B(e,o)}function Y(e,o){let r=M(e);if(B(e,o),r.length>0){let t=o.placeholders[0];T(r,t),e.current=p(r),g(e)}}function Z(e,o){var n;if(o.placeholders.length<2)throw"Expected 2 placeholders.";let r=M(e),t=o.placeholders[1];T(r,t),R(e,o),e.current=(n=m(r))!=null?n:t}function k(e){var t;let o=e.current instanceof i?e.current:e.current.parentPlaceholder,r;for(;;){if(o.parentNode==null)return;r=o.parentNode;let n=r.getMoveDownSuggestion(o);if(n!=null){e.current=(t=m(n.nodes))!=null?t:n;return}o=r.parentPlaceholder}}function ee(e){var o,r,t;if(e.current instanceof i){if(e.current.parentNode==null)return;let n=d(e.current.parentNode.placeholders,e.current);if(n!==null)e.current=(o=m(n.nodes))!=null?o:n;else{let l=e.current.parentNode.parentPlaceholder,c=d(l.nodes,e.current.parentNode);e.current=c!=null?c:l}}else if(e.current instanceof a){let n=p(e.current.placeholders);e.current=(r=m(n.nodes))!=null?r:n}else e.current=(t=d(e.current.parentPlaceholder.nodes,e.current))!=null?t:e.current.parentPlaceholder}function re(e){var t;let o=e.current instanceof i?e.current:e.current.parentPlaceholder,r;for(;;){if(o.parentNode==null)return;r=o.parentNode;let n=r.getMoveUpSuggestion(o);if(n!=null){e.current=(t=m(n.nodes))!=null?t:n;return}o=r.parentPlaceholder}}function N(e,o){if(e.selectionDiff=o,o==0)e.inclusiveSelectionLeftBorder=null,e.inclusiveSelectionRightBorder=null;else if(e.current instanceof i)e.inclusiveSelectionLeftBorder=e.current,e.inclusiveSelectionRightBorder=e.current.nodes[o-1];else{let r=e.current.parentPlaceholder.nodes,t=r.indexOf(e.current);if(o>0)e.inclusiveSelectionLeftBorder=r[t+1],e.inclusiveSelectionRightBorder=r[t+o];else{let n=t+o+1;if(n<0)throw"The TreeNode at index 0 of the current Placeholder is as far as you can go left if current is a TreeNode.";e.inclusiveSelectionLeftBorder=r[n],e.inclusiveSelectionRightBorder=e.current}}}function oe(e){N(e,0)}function te(e){return e.selectionDiff!=null}function ne(e){var r;let o=(r=e.selectionDiff)!=null?r:0;e.current instanceof s&&e.current.parentPlaceholder.nodes.indexOf(e.current)+o>=0||e.current instanceof i&&o>0?N(e,o-1):e.inclusiveSelectionLeftBorder instanceof s&&e.inclusiveSelectionLeftBorder.parentPlaceholder.nodes.indexOf(e.inclusiveSelectionLeftBorder)==0&&e.inclusiveSelectionLeftBorder.parentPlaceholder.parentNode!=null&&(e.current=e.inclusiveSelectionLeftBorder.parentPlaceholder.parentNode,N(e,-1))}function le(e){var r,t;let o=(r=e.selectionDiff)!=null?r:0;if(e.current instanceof i&&o<e.current.nodes.length||e.current instanceof s&&e.current.parentPlaceholder.nodes.indexOf(e.current)+o<e.current.parentPlaceholder.nodes.length-1)N(e,o+1);else if(e.inclusiveSelectionRightBorder instanceof s&&p(e.inclusiveSelectionRightBorder.parentPlaceholder.nodes)==e.inclusiveSelectionRightBorder&&e.inclusiveSelectionRightBorder.parentPlaceholder.parentNode!=null){let n=e.inclusiveSelectionRightBorder.parentPlaceholder.parentNode;e.current=(t=d(n.parentPlaceholder.nodes,n))!=null?t:n.parentPlaceholder,N(e,1)}}var I=class extends f{constructor(r="."){super();this.latex=typeof r=="string"?()=>r:r}getLatexPart(r,t){return this.latex()}};var E=class extends f{constructor(r){super();this.latex=r}getLatexPart(r,t){return this.latex}};var W=class extends P{constructor(r){super();this.latex=typeof r=="string"?()=>r:r}getLatexPart(r,t){return this.latex()}};var A=class extends a{constructor(r,t,n){let l=[],c=[];for(let v=0;v<n;v++){let D=[];for(let q=0;q<t;q++){let F=new i;D.push(F),c.push(F)}l.push(D)}super(c);this.grid=l,this.matrixType=r,this.width=t}getLatexPart(r,t){let n=String.raw`\begin{${this.matrixType}}`;return n+=this.grid.map(l=>l.map(c=>c.getLatex(r,t)).join(" & ")).join(String.raw` \\ `),n+=String.raw`\end{${this.matrixType}}`,n}getMoveDownSuggestion(r){let{rowIndex:t,columnIndex:n}=this.getPositionOf(r);return t+1<this.grid.length?this.grid[t+1][n]:null}getMoveUpSuggestion(r){let{rowIndex:t,columnIndex:n}=this.getPositionOf(r);return t-1>=0?this.grid[t-1][n]:null}getPositionOf(r){let t=this.placeholders.indexOf(r);if(t==-1)throw"The provided Placeholder is not part of this MatrixNode.";let n=Math.floor(t/this.width),l=t-n*this.width;return{rowIndex:n,columnIndex:l}}};var U=class extends u{getMoveDownSuggestion(o){let r=this.placeholders.indexOf(o);return r>0?this.placeholders[r-1]:null}getMoveUpSuggestion(o){let r=this.placeholders.indexOf(o);return r<this.placeholders.length-1?this.placeholders[r+1]:null}};var _=class extends u{getMoveDownSuggestion(o){let r=this.placeholders.indexOf(o);return r<this.placeholders.length-1?this.placeholders[r+1]:null}getMoveUpSuggestion(o){let r=this.placeholders.indexOf(o);return r>0?this.placeholders[r-1]:null}};var $=class{constructor(){this.activePlaceholderShape=String.raw`\blacksquare`;this.passivePlaceholderShape=String.raw`\square`;this.selectionHightlightStart=String.raw`\colorbox{#ADD8E6}{\(\displaystyle`;this.selectionHightlightEnd=String.raw`\)}`}get activePlaceholderLatex(){return this.activePlaceholderColor==null?this.activePlaceholderShape:String.raw`{\color{${this.activePlaceholderColor}}${this.activePlaceholderShape}}`}get passivePlaceholderLatex(){return this.passivePlaceholderColor==null?this.passivePlaceholderShape:String.raw`{\color{${this.passivePlaceholderColor}}${this.passivePlaceholderShape}}`}};return pe(he);})();
"use strict";var mke=(()=>{var k=Object.defineProperty;var ye=Object.getOwnPropertyDescriptor;var Ne=Object.getOwnPropertyNames;var ve=Object.prototype.hasOwnProperty;var be=(e,o)=>{for(var r in o)k(e,r,{get:o[r],enumerable:!0})},Se=(e,o,r,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of Ne(o))!ve.call(e,n)&&n!==r&&k(e,n,{get:()=>o[n],enumerable:!(t=ye(o,n))||t.enumerable});return e};var Le=e=>Se(k({},"__esModule",{value:!0}),e);var Oe={};be(Oe,{AscendingBranchingNode:()=>q,BranchingNode:()=>f,DecimalSeparatorNode:()=>F,DescendingBranchingNode:()=>W,DigitNode:()=>V,KeyboardMemory:()=>L,LatexConfiguration:()=>Z,LatexParserConfiguration:()=>Y,LeafNode:()=>K,MatrixNode:()=>z,Placeholder:()=>c,RoundBracketsNode:()=>U,StandardBranchingNode:()=>g,StandardLeafNode:()=>M,TreeNode:()=>u,deleteLeft:()=>ee,deleteRight:()=>X,deleteSelection:()=>ce,enterSelectionMode:()=>me,getEditModeLatex:()=>te,getViewModeLatex:()=>ne,inSelectionMode:()=>ue,insert:()=>a,insertWithEncapsulateCurrent:()=>j,insertWithEncapsulateSelection:()=>se,insertWithEncapsulateSelectionAndPrevious:()=>ae,leaveSelectionMode:()=>_,moveDown:()=>de,moveLeft:()=>fe,moveRight:()=>y,moveUp:()=>pe,parseLatex:()=>E,selectLeft:()=>he,selectRight:()=>ge});function te(e,o){return e.syntaxTreeRoot.getLatex(e,o)}function O(e){return e.toLowerCase()!=e.toUpperCase()}function oe(e){if(e.length==0)return!1;if(O(e[e.length-1]))for(let o=e.length-2;o>=0;o--){let r=e[o];if(!O(r))return r=="\\"}return!1}function w(...e){let o="";for(let r=0;r<e.length;r++){let t=e[r];oe(o)&&O(t[0])&&(o+=" "),o+=t}return o}var c=class{constructor(){this.parentNode=null;this.nodes=[]}getLatex(o,r){let t=()=>w(...this.nodes.map(n=>n.getLatex(o,r)));return o.inclusiveSelectionLeftBorder===this?w(r.selectionHightlightStart,t()):this===o.current?this.nodes.length==0?r.activePlaceholderLatex:w(r.activePlaceholderLatex,t()):this.nodes.length==0?r.passivePlaceholderLatex:t()}};var L=class{constructor(){this.syntaxTreeRoot=new c;this.current=this.syntaxTreeRoot;this.selectionDiff=null;this.inclusiveSelectionRightBorder=null;this.inclusiveSelectionLeftBorder=null}};var Me=new L;function ne(e,o){return(e instanceof L?e.syntaxTreeRoot:e).getLatex(Me,o)}function ie(e,o){let r=!1;for(let t=e.length-1;t>=0;t--){let n=e[t];if(!r){n===o&&(r=!0);continue}if(n.nodes.length>0)return n}return null}function S(e){return e.length==0?null:e[e.length-1]}function h(e,o){let r=e.indexOf(o);return r>0?e[r-1]:null}function T(e,o){let r=e.indexOf(o);e.splice(r,1)}var u=class{getLatex(o,r){let t=this.getLatexPart(o,r);return o.selectionDiff!=null&&o.selectionDiff!=0?(o.inclusiveSelectionLeftBorder===this&&(t=w(r.selectionHightlightStart,t)),o.inclusiveSelectionRightBorder===this&&(t=w(t,r.selectionHightlightEnd)),t):o.current===this?w(t,r.activePlaceholderLatex):t}};var f=class extends u{constructor(r){super();this.placeholders=r,this.placeholders.forEach(t=>{t.parentNode=this})}getMoveDownSuggestion(r){return null}getMoveUpSuggestion(r){return null}};function x(e){return e[e.length-1]}var K=class extends u{};var P=class extends K{};function Q(e,o,r){for(let t=e-1;t>=0;t--){let n=o[t];if(n instanceof P)T(o,n),r.nodes.unshift(n),n.parentPlaceholder=r;else break}}function C(e){let o=e.parentNode,r=o.parentPlaceholder.nodes.indexOf(o);o.parentPlaceholder.nodes.splice(r,1,...e.nodes);for(let t of e.nodes)t.parentPlaceholder=o.parentPlaceholder}function ee(e){var o;if(e.current instanceof c){if(e.current.parentNode==null||e.current.nodes.length>0)return;{let r=ie(e.current.parentNode.placeholders,e.current);if(r)e.current.parentNode.placeholders.length==2&&e.current===e.current.parentNode.placeholders[1]&&e.current.nodes.length==0?(C(r),e.current=x(r.nodes)):(r.nodes.pop(),e.current=(o=S(r.nodes))!=null?o:r);else if(e.current.parentNode.placeholders.every(t=>t.nodes.length==0)){let t=e.current.parentNode.parentPlaceholder,n=h(t.nodes,e.current.parentNode);T(t.nodes,e.current.parentNode),e.current=n!=null?n:t}else if(e.current.parentNode.placeholders[0]===e.current&&e.current.nodes.length==0&&e.current.parentNode.placeholders.some(t=>t.nodes.length!=0)){let t=h(e.current.parentNode.parentPlaceholder.nodes,e.current.parentNode);if(t!=null)Be(t,e.current),e.current=x(e.current.nodes);else{let n=e.current.parentNode.placeholders.filter(i=>i.nodes.length!=0);if(n.length==1){let i=n[0].nodes,l=e.current.parentNode.parentPlaceholder,N=l.nodes.indexOf(e.current.parentNode);for(let d of i)d.parentPlaceholder=l;l.nodes.splice(N,1,...i),e.current=x(i)}}}}}else if(e.current instanceof f&&e.current.placeholders[0].nodes.length>0&&e.current.placeholders.slice(1).every(r=>r.nodes.length==0)){let r=e.current.placeholders[0];C(r),e.current=x(r.nodes)}else if(e.current instanceof f&&e.current.placeholders.some(r=>r.nodes.length>0))e.current=x(e.current.placeholders.flatMap(r=>r.nodes)),ee(e);else{let r=h(e.current.parentPlaceholder.nodes,e.current);T(e.current.parentPlaceholder.nodes,e.current),e.current=r!=null?r:e.current.parentPlaceholder}}function Be(e,o){T(o.parentNode.parentPlaceholder.nodes,e),o.nodes.push(e);let r=e.parentPlaceholder;e.parentPlaceholder=o,e instanceof P&&Q(r.nodes.length-1,r.nodes,o)}function R(e,o){let r=e.indexOf(o);return r!=-1&&r<e.length-1?e[r+1]:null}function X(e){var o;if(e.current instanceof c)if(e.current.parentNode!=null&&e.current.parentNode.placeholders.every(r=>r.nodes.length==0)){let r=h(e.current.parentNode.parentPlaceholder.nodes,e.current.parentNode);T(e.current.parentNode.parentPlaceholder.nodes,e.current.parentNode),e.current=r!=null?r:e.current.parentNode.parentPlaceholder}else{let r=e.current.nodes;if(r.length>0)le(e,r[0]);else if(e.current.parentNode!=null){let t=e.current.parentNode,n=t.placeholders;if(n[0]==e.current&&n.length==2){let i=n[1];e.current=(o=h(t.parentPlaceholder.nodes,t))!=null?o:t.parentPlaceholder,C(i)}else for(let i=n.indexOf(e.current)+1;i<n.length;i++)if(n[i].nodes.length>0){e.current=n[i],X(e);return}}}else{let r=R(e.current.parentPlaceholder.nodes,e.current);r!=null&&le(e,r)}}function le(e,o){o instanceof f?o.placeholders.length==1&&o.placeholders[0].nodes.length>0?C(o.placeholders[0]):o.placeholders.length==2&&o.placeholders[0].nodes.length==0&&o.placeholders[1].nodes.length>0?C(o.placeholders[1]):(e.current=o.placeholders[0],X(e)):T(o.parentPlaceholder.nodes,o)}function _(e){e.selectionDiff=null,e.inclusiveSelectionRightBorder=null,e.inclusiveSelectionLeftBorder=null}function $(e){var r;if(e.selectionDiff==null)throw"Enter selection mode before calling this method.";if(e.selectionDiff==0)return _(e),[];let o=e.selectionDiff;if(e.current instanceof c)return _(e),e.current.nodes.splice(0,o);{let t=e.current.parentPlaceholder.nodes,n=t.indexOf(e.inclusiveSelectionLeftBorder);return e.current=(r=h(t,e.inclusiveSelectionLeftBorder))!=null?r:e.current.parentPlaceholder,_(e),t.splice(n,Te(o))}}function Te(e){return e<0?-e:e}function ce(e){$(e)}function y(e){var o;if(e.current instanceof c)if(e.current.nodes.length>0){let r=e.current.nodes[0];e.current=r instanceof f?r.placeholders[0]:r}else{if(e.current.parentNode==null)return;e.current=(o=R(e.current.parentNode.placeholders,e.current))!=null?o:e.current.parentNode}else{let r=R(e.current.parentPlaceholder.nodes,e.current);if(r!=null)e.current=r instanceof f?r.placeholders[0]:r;else{let t=e.current.parentPlaceholder.parentNode;if(t!=null){let n=R(t.placeholders,e.current.parentPlaceholder);e.current=n!=null?n:t}}}}function a(e,o){if(e.current instanceof c)e.current.nodes.unshift(o),o.parentPlaceholder=e.current;else{let r=e.current.parentPlaceholder,t=r.nodes.indexOf(e.current);r.nodes.splice(t+1,0,o),o.parentPlaceholder=r}y(e)}var g=class extends f{constructor(r,t,...n){let i=n.length+1,l=new Array;for(let N=0;N<i;N++)l.push(new c);super(l);this.before=r,this.then=t,this.rest=n}getLatexPart(r,t){let n=this.before+this.placeholders[0].getLatex(r,t)+this.then;for(let i=0;i<this.rest.length;i++)n+=this.placeholders[i+1].getLatex(r,t)+this.rest[i];return n}};var U=class extends g{constructor(o=String.raw`\left(`,r=String.raw`\right)`){super(o,r)}};function H(e,o){for(let r of e)r.parentPlaceholder=o,o.nodes.push(r)}function j(e,o,r){var n;let t=o.placeholders[0];if(e.current instanceof u){let i=e.current.parentPlaceholder.nodes,l=i.indexOf(e.current);i[l]=o,o.parentPlaceholder=e.current.parentPlaceholder,e.current instanceof U&&(r!=null&&r.deleteOuterRoundBracketsIfAny)?(H(e.current.placeholders[0].nodes,t),e.current=(n=R(o.placeholders,t))!=null?n:o):e.current instanceof P?(t.nodes.push(e.current),e.current.parentPlaceholder=t,Q(l,i,t),y(e)):(t.nodes.push(e.current),e.current.parentPlaceholder=t,y(e))}else a(e,o)}function se(e,o){let r=$(e);if(a(e,o),r.length>0){let t=o.placeholders[0];H(r,t),e.current=x(r),y(e)}}function ae(e,o){var n;if(o.placeholders.length<2)throw"Expected 2 placeholders.";let r=$(e),t=o.placeholders[1];H(r,t),j(e,o),e.current=(n=S(r))!=null?n:t}function de(e){var t;let o=e.current instanceof c?e.current:e.current.parentPlaceholder,r;for(;;){if(o.parentNode==null)return;r=o.parentNode;let n=r.getMoveDownSuggestion(o);if(n!=null){e.current=(t=S(n.nodes))!=null?t:n;return}o=r.parentPlaceholder}}function fe(e){var o,r,t;if(e.current instanceof c){if(e.current.parentNode==null)return;let n=h(e.current.parentNode.placeholders,e.current);if(n!==null)e.current=(o=S(n.nodes))!=null?o:n;else{let i=e.current.parentNode.parentPlaceholder,l=h(i.nodes,e.current.parentNode);e.current=l!=null?l:i}}else if(e.current instanceof f){let n=x(e.current.placeholders);e.current=(r=S(n.nodes))!=null?r:n}else e.current=(t=h(e.current.parentPlaceholder.nodes,e.current))!=null?t:e.current.parentPlaceholder}function pe(e){var t;let o=e.current instanceof c?e.current:e.current.parentPlaceholder,r;for(;;){if(o.parentNode==null)return;r=o.parentNode;let n=r.getMoveUpSuggestion(o);if(n!=null){e.current=(t=S(n.nodes))!=null?t:n;return}o=r.parentPlaceholder}}function D(e,o){if(e.selectionDiff=o,o==0)e.inclusiveSelectionLeftBorder=null,e.inclusiveSelectionRightBorder=null;else if(e.current instanceof c)e.inclusiveSelectionLeftBorder=e.current,e.inclusiveSelectionRightBorder=e.current.nodes[o-1];else{let r=e.current.parentPlaceholder.nodes,t=r.indexOf(e.current);if(o>0)e.inclusiveSelectionLeftBorder=r[t+1],e.inclusiveSelectionRightBorder=r[t+o];else{let n=t+o+1;if(n<0)throw"The TreeNode at index 0 of the current Placeholder is as far as you can go left if current is a TreeNode.";e.inclusiveSelectionLeftBorder=r[n],e.inclusiveSelectionRightBorder=e.current}}}function me(e){D(e,0)}function ue(e){return e.selectionDiff!=null}function he(e){var r;let o=(r=e.selectionDiff)!=null?r:0;e.current instanceof u&&e.current.parentPlaceholder.nodes.indexOf(e.current)+o>=0||e.current instanceof c&&o>0?D(e,o-1):e.inclusiveSelectionLeftBorder instanceof u&&e.inclusiveSelectionLeftBorder.parentPlaceholder.nodes.indexOf(e.inclusiveSelectionLeftBorder)==0&&e.inclusiveSelectionLeftBorder.parentPlaceholder.parentNode!=null&&(e.current=e.inclusiveSelectionLeftBorder.parentPlaceholder.parentNode,D(e,-1))}function ge(e){var r,t;let o=(r=e.selectionDiff)!=null?r:0;if(e.current instanceof c&&o<e.current.nodes.length||e.current instanceof u&&e.current.parentPlaceholder.nodes.indexOf(e.current)+o<e.current.parentPlaceholder.nodes.length-1)D(e,o+1);else if(e.inclusiveSelectionRightBorder instanceof u&&x(e.inclusiveSelectionRightBorder.parentPlaceholder.nodes)==e.inclusiveSelectionRightBorder&&e.inclusiveSelectionRightBorder.parentPlaceholder.parentNode!=null){let n=e.inclusiveSelectionRightBorder.parentPlaceholder.parentNode;e.current=(t=h(n.parentPlaceholder.nodes,n))!=null?t:n.parentPlaceholder,D(e,1)}}var q=class extends g{getMoveDownSuggestion(o){let r=this.placeholders.indexOf(o);return r>0?this.placeholders[r-1]:null}getMoveUpSuggestion(o){let r=this.placeholders.indexOf(o);return r<this.placeholders.length-1?this.placeholders[r+1]:null}};var F=class extends P{constructor(r="."){super();this.latex=typeof r=="string"?()=>r:r}getLatexPart(r,t){return this.latex()}};var W=class extends g{getMoveDownSuggestion(o){let r=this.placeholders.indexOf(o);return r<this.placeholders.length-1?this.placeholders[r+1]:null}getMoveUpSuggestion(o){let r=this.placeholders.indexOf(o);return r>0?this.placeholders[r-1]:null}};var V=class extends P{constructor(r){super();this.latex=r}getLatexPart(r,t){return this.latex}};var M=class extends K{constructor(r){super();this.latex=typeof r=="string"?()=>r:r}getLatexPart(r,t){return this.latex()}};function I(e,o,r){let t=e.slice(-1),n=r.slice(e.length),i=0;for(let l=0;l<n.length;l++){if(n[l]==o){if(i==0)return{content:n.slice(0,l),rest:n.slice(l+1)};i--;continue}let N=["\\"+t,"\\"+o,String.raw`\left`+t,String.raw`\right`+o],d=n.slice(l);for(let m of N)if(d.length>=m.length&&d.startsWith(m)){l+=m.length;continue}n[l]==t&&i++}throw`A closing ${o} is missing.`}var z=class extends f{constructor(r,t,n){let i=[],l=[];for(let N=0;N<n;N++){let d=[];for(let m=0;m<t;m++){let s=new c;d.push(s),l.push(s)}i.push(d)}super(l);this.grid=i,this.matrixType=r,this.width=t}getLatexPart(r,t){let n=String.raw`\begin{${this.matrixType}}`;return n+=this.grid.map(i=>i.map(l=>l.getLatex(r,t)).join(" & ")).join(String.raw` \\ `),n+=String.raw`\end{${this.matrixType}}`,n}getMoveDownSuggestion(r){let{rowIndex:t,columnIndex:n}=this.getPositionOf(r);return t+1<this.grid.length?this.grid[t+1][n]:null}getMoveUpSuggestion(r){let{rowIndex:t,columnIndex:n}=this.getPositionOf(r);return t-1>=0?this.grid[t-1][n]:null}getPositionOf(r){let t=this.placeholders.indexOf(r);if(t==-1)throw"The provided Placeholder is not part of this MatrixNode.";let n=Math.floor(t/this.width),i=t-n*this.width;return{rowIndex:n,columnIndex:i}}};function E(e,o,r){var i;let t=e==null?void 0:e.trim();if(t==null||t=="")return new L;let n=new L;for(;t!="";){if(t[0]==" "){t=t.trimStart();continue}if(t.startsWith(r.decimalSeparator)){a(n,new F(r.decimalSeparator)),t=t.slice(r.decimalSeparator.length);continue}if(["1","2","3","4","5","6","7","8","9","0"].includes(t[0])||(i=r.additionalDigits)!=null&&i.includes(t[0])){a(n,new V(t[0])),t=t.slice(1);continue}let l=!1;if(t.startsWith(String.raw`\begin{`)){let d=I(String.raw`\begin{`,"}",t);if(!d.content.endsWith("matrix")&&!d.content.endsWith("cases"))throw String.raw`Expected a word ending with 'matrix' or 'cases' after '\begin{'.`;let s=d.rest.slice(0,d.rest.indexOf(String.raw`\end{${d.content}}`)).split(String.raw`\\`);a(n,new z(d.content,s[0].split("&").length,s.length));for(let v of s)for(let b of v.split("&")){let A=E(b,o,r).syntaxTreeRoot.nodes;for(let B of A)a(n,B),n.current=B;y(n)}let p=String.raw`\end{${d.content}}`;t=t.slice(t.indexOf(p)+p.length);continue}if(t.startsWith("\\")){for(let s of["\\left\\","\\right\\",String.raw`\left`,String.raw`\right`])if(t.startsWith(s)){a(n,new M(s+t[s.length])),t=t.slice(s.length+1),l=!0;break}if(l)continue;for(let s of r.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets){let p=s.slice(0,-3),v=s.slice(-3,-2),b=s.slice(-2,-1),A=s.slice(-1);if(t.startsWith(p)){let B=I(p,v,t);if(B.rest[0]!=b)continue;let G=new W(p,v+b,A);a(n,G);let xe=E(B.content,o,r).syntaxTreeRoot.nodes;for(let J of xe)a(n,J),n.current=J;y(n);let re=I(b,A,B.rest),Pe=E(re.content,o,r).syntaxTreeRoot.nodes;for(let J of Pe)a(n,J),n.current=J;n.current=G,t=re.rest,l=!0;break}}if(l)continue;let d=String.raw`\text{`;if(t.startsWith(d)){let s=I(d,"}",t),p=new g(d,"}");a(n,p);for(let v of s.content)a(n,new M(v));n.current=p,t=s.rest;continue}let m="\\";if(O(t[1])){for(let s=1;s<t.length;s++){let p=t[s];if(O(p))m+=p;else if(p=="{"){m+=p;let v=m,b=I(v,"}",t),A=E(b.content,o,r).syntaxTreeRoot.nodes,B=new g(v,"}");a(n,B);for(let G of A)a(n,G),n.current=G;n.current=B,t=b.rest,l=!0;break}else break}if(l)continue;a(n,new M(m)),t=t.slice(m.length)}else a(n,new M("\\"+t[1])),t=t.slice(2);continue}let N=[["^{",()=>new q("","^{","}")],["_{",()=>new W("","_{","}")]];for(let d of N){let m=d[0];if(t.startsWith(m)){let s=d[1]();j(n,s);let p=I(m,"}",t),v=E(p.content,o,r).syntaxTreeRoot.nodes;for(let b of v)a(n,b),n.current=b;n.current=s,t=p.rest,l=!0;break}}l!=!0&&(a(n,new M(t[0])),t=t.slice(1))}return n}var Y=class{constructor(){this.additionalDigits=null;this.decimalSeparator=".";this.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets=[]}};var Z=class{constructor(){this.activePlaceholderShape=String.raw`\blacksquare`;this.passivePlaceholderShape=String.raw`\square`;this.selectionHightlightStart=String.raw`\colorbox{#ADD8E6}{\(\displaystyle`;this.selectionHightlightEnd=String.raw`\)}`}get activePlaceholderLatex(){return this.activePlaceholderColor==null?this.activePlaceholderShape:String.raw`{\color{${this.activePlaceholderColor}}${this.activePlaceholderShape}}`}get passivePlaceholderLatex(){return this.passivePlaceholderColor==null?this.passivePlaceholderShape:String.raw`{\color{${this.passivePlaceholderColor}}${this.passivePlaceholderShape}}`}};return Le(Oe);})();

@@ -618,2 +618,22 @@ // src/GetLatex/getEditModeLatex.ts

// src/SyntaxTreeComponents/Nodes/BranchingNodes/AscendingBranchingNode.ts
var AscendingBranchingNode = class extends StandardBranchingNode {
getMoveDownSuggestion(fromPlaceholder) {
const currentPlaceholderIndex = this.placeholders.indexOf(fromPlaceholder);
if (currentPlaceholderIndex > 0) {
return this.placeholders[currentPlaceholderIndex - 1];
} else {
return null;
}
}
getMoveUpSuggestion(fromPlaceholder) {
const currentPlaceholderIndex = this.placeholders.indexOf(fromPlaceholder);
if (currentPlaceholderIndex < this.placeholders.length - 1) {
return this.placeholders[currentPlaceholderIndex + 1];
} else {
return null;
}
}
};
// src/SyntaxTreeComponents/Nodes/LeafNodes/DecimalSeparatorNode.ts

@@ -630,2 +650,22 @@ var DecimalSeparatorNode = class extends PartOfNumberWithDigits {

// src/SyntaxTreeComponents/Nodes/BranchingNodes/DescendingBranchingNode.ts
var DescendingBranchingNode = class extends StandardBranchingNode {
getMoveDownSuggestion(fromPlaceholder) {
const currentPlaceholderIndex = this.placeholders.indexOf(fromPlaceholder);
if (currentPlaceholderIndex < this.placeholders.length - 1) {
return this.placeholders[currentPlaceholderIndex + 1];
} else {
return null;
}
}
getMoveUpSuggestion(fromPlaceholder) {
const currentPlaceholderIndex = this.placeholders.indexOf(fromPlaceholder);
if (currentPlaceholderIndex > 0) {
return this.placeholders[currentPlaceholderIndex - 1];
} else {
return null;
}
}
};
// src/SyntaxTreeComponents/Nodes/LeafNodes/DigitNode.ts

@@ -653,2 +693,31 @@ var DigitNode = class extends PartOfNumberWithDigits {

// src/LatexParser/helpers/getBracketPairContent.ts
function getBracketPairContent(opening, closingBracket, sWithOpening) {
const openingBracket = opening.slice(-1);
const s = sWithOpening.slice(opening.length);
let level = 0;
for (let closingBracketIndex = 0; closingBracketIndex < s.length; closingBracketIndex++) {
if (s[closingBracketIndex] == closingBracket) {
if (level == 0) {
return { content: s.slice(0, closingBracketIndex), rest: s.slice(closingBracketIndex + 1) };
} else {
level--;
continue;
}
}
const toIgnores = ["\\" + openingBracket, "\\" + closingBracket, String.raw`\left` + openingBracket, String.raw`\right` + closingBracket];
const currentPosition = s.slice(closingBracketIndex);
for (const toIgnore of toIgnores) {
if (currentPosition.length >= toIgnore.length && currentPosition.startsWith(toIgnore)) {
closingBracketIndex += toIgnore.length;
continue;
}
}
if (s[closingBracketIndex] == openingBracket) {
level++;
}
}
throw `A closing ${closingBracket} is missing.`;
}
// src/SyntaxTreeComponents/Nodes/BranchingNodes/MatrixNode.ts

@@ -706,40 +775,179 @@ var MatrixNode = class extends BranchingNode {

// src/SyntaxTreeComponents/Nodes/BranchingNodes/AscendingBranchingNode.ts
var AscendingBranchingNode = class extends StandardBranchingNode {
getMoveDownSuggestion(fromPlaceholder) {
const currentPlaceholderIndex = this.placeholders.indexOf(fromPlaceholder);
if (currentPlaceholderIndex > 0) {
return this.placeholders[currentPlaceholderIndex - 1];
} else {
return null;
}
// src/LatexParser/parseLatex.ts
function parseLatex(latex, latexConfiguration, latexParserConfiguration) {
var _a;
let x = latex == null ? void 0 : latex.trim();
if (x == null || x == "") {
return new KeyboardMemory();
}
getMoveUpSuggestion(fromPlaceholder) {
const currentPlaceholderIndex = this.placeholders.indexOf(fromPlaceholder);
if (currentPlaceholderIndex < this.placeholders.length - 1) {
return this.placeholders[currentPlaceholderIndex + 1];
} else {
return null;
const k = new KeyboardMemory();
while (x != "") {
if (x[0] == " ") {
x = x.trimStart();
continue;
}
if (x.startsWith(latexParserConfiguration.decimalSeparator)) {
insert(k, new DecimalSeparatorNode(latexParserConfiguration.decimalSeparator));
x = x.slice(latexParserConfiguration.decimalSeparator.length);
continue;
}
if (["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"].includes(x[0]) || ((_a = latexParserConfiguration.additionalDigits) == null ? void 0 : _a.includes(x[0]))) {
insert(k, new DigitNode(x[0]));
x = x.slice(1);
continue;
}
let handled = false;
if (x.startsWith(String.raw`\begin{`)) {
const matrixTypeAndRest = getBracketPairContent(String.raw`\begin{`, "}", x);
if (!matrixTypeAndRest.content.endsWith("matrix") && !matrixTypeAndRest.content.endsWith("cases")) {
throw String.raw`Expected a word ending with 'matrix' or 'cases' after '\begin{'.`;
}
const matrixContent = matrixTypeAndRest.rest.slice(0, matrixTypeAndRest.rest.indexOf(String.raw`\end{${matrixTypeAndRest.content}}`));
const lines = matrixContent.split(String.raw`\\`);
insert(k, new MatrixNode(matrixTypeAndRest.content, lines[0].split("&").length, lines.length));
for (const line of lines) {
for (const latex2 of line.split("&")) {
const nodes = parseLatex(latex2, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
for (const node of nodes) {
insert(k, node);
k.current = node;
}
moveRight(k);
}
}
const matrixEnd = String.raw`\end{${matrixTypeAndRest.content}}`;
x = x.slice(x.indexOf(matrixEnd) + matrixEnd.length);
continue;
}
if (x.startsWith("\\")) {
for (const prefix of ["\\left\\", "\\right\\", String.raw`\left`, String.raw`\right`]) {
if (x.startsWith(prefix)) {
insert(k, new StandardLeafNode(prefix + x[prefix.length]));
x = x.slice(prefix.length + 1);
handled = true;
break;
}
}
if (handled) {
continue;
}
for (const commandWithBrackets of latexParserConfiguration.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets) {
const opening = commandWithBrackets.slice(0, -3);
const closingBracket1 = commandWithBrackets.slice(-3, -2);
const openingBracket2 = commandWithBrackets.slice(-2, -1);
const closingBracket2 = commandWithBrackets.slice(-1);
if (x.startsWith(opening)) {
const numeratorAndRest = getBracketPairContent(opening, closingBracket1, x);
if (numeratorAndRest.rest[0] != openingBracket2) {
continue;
}
const node = new DescendingBranchingNode(opening, closingBracket1 + openingBracket2, closingBracket2);
insert(k, node);
const numerator = parseLatex(numeratorAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
for (const node2 of numerator) {
insert(k, node2);
k.current = node2;
}
moveRight(k);
const denominatorAndRest = getBracketPairContent(openingBracket2, closingBracket2, numeratorAndRest.rest);
const denominator = parseLatex(denominatorAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
for (const node2 of denominator) {
insert(k, node2);
k.current = node2;
}
k.current = node;
x = denominatorAndRest.rest;
handled = true;
break;
}
}
if (handled) {
continue;
}
const textOpening = String.raw`\text{`;
if (x.startsWith(textOpening)) {
const bracketPairContentAndRest = getBracketPairContent(textOpening, "}", x);
const textNode = new StandardBranchingNode(textOpening, "}");
insert(k, textNode);
for (const character of bracketPairContentAndRest.content) {
insert(k, new StandardLeafNode(character));
}
k.current = textNode;
x = bracketPairContentAndRest.rest;
continue;
}
let command = "\\";
if (isLetter(x[1])) {
for (let i = 1; i < x.length; i++) {
const character = x[i];
if (isLetter(character)) {
command += character;
} else if (character == "{") {
command += character;
const opening = command;
const bracketPairContentAndRest = getBracketPairContent(opening, "}", x);
const placeholderContent = parseLatex(bracketPairContentAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
const branchingNode = new StandardBranchingNode(opening, "}");
insert(k, branchingNode);
for (const node of placeholderContent) {
insert(k, node);
k.current = node;
}
k.current = branchingNode;
x = bracketPairContentAndRest.rest;
handled = true;
break;
} else {
break;
}
}
if (handled) {
continue;
}
insert(k, new StandardLeafNode(command));
x = x.slice(command.length);
} else {
insert(k, new StandardLeafNode("\\" + x[1]));
x = x.slice(2);
}
continue;
}
const various = [
["^{", () => new AscendingBranchingNode("", "^{", "}")],
["_{", () => new DescendingBranchingNode("", "_{", "}")]
];
for (const opening_getTreeNode of various) {
const opening = opening_getTreeNode[0];
if (x.startsWith(opening)) {
const node = opening_getTreeNode[1]();
insertWithEncapsulateCurrent(k, node);
const bracketPairContentAndRest = getBracketPairContent(opening, "}", x);
const secondPlaceholderNodes = parseLatex(bracketPairContentAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
for (const node2 of secondPlaceholderNodes) {
insert(k, node2);
k.current = node2;
}
k.current = node;
x = bracketPairContentAndRest.rest;
handled = true;
break;
}
}
if (handled == true) {
continue;
}
insert(k, new StandardLeafNode(x[0]));
x = x.slice(1);
continue;
}
};
return k;
}
// src/SyntaxTreeComponents/Nodes/BranchingNodes/DescendingBranchingNode.ts
var DescendingBranchingNode = class extends StandardBranchingNode {
getMoveDownSuggestion(fromPlaceholder) {
const currentPlaceholderIndex = this.placeholders.indexOf(fromPlaceholder);
if (currentPlaceholderIndex < this.placeholders.length - 1) {
return this.placeholders[currentPlaceholderIndex + 1];
} else {
return null;
}
// src/LatexParser/LatexParserConfiguration.ts
var LatexParserConfiguration = class {
constructor() {
this.additionalDigits = null;
this.decimalSeparator = ".";
this.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets = [];
}
getMoveUpSuggestion(fromPlaceholder) {
const currentPlaceholderIndex = this.placeholders.indexOf(fromPlaceholder);
if (currentPlaceholderIndex > 0) {
return this.placeholders[currentPlaceholderIndex - 1];
} else {
return null;
}
}
};

@@ -778,2 +986,3 @@

LatexConfiguration,
LatexParserConfiguration,
LeafNode,

@@ -802,4 +1011,5 @@ MatrixNode,

moveUp,
parseLatex,
selectLeft,
selectRight
};

@@ -1,1 +0,1 @@

function G(e,o){return e.syntaxTreeRoot.getLatex(e,o)}function B(e){return e.toLowerCase()!=e.toUpperCase()}function q(e){if(e.length==0)return!1;if(B(e[e.length-1]))for(let o=e.length-2;o>=0;o--){let r=e[o];if(!B(r))return r=="\\"}return!1}function g(...e){let o="";for(let r=0;r<e.length;r++){let t=e[r];q(o)&&B(t[0])&&(o+=" "),o+=t}return o}var i=class{constructor(){this.parentNode=null;this.nodes=[]}getLatex(o,r){let t=()=>g(...this.nodes.map(n=>n.getLatex(o,r)));return o.inclusiveSelectionLeftBorder===this?g(r.selectionHightlightStart,t()):this===o.current?this.nodes.length==0?r.activePlaceholderLatex:g(r.activePlaceholderLatex,t()):this.nodes.length==0?r.passivePlaceholderLatex:t()}};var L=class{constructor(){this.syntaxTreeRoot=new i;this.current=this.syntaxTreeRoot;this.selectionDiff=null;this.inclusiveSelectionRightBorder=null;this.inclusiveSelectionLeftBorder=null}};var J=new L;function Q(e,o){return(e instanceof L?e.syntaxTreeRoot:e).getLatex(J,o)}function F(e,o){let r=!1;for(let t=e.length-1;t>=0;t--){let n=e[t];if(!r){n===o&&(r=!0);continue}if(n.nodes.length>0)return n}return null}function m(e){return e.length==0?null:e[e.length-1]}function s(e,o){let r=e.indexOf(o);return r>0?e[r-1]:null}function u(e,o){let r=e.indexOf(o);e.splice(r,1)}var d=class{getLatex(o,r){let t=this.getLatexPart(o,r);return o.selectionDiff!=null&&o.selectionDiff!=0?(o.inclusiveSelectionLeftBorder===this&&(t=g(r.selectionHightlightStart,t)),o.inclusiveSelectionRightBorder===this&&(t=g(t,r.selectionHightlightEnd)),t):o.current===this?g(t,r.activePlaceholderLatex):t}};var a=class extends d{constructor(r){super();this.placeholders=r,this.placeholders.forEach(t=>{t.parentNode=this})}getMoveDownSuggestion(r){return null}getMoveUpSuggestion(r){return null}};function p(e){return e[e.length-1]}var v=class extends d{};var f=class extends v{};function C(e,o,r){for(let t=e-1;t>=0;t--){let n=o[t];if(n instanceof f)u(o,n),r.nodes.unshift(n),n.parentPlaceholder=r;else break}}function b(e){let o=e.parentNode,r=o.parentPlaceholder.nodes.indexOf(o);o.parentPlaceholder.nodes.splice(r,1,...e.nodes);for(let t of e.nodes)t.parentPlaceholder=o.parentPlaceholder}function V(e){var o;if(e.current instanceof i){if(e.current.parentNode==null||e.current.nodes.length>0)return;{let r=F(e.current.parentNode.placeholders,e.current);if(r)e.current.parentNode.placeholders.length==2&&e.current===e.current.parentNode.placeholders[1]&&e.current.nodes.length==0?(b(r),e.current=p(r.nodes)):(r.nodes.pop(),e.current=(o=m(r.nodes))!=null?o:r);else if(e.current.parentNode.placeholders.every(t=>t.nodes.length==0)){let t=e.current.parentNode.parentPlaceholder,n=s(t.nodes,e.current.parentNode);u(t.nodes,e.current.parentNode),e.current=n!=null?n:t}else if(e.current.parentNode.placeholders[0]===e.current&&e.current.nodes.length==0&&e.current.parentNode.placeholders.some(t=>t.nodes.length!=0)){let t=s(e.current.parentNode.parentPlaceholder.nodes,e.current.parentNode);if(t!=null)X(t,e.current),e.current=p(e.current.nodes);else{let n=e.current.parentNode.placeholders.filter(l=>l.nodes.length!=0);if(n.length==1){let l=n[0].nodes,c=e.current.parentNode.parentPlaceholder,N=c.nodes.indexOf(e.current.parentNode);for(let D of l)D.parentPlaceholder=c;c.nodes.splice(N,1,...l),e.current=p(l)}}}}}else if(e.current instanceof a&&e.current.placeholders[0].nodes.length>0&&e.current.placeholders.slice(1).every(r=>r.nodes.length==0)){let r=e.current.placeholders[0];b(r),e.current=p(r.nodes)}else if(e.current instanceof a&&e.current.placeholders.some(r=>r.nodes.length>0))e.current=p(e.current.placeholders.flatMap(r=>r.nodes)),V(e);else{let r=s(e.current.parentPlaceholder.nodes,e.current);u(e.current.parentPlaceholder.nodes,e.current),e.current=r!=null?r:e.current.parentPlaceholder}}function X(e,o){u(o.parentNode.parentPlaceholder.nodes,e),o.nodes.push(e);let r=e.parentPlaceholder;e.parentPlaceholder=o,e instanceof f&&C(r.nodes.length-1,r.nodes,o)}function x(e,o){let r=e.indexOf(o);return r!=-1&&r<e.length-1?e[r+1]:null}function w(e){var o;if(e.current instanceof i)if(e.current.parentNode!=null&&e.current.parentNode.placeholders.every(r=>r.nodes.length==0)){let r=s(e.current.parentNode.parentPlaceholder.nodes,e.current.parentNode);u(e.current.parentNode.parentPlaceholder.nodes,e.current.parentNode),e.current=r!=null?r:e.current.parentNode.parentPlaceholder}else{let r=e.current.nodes;if(r.length>0)z(e,r[0]);else if(e.current.parentNode!=null){let t=e.current.parentNode,n=t.placeholders;if(n[0]==e.current&&n.length==2){let l=n[1];e.current=(o=s(t.parentPlaceholder.nodes,t))!=null?o:t.parentPlaceholder,b(l)}else for(let l=n.indexOf(e.current)+1;l<n.length;l++)if(n[l].nodes.length>0){e.current=n[l],w(e);return}}}else{let r=x(e.current.parentPlaceholder.nodes,e.current);r!=null&&z(e,r)}}function z(e,o){o instanceof a?o.placeholders.length==1&&o.placeholders[0].nodes.length>0?b(o.placeholders[0]):o.placeholders.length==2&&o.placeholders[0].nodes.length==0&&o.placeholders[1].nodes.length>0?b(o.placeholders[1]):(e.current=o.placeholders[0],w(e)):u(o.parentPlaceholder.nodes,o)}function O(e){e.selectionDiff=null,e.inclusiveSelectionRightBorder=null,e.inclusiveSelectionLeftBorder=null}function S(e){var r;if(e.selectionDiff==null)throw"Enter selection mode before calling this method.";if(e.selectionDiff==0)return O(e),[];let o=e.selectionDiff;if(e.current instanceof i)return O(e),e.current.nodes.splice(0,o);{let t=e.current.parentPlaceholder.nodes,n=t.indexOf(e.inclusiveSelectionLeftBorder);return e.current=(r=s(t,e.inclusiveSelectionLeftBorder))!=null?r:e.current.parentPlaceholder,O(e),t.splice(n,Y(o))}}function Y(e){return e<0?-e:e}function Z(e){S(e)}function P(e){var o;if(e.current instanceof i)if(e.current.nodes.length>0){let r=e.current.nodes[0];e.current=r instanceof a?r.placeholders[0]:r}else{if(e.current.parentNode==null)return;e.current=(o=x(e.current.parentNode.placeholders,e.current))!=null?o:e.current.parentNode}else{let r=x(e.current.parentPlaceholder.nodes,e.current);if(r!=null)e.current=r instanceof a?r.placeholders[0]:r;else{let t=e.current.parentPlaceholder.parentNode;if(t!=null){let n=x(t.placeholders,e.current.parentPlaceholder);e.current=n!=null?n:t}}}}function T(e,o){if(e.current instanceof i)e.current.nodes.unshift(o),o.parentPlaceholder=e.current;else{let r=e.current.parentPlaceholder,t=r.nodes.indexOf(e.current);r.nodes.splice(t+1,0,o),o.parentPlaceholder=r}P(e)}var h=class extends a{constructor(r,t,...n){let l=n.length+1,c=new Array;for(let N=0;N<l;N++)c.push(new i);super(c);this.before=r,this.then=t,this.rest=n}getLatexPart(r,t){let n=this.before+this.placeholders[0].getLatex(r,t)+this.then;for(let l=0;l<this.rest.length;l++)n+=this.placeholders[l+1].getLatex(r,t)+this.rest[l];return n}};var K=class extends h{constructor(o=String.raw`\left(`,r=String.raw`\right)`){super(o,r)}};function M(e,o){for(let r of e)r.parentPlaceholder=o,o.nodes.push(r)}function R(e,o,r){var n;let t=o.placeholders[0];if(e.current instanceof d){let l=e.current.parentPlaceholder.nodes,c=l.indexOf(e.current);l[c]=o,o.parentPlaceholder=e.current.parentPlaceholder,e.current instanceof K&&(r!=null&&r.deleteOuterRoundBracketsIfAny)?(M(e.current.placeholders[0].nodes,t),e.current=(n=x(o.placeholders,t))!=null?n:o):e.current instanceof f?(t.nodes.push(e.current),e.current.parentPlaceholder=t,C(c,l,t),P(e)):(t.nodes.push(e.current),e.current.parentPlaceholder=t,P(e))}else T(e,o)}function k(e,o){let r=S(e);if(T(e,o),r.length>0){let t=o.placeholders[0];M(r,t),e.current=p(r),P(e)}}function ee(e,o){var n;if(o.placeholders.length<2)throw"Expected 2 placeholders.";let r=S(e),t=o.placeholders[1];M(r,t),R(e,o),e.current=(n=m(r))!=null?n:t}function re(e){var t;let o=e.current instanceof i?e.current:e.current.parentPlaceholder,r;for(;;){if(o.parentNode==null)return;r=o.parentNode;let n=r.getMoveDownSuggestion(o);if(n!=null){e.current=(t=m(n.nodes))!=null?t:n;return}o=r.parentPlaceholder}}function oe(e){var o,r,t;if(e.current instanceof i){if(e.current.parentNode==null)return;let n=s(e.current.parentNode.placeholders,e.current);if(n!==null)e.current=(o=m(n.nodes))!=null?o:n;else{let l=e.current.parentNode.parentPlaceholder,c=s(l.nodes,e.current.parentNode);e.current=c!=null?c:l}}else if(e.current instanceof a){let n=p(e.current.placeholders);e.current=(r=m(n.nodes))!=null?r:n}else e.current=(t=s(e.current.parentPlaceholder.nodes,e.current))!=null?t:e.current.parentPlaceholder}function te(e){var t;let o=e.current instanceof i?e.current:e.current.parentPlaceholder,r;for(;;){if(o.parentNode==null)return;r=o.parentNode;let n=r.getMoveUpSuggestion(o);if(n!=null){e.current=(t=m(n.nodes))!=null?t:n;return}o=r.parentPlaceholder}}function y(e,o){if(e.selectionDiff=o,o==0)e.inclusiveSelectionLeftBorder=null,e.inclusiveSelectionRightBorder=null;else if(e.current instanceof i)e.inclusiveSelectionLeftBorder=e.current,e.inclusiveSelectionRightBorder=e.current.nodes[o-1];else{let r=e.current.parentPlaceholder.nodes,t=r.indexOf(e.current);if(o>0)e.inclusiveSelectionLeftBorder=r[t+1],e.inclusiveSelectionRightBorder=r[t+o];else{let n=t+o+1;if(n<0)throw"The TreeNode at index 0 of the current Placeholder is as far as you can go left if current is a TreeNode.";e.inclusiveSelectionLeftBorder=r[n],e.inclusiveSelectionRightBorder=e.current}}}function ne(e){y(e,0)}function le(e){return e.selectionDiff!=null}function ie(e){var r;let o=(r=e.selectionDiff)!=null?r:0;e.current instanceof d&&e.current.parentPlaceholder.nodes.indexOf(e.current)+o>=0||e.current instanceof i&&o>0?y(e,o-1):e.inclusiveSelectionLeftBorder instanceof d&&e.inclusiveSelectionLeftBorder.parentPlaceholder.nodes.indexOf(e.inclusiveSelectionLeftBorder)==0&&e.inclusiveSelectionLeftBorder.parentPlaceholder.parentNode!=null&&(e.current=e.inclusiveSelectionLeftBorder.parentPlaceholder.parentNode,y(e,-1))}function ce(e){var r,t;let o=(r=e.selectionDiff)!=null?r:0;if(e.current instanceof i&&o<e.current.nodes.length||e.current instanceof d&&e.current.parentPlaceholder.nodes.indexOf(e.current)+o<e.current.parentPlaceholder.nodes.length-1)y(e,o+1);else if(e.inclusiveSelectionRightBorder instanceof d&&p(e.inclusiveSelectionRightBorder.parentPlaceholder.nodes)==e.inclusiveSelectionRightBorder&&e.inclusiveSelectionRightBorder.parentPlaceholder.parentNode!=null){let n=e.inclusiveSelectionRightBorder.parentPlaceholder.parentNode;e.current=(t=s(n.parentPlaceholder.nodes,n))!=null?t:n.parentPlaceholder,y(e,1)}}var I=class extends f{constructor(r="."){super();this.latex=typeof r=="string"?()=>r:r}getLatexPart(r,t){return this.latex()}};var E=class extends f{constructor(r){super();this.latex=r}getLatexPart(r,t){return this.latex}};var W=class extends v{constructor(r){super();this.latex=typeof r=="string"?()=>r:r}getLatexPart(r,t){return this.latex()}};var A=class extends a{constructor(r,t,n){let l=[],c=[];for(let N=0;N<n;N++){let D=[];for(let H=0;H<t;H++){let j=new i;D.push(j),c.push(j)}l.push(D)}super(c);this.grid=l,this.matrixType=r,this.width=t}getLatexPart(r,t){let n=String.raw`\begin{${this.matrixType}}`;return n+=this.grid.map(l=>l.map(c=>c.getLatex(r,t)).join(" & ")).join(String.raw` \\ `),n+=String.raw`\end{${this.matrixType}}`,n}getMoveDownSuggestion(r){let{rowIndex:t,columnIndex:n}=this.getPositionOf(r);return t+1<this.grid.length?this.grid[t+1][n]:null}getMoveUpSuggestion(r){let{rowIndex:t,columnIndex:n}=this.getPositionOf(r);return t-1>=0?this.grid[t-1][n]:null}getPositionOf(r){let t=this.placeholders.indexOf(r);if(t==-1)throw"The provided Placeholder is not part of this MatrixNode.";let n=Math.floor(t/this.width),l=t-n*this.width;return{rowIndex:n,columnIndex:l}}};var U=class extends h{getMoveDownSuggestion(o){let r=this.placeholders.indexOf(o);return r>0?this.placeholders[r-1]:null}getMoveUpSuggestion(o){let r=this.placeholders.indexOf(o);return r<this.placeholders.length-1?this.placeholders[r+1]:null}};var _=class extends h{getMoveDownSuggestion(o){let r=this.placeholders.indexOf(o);return r<this.placeholders.length-1?this.placeholders[r+1]:null}getMoveUpSuggestion(o){let r=this.placeholders.indexOf(o);return r>0?this.placeholders[r-1]:null}};var $=class{constructor(){this.activePlaceholderShape=String.raw`\blacksquare`;this.passivePlaceholderShape=String.raw`\square`;this.selectionHightlightStart=String.raw`\colorbox{#ADD8E6}{\(\displaystyle`;this.selectionHightlightEnd=String.raw`\)}`}get activePlaceholderLatex(){return this.activePlaceholderColor==null?this.activePlaceholderShape:String.raw`{\color{${this.activePlaceholderColor}}${this.activePlaceholderShape}}`}get passivePlaceholderLatex(){return this.passivePlaceholderColor==null?this.passivePlaceholderShape:String.raw`{\color{${this.passivePlaceholderColor}}${this.passivePlaceholderShape}}`}};export{U as AscendingBranchingNode,a as BranchingNode,I as DecimalSeparatorNode,_ as DescendingBranchingNode,E as DigitNode,L as KeyboardMemory,$ as LatexConfiguration,v as LeafNode,A as MatrixNode,i as Placeholder,K as RoundBracketsNode,h as StandardBranchingNode,W as StandardLeafNode,d as TreeNode,V as deleteLeft,w as deleteRight,Z as deleteSelection,ne as enterSelectionMode,G as getEditModeLatex,Q as getViewModeLatex,le as inSelectionMode,T as insert,R as insertWithEncapsulateCurrent,k as insertWithEncapsulateSelection,ee as insertWithEncapsulateSelectionAndPrevious,O as leaveSelectionMode,re as moveDown,oe as moveLeft,P as moveRight,te as moveUp,ie as selectLeft,ce as selectRight};
function le(e,o){return e.syntaxTreeRoot.getLatex(e,o)}function O(e){return e.toLowerCase()!=e.toUpperCase()}function ee(e){if(e.length==0)return!1;if(O(e[e.length-1]))for(let o=e.length-2;o>=0;o--){let r=e[o];if(!O(r))return r=="\\"}return!1}function w(...e){let o="";for(let r=0;r<e.length;r++){let t=e[r];ee(o)&&O(t[0])&&(o+=" "),o+=t}return o}var c=class{constructor(){this.parentNode=null;this.nodes=[]}getLatex(o,r){let t=()=>w(...this.nodes.map(n=>n.getLatex(o,r)));return o.inclusiveSelectionLeftBorder===this?w(r.selectionHightlightStart,t()):this===o.current?this.nodes.length==0?r.activePlaceholderLatex:w(r.activePlaceholderLatex,t()):this.nodes.length==0?r.passivePlaceholderLatex:t()}};var M=class{constructor(){this.syntaxTreeRoot=new c;this.current=this.syntaxTreeRoot;this.selectionDiff=null;this.inclusiveSelectionRightBorder=null;this.inclusiveSelectionLeftBorder=null}};var ce=new M;function se(e,o){return(e instanceof M?e.syntaxTreeRoot:e).getLatex(ce,o)}function re(e,o){let r=!1;for(let t=e.length-1;t>=0;t--){let n=e[t];if(!r){n===o&&(r=!0);continue}if(n.nodes.length>0)return n}return null}function b(e){return e.length==0?null:e[e.length-1]}function u(e,o){let r=e.indexOf(o);return r>0?e[r-1]:null}function B(e,o){let r=e.indexOf(o);e.splice(r,1)}var h=class{getLatex(o,r){let t=this.getLatexPart(o,r);return o.selectionDiff!=null&&o.selectionDiff!=0?(o.inclusiveSelectionLeftBorder===this&&(t=w(r.selectionHightlightStart,t)),o.inclusiveSelectionRightBorder===this&&(t=w(t,r.selectionHightlightEnd)),t):o.current===this?w(t,r.activePlaceholderLatex):t}};var p=class extends h{constructor(r){super();this.placeholders=r,this.placeholders.forEach(t=>{t.parentNode=this})}getMoveDownSuggestion(r){return null}getMoveUpSuggestion(r){return null}};function g(e){return e[e.length-1]}var D=class extends h{};var x=class extends D{};function Q(e,o,r){for(let t=e-1;t>=0;t--){let n=o[t];if(n instanceof x)B(o,n),r.nodes.unshift(n),n.parentPlaceholder=r;else break}}function C(e){let o=e.parentNode,r=o.parentPlaceholder.nodes.indexOf(o);o.parentPlaceholder.nodes.splice(r,1,...e.nodes);for(let t of e.nodes)t.parentPlaceholder=o.parentPlaceholder}function te(e){var o;if(e.current instanceof c){if(e.current.parentNode==null||e.current.nodes.length>0)return;{let r=re(e.current.parentNode.placeholders,e.current);if(r)e.current.parentNode.placeholders.length==2&&e.current===e.current.parentNode.placeholders[1]&&e.current.nodes.length==0?(C(r),e.current=g(r.nodes)):(r.nodes.pop(),e.current=(o=b(r.nodes))!=null?o:r);else if(e.current.parentNode.placeholders.every(t=>t.nodes.length==0)){let t=e.current.parentNode.parentPlaceholder,n=u(t.nodes,e.current.parentNode);B(t.nodes,e.current.parentNode),e.current=n!=null?n:t}else if(e.current.parentNode.placeholders[0]===e.current&&e.current.nodes.length==0&&e.current.parentNode.placeholders.some(t=>t.nodes.length!=0)){let t=u(e.current.parentNode.parentPlaceholder.nodes,e.current.parentNode);if(t!=null)ae(t,e.current),e.current=g(e.current.nodes);else{let n=e.current.parentNode.placeholders.filter(i=>i.nodes.length!=0);if(n.length==1){let i=n[0].nodes,l=e.current.parentNode.parentPlaceholder,y=l.nodes.indexOf(e.current.parentNode);for(let a of i)a.parentPlaceholder=l;l.nodes.splice(y,1,...i),e.current=g(i)}}}}}else if(e.current instanceof p&&e.current.placeholders[0].nodes.length>0&&e.current.placeholders.slice(1).every(r=>r.nodes.length==0)){let r=e.current.placeholders[0];C(r),e.current=g(r.nodes)}else if(e.current instanceof p&&e.current.placeholders.some(r=>r.nodes.length>0))e.current=g(e.current.placeholders.flatMap(r=>r.nodes)),te(e);else{let r=u(e.current.parentPlaceholder.nodes,e.current);B(e.current.parentPlaceholder.nodes,e.current),e.current=r!=null?r:e.current.parentPlaceholder}}function ae(e,o){B(o.parentNode.parentPlaceholder.nodes,e),o.nodes.push(e);let r=e.parentPlaceholder;e.parentPlaceholder=o,e instanceof x&&Q(r.nodes.length-1,r.nodes,o)}function K(e,o){let r=e.indexOf(o);return r!=-1&&r<e.length-1?e[r+1]:null}function X(e){var o;if(e.current instanceof c)if(e.current.parentNode!=null&&e.current.parentNode.placeholders.every(r=>r.nodes.length==0)){let r=u(e.current.parentNode.parentPlaceholder.nodes,e.current.parentNode);B(e.current.parentNode.parentPlaceholder.nodes,e.current.parentNode),e.current=r!=null?r:e.current.parentNode.parentPlaceholder}else{let r=e.current.nodes;if(r.length>0)oe(e,r[0]);else if(e.current.parentNode!=null){let t=e.current.parentNode,n=t.placeholders;if(n[0]==e.current&&n.length==2){let i=n[1];e.current=(o=u(t.parentPlaceholder.nodes,t))!=null?o:t.parentPlaceholder,C(i)}else for(let i=n.indexOf(e.current)+1;i<n.length;i++)if(n[i].nodes.length>0){e.current=n[i],X(e);return}}}else{let r=K(e.current.parentPlaceholder.nodes,e.current);r!=null&&oe(e,r)}}function oe(e,o){o instanceof p?o.placeholders.length==1&&o.placeholders[0].nodes.length>0?C(o.placeholders[0]):o.placeholders.length==2&&o.placeholders[0].nodes.length==0&&o.placeholders[1].nodes.length>0?C(o.placeholders[1]):(e.current=o.placeholders[0],X(e)):B(o.parentPlaceholder.nodes,o)}function j(e){e.selectionDiff=null,e.inclusiveSelectionRightBorder=null,e.inclusiveSelectionLeftBorder=null}function E(e){var r;if(e.selectionDiff==null)throw"Enter selection mode before calling this method.";if(e.selectionDiff==0)return j(e),[];let o=e.selectionDiff;if(e.current instanceof c)return j(e),e.current.nodes.splice(0,o);{let t=e.current.parentPlaceholder.nodes,n=t.indexOf(e.inclusiveSelectionLeftBorder);return e.current=(r=u(t,e.inclusiveSelectionLeftBorder))!=null?r:e.current.parentPlaceholder,j(e),t.splice(n,de(o))}}function de(e){return e<0?-e:e}function fe(e){E(e)}function S(e){var o;if(e.current instanceof c)if(e.current.nodes.length>0){let r=e.current.nodes[0];e.current=r instanceof p?r.placeholders[0]:r}else{if(e.current.parentNode==null)return;e.current=(o=K(e.current.parentNode.placeholders,e.current))!=null?o:e.current.parentNode}else{let r=K(e.current.parentPlaceholder.nodes,e.current);if(r!=null)e.current=r instanceof p?r.placeholders[0]:r;else{let t=e.current.parentPlaceholder.parentNode;if(t!=null){let n=K(t.placeholders,e.current.parentPlaceholder);e.current=n!=null?n:t}}}}function d(e,o){if(e.current instanceof c)e.current.nodes.unshift(o),o.parentPlaceholder=e.current;else{let r=e.current.parentPlaceholder,t=r.nodes.indexOf(e.current);r.nodes.splice(t+1,0,o),o.parentPlaceholder=r}S(e)}var P=class extends p{constructor(r,t,...n){let i=n.length+1,l=new Array;for(let y=0;y<i;y++)l.push(new c);super(l);this.before=r,this.then=t,this.rest=n}getLatexPart(r,t){let n=this.before+this.placeholders[0].getLatex(r,t)+this.then;for(let i=0;i<this.rest.length;i++)n+=this.placeholders[i+1].getLatex(r,t)+this.rest[i];return n}};var q=class extends P{constructor(o=String.raw`\left(`,r=String.raw`\right)`){super(o,r)}};function A(e,o){for(let r of e)r.parentPlaceholder=o,o.nodes.push(r)}function F(e,o,r){var n;let t=o.placeholders[0];if(e.current instanceof h){let i=e.current.parentPlaceholder.nodes,l=i.indexOf(e.current);i[l]=o,o.parentPlaceholder=e.current.parentPlaceholder,e.current instanceof q&&(r!=null&&r.deleteOuterRoundBracketsIfAny)?(A(e.current.placeholders[0].nodes,t),e.current=(n=K(o.placeholders,t))!=null?n:o):e.current instanceof x?(t.nodes.push(e.current),e.current.parentPlaceholder=t,Q(l,i,t),S(e)):(t.nodes.push(e.current),e.current.parentPlaceholder=t,S(e))}else d(e,o)}function pe(e,o){let r=E(e);if(d(e,o),r.length>0){let t=o.placeholders[0];A(r,t),e.current=g(r),S(e)}}function me(e,o){var n;if(o.placeholders.length<2)throw"Expected 2 placeholders.";let r=E(e),t=o.placeholders[1];A(r,t),F(e,o),e.current=(n=b(r))!=null?n:t}function ue(e){var t;let o=e.current instanceof c?e.current:e.current.parentPlaceholder,r;for(;;){if(o.parentNode==null)return;r=o.parentNode;let n=r.getMoveDownSuggestion(o);if(n!=null){e.current=(t=b(n.nodes))!=null?t:n;return}o=r.parentPlaceholder}}function he(e){var o,r,t;if(e.current instanceof c){if(e.current.parentNode==null)return;let n=u(e.current.parentNode.placeholders,e.current);if(n!==null)e.current=(o=b(n.nodes))!=null?o:n;else{let i=e.current.parentNode.parentPlaceholder,l=u(i.nodes,e.current.parentNode);e.current=l!=null?l:i}}else if(e.current instanceof p){let n=g(e.current.placeholders);e.current=(r=b(n.nodes))!=null?r:n}else e.current=(t=u(e.current.parentPlaceholder.nodes,e.current))!=null?t:e.current.parentPlaceholder}function ge(e){var t;let o=e.current instanceof c?e.current:e.current.parentPlaceholder,r;for(;;){if(o.parentNode==null)return;r=o.parentNode;let n=r.getMoveUpSuggestion(o);if(n!=null){e.current=(t=b(n.nodes))!=null?t:n;return}o=r.parentPlaceholder}}function R(e,o){if(e.selectionDiff=o,o==0)e.inclusiveSelectionLeftBorder=null,e.inclusiveSelectionRightBorder=null;else if(e.current instanceof c)e.inclusiveSelectionLeftBorder=e.current,e.inclusiveSelectionRightBorder=e.current.nodes[o-1];else{let r=e.current.parentPlaceholder.nodes,t=r.indexOf(e.current);if(o>0)e.inclusiveSelectionLeftBorder=r[t+1],e.inclusiveSelectionRightBorder=r[t+o];else{let n=t+o+1;if(n<0)throw"The TreeNode at index 0 of the current Placeholder is as far as you can go left if current is a TreeNode.";e.inclusiveSelectionLeftBorder=r[n],e.inclusiveSelectionRightBorder=e.current}}}function xe(e){R(e,0)}function Pe(e){return e.selectionDiff!=null}function ye(e){var r;let o=(r=e.selectionDiff)!=null?r:0;e.current instanceof h&&e.current.parentPlaceholder.nodes.indexOf(e.current)+o>=0||e.current instanceof c&&o>0?R(e,o-1):e.inclusiveSelectionLeftBorder instanceof h&&e.inclusiveSelectionLeftBorder.parentPlaceholder.nodes.indexOf(e.inclusiveSelectionLeftBorder)==0&&e.inclusiveSelectionLeftBorder.parentPlaceholder.parentNode!=null&&(e.current=e.inclusiveSelectionLeftBorder.parentPlaceholder.parentNode,R(e,-1))}function Ne(e){var r,t;let o=(r=e.selectionDiff)!=null?r:0;if(e.current instanceof c&&o<e.current.nodes.length||e.current instanceof h&&e.current.parentPlaceholder.nodes.indexOf(e.current)+o<e.current.parentPlaceholder.nodes.length-1)R(e,o+1);else if(e.inclusiveSelectionRightBorder instanceof h&&g(e.inclusiveSelectionRightBorder.parentPlaceholder.nodes)==e.inclusiveSelectionRightBorder&&e.inclusiveSelectionRightBorder.parentPlaceholder.parentNode!=null){let n=e.inclusiveSelectionRightBorder.parentPlaceholder.parentNode;e.current=(t=u(n.parentPlaceholder.nodes,n))!=null?t:n.parentPlaceholder,R(e,1)}}var V=class extends P{getMoveDownSuggestion(o){let r=this.placeholders.indexOf(o);return r>0?this.placeholders[r-1]:null}getMoveUpSuggestion(o){let r=this.placeholders.indexOf(o);return r<this.placeholders.length-1?this.placeholders[r+1]:null}};var z=class extends x{constructor(r="."){super();this.latex=typeof r=="string"?()=>r:r}getLatexPart(r,t){return this.latex()}};var _=class extends P{getMoveDownSuggestion(o){let r=this.placeholders.indexOf(o);return r<this.placeholders.length-1?this.placeholders[r+1]:null}getMoveUpSuggestion(o){let r=this.placeholders.indexOf(o);return r>0?this.placeholders[r-1]:null}};var G=class extends x{constructor(r){super();this.latex=r}getLatexPart(r,t){return this.latex}};var T=class extends D{constructor(r){super();this.latex=typeof r=="string"?()=>r:r}getLatexPart(r,t){return this.latex()}};function W(e,o,r){let t=e.slice(-1),n=r.slice(e.length),i=0;for(let l=0;l<n.length;l++){if(n[l]==o){if(i==0)return{content:n.slice(0,l),rest:n.slice(l+1)};i--;continue}let y=["\\"+t,"\\"+o,String.raw`\left`+t,String.raw`\right`+o],a=n.slice(l);for(let m of y)if(a.length>=m.length&&a.startsWith(m)){l+=m.length;continue}n[l]==t&&i++}throw`A closing ${o} is missing.`}var J=class extends p{constructor(r,t,n){let i=[],l=[];for(let y=0;y<n;y++){let a=[];for(let m=0;m<t;m++){let s=new c;a.push(s),l.push(s)}i.push(a)}super(l);this.grid=i,this.matrixType=r,this.width=t}getLatexPart(r,t){let n=String.raw`\begin{${this.matrixType}}`;return n+=this.grid.map(i=>i.map(l=>l.getLatex(r,t)).join(" & ")).join(String.raw` \\ `),n+=String.raw`\end{${this.matrixType}}`,n}getMoveDownSuggestion(r){let{rowIndex:t,columnIndex:n}=this.getPositionOf(r);return t+1<this.grid.length?this.grid[t+1][n]:null}getMoveUpSuggestion(r){let{rowIndex:t,columnIndex:n}=this.getPositionOf(r);return t-1>=0?this.grid[t-1][n]:null}getPositionOf(r){let t=this.placeholders.indexOf(r);if(t==-1)throw"The provided Placeholder is not part of this MatrixNode.";let n=Math.floor(t/this.width),i=t-n*this.width;return{rowIndex:n,columnIndex:i}}};function $(e,o,r){var i;let t=e==null?void 0:e.trim();if(t==null||t=="")return new M;let n=new M;for(;t!="";){if(t[0]==" "){t=t.trimStart();continue}if(t.startsWith(r.decimalSeparator)){d(n,new z(r.decimalSeparator)),t=t.slice(r.decimalSeparator.length);continue}if(["1","2","3","4","5","6","7","8","9","0"].includes(t[0])||(i=r.additionalDigits)!=null&&i.includes(t[0])){d(n,new G(t[0])),t=t.slice(1);continue}let l=!1;if(t.startsWith(String.raw`\begin{`)){let a=W(String.raw`\begin{`,"}",t);if(!a.content.endsWith("matrix")&&!a.content.endsWith("cases"))throw String.raw`Expected a word ending with 'matrix' or 'cases' after '\begin{'.`;let s=a.rest.slice(0,a.rest.indexOf(String.raw`\end{${a.content}}`)).split(String.raw`\\`);d(n,new J(a.content,s[0].split("&").length,s.length));for(let N of s)for(let v of N.split("&")){let I=$(v,o,r).syntaxTreeRoot.nodes;for(let L of I)d(n,L),n.current=L;S(n)}let f=String.raw`\end{${a.content}}`;t=t.slice(t.indexOf(f)+f.length);continue}if(t.startsWith("\\")){for(let s of["\\left\\","\\right\\",String.raw`\left`,String.raw`\right`])if(t.startsWith(s)){d(n,new T(s+t[s.length])),t=t.slice(s.length+1),l=!0;break}if(l)continue;for(let s of r.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets){let f=s.slice(0,-3),N=s.slice(-3,-2),v=s.slice(-2,-1),I=s.slice(-1);if(t.startsWith(f)){let L=W(f,N,t);if(L.rest[0]!=v)continue;let U=new _(f,N+v,I);d(n,U);let ne=$(L.content,o,r).syntaxTreeRoot.nodes;for(let H of ne)d(n,H),n.current=H;S(n);let k=W(v,I,L.rest),ie=$(k.content,o,r).syntaxTreeRoot.nodes;for(let H of ie)d(n,H),n.current=H;n.current=U,t=k.rest,l=!0;break}}if(l)continue;let a=String.raw`\text{`;if(t.startsWith(a)){let s=W(a,"}",t),f=new P(a,"}");d(n,f);for(let N of s.content)d(n,new T(N));n.current=f,t=s.rest;continue}let m="\\";if(O(t[1])){for(let s=1;s<t.length;s++){let f=t[s];if(O(f))m+=f;else if(f=="{"){m+=f;let N=m,v=W(N,"}",t),I=$(v.content,o,r).syntaxTreeRoot.nodes,L=new P(N,"}");d(n,L);for(let U of I)d(n,U),n.current=U;n.current=L,t=v.rest,l=!0;break}else break}if(l)continue;d(n,new T(m)),t=t.slice(m.length)}else d(n,new T("\\"+t[1])),t=t.slice(2);continue}let y=[["^{",()=>new V("","^{","}")],["_{",()=>new _("","_{","}")]];for(let a of y){let m=a[0];if(t.startsWith(m)){let s=a[1]();F(n,s);let f=W(m,"}",t),N=$(f.content,o,r).syntaxTreeRoot.nodes;for(let v of N)d(n,v),n.current=v;n.current=s,t=f.rest,l=!0;break}}l!=!0&&(d(n,new T(t[0])),t=t.slice(1))}return n}var Y=class{constructor(){this.additionalDigits=null;this.decimalSeparator=".";this.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets=[]}};var Z=class{constructor(){this.activePlaceholderShape=String.raw`\blacksquare`;this.passivePlaceholderShape=String.raw`\square`;this.selectionHightlightStart=String.raw`\colorbox{#ADD8E6}{\(\displaystyle`;this.selectionHightlightEnd=String.raw`\)}`}get activePlaceholderLatex(){return this.activePlaceholderColor==null?this.activePlaceholderShape:String.raw`{\color{${this.activePlaceholderColor}}${this.activePlaceholderShape}}`}get passivePlaceholderLatex(){return this.passivePlaceholderColor==null?this.passivePlaceholderShape:String.raw`{\color{${this.passivePlaceholderColor}}${this.passivePlaceholderShape}}`}};export{V as AscendingBranchingNode,p as BranchingNode,z as DecimalSeparatorNode,_ as DescendingBranchingNode,G as DigitNode,M as KeyboardMemory,Z as LatexConfiguration,Y as LatexParserConfiguration,D as LeafNode,J as MatrixNode,c as Placeholder,q as RoundBracketsNode,P as StandardBranchingNode,T as StandardLeafNode,h as TreeNode,te as deleteLeft,X as deleteRight,fe as deleteSelection,xe as enterSelectionMode,le as getEditModeLatex,se as getViewModeLatex,Pe as inSelectionMode,d as insert,F as insertWithEncapsulateCurrent,pe as insertWithEncapsulateSelection,me as insertWithEncapsulateSelectionAndPrevious,j as leaveSelectionMode,ue as moveDown,he as moveLeft,S as moveRight,ge as moveUp,$ as parseLatex,ye as selectLeft,Ne as selectRight};

@@ -607,2 +607,22 @@ // src/GetLatex/getEditModeLatex.ts

// src/SyntaxTreeComponents/Nodes/BranchingNodes/AscendingBranchingNode.ts
var AscendingBranchingNode = class extends StandardBranchingNode {
getMoveDownSuggestion(fromPlaceholder) {
const currentPlaceholderIndex = this.placeholders.indexOf(fromPlaceholder);
if (currentPlaceholderIndex > 0) {
return this.placeholders[currentPlaceholderIndex - 1];
} else {
return null;
}
}
getMoveUpSuggestion(fromPlaceholder) {
const currentPlaceholderIndex = this.placeholders.indexOf(fromPlaceholder);
if (currentPlaceholderIndex < this.placeholders.length - 1) {
return this.placeholders[currentPlaceholderIndex + 1];
} else {
return null;
}
}
};
// src/SyntaxTreeComponents/Nodes/LeafNodes/DecimalSeparatorNode.ts

@@ -619,2 +639,22 @@ var DecimalSeparatorNode = class extends PartOfNumberWithDigits {

// src/SyntaxTreeComponents/Nodes/BranchingNodes/DescendingBranchingNode.ts
var DescendingBranchingNode = class extends StandardBranchingNode {
getMoveDownSuggestion(fromPlaceholder) {
const currentPlaceholderIndex = this.placeholders.indexOf(fromPlaceholder);
if (currentPlaceholderIndex < this.placeholders.length - 1) {
return this.placeholders[currentPlaceholderIndex + 1];
} else {
return null;
}
}
getMoveUpSuggestion(fromPlaceholder) {
const currentPlaceholderIndex = this.placeholders.indexOf(fromPlaceholder);
if (currentPlaceholderIndex > 0) {
return this.placeholders[currentPlaceholderIndex - 1];
} else {
return null;
}
}
};
// src/SyntaxTreeComponents/Nodes/LeafNodes/DigitNode.ts

@@ -642,2 +682,31 @@ var DigitNode = class extends PartOfNumberWithDigits {

// src/LatexParser/helpers/getBracketPairContent.ts
function getBracketPairContent(opening, closingBracket, sWithOpening) {
const openingBracket = opening.slice(-1);
const s = sWithOpening.slice(opening.length);
let level = 0;
for (let closingBracketIndex = 0; closingBracketIndex < s.length; closingBracketIndex++) {
if (s[closingBracketIndex] == closingBracket) {
if (level == 0) {
return { content: s.slice(0, closingBracketIndex), rest: s.slice(closingBracketIndex + 1) };
} else {
level--;
continue;
}
}
const toIgnores = ["\\" + openingBracket, "\\" + closingBracket, String.raw`\left` + openingBracket, String.raw`\right` + closingBracket];
const currentPosition = s.slice(closingBracketIndex);
for (const toIgnore of toIgnores) {
if (currentPosition.length >= toIgnore.length && currentPosition.startsWith(toIgnore)) {
closingBracketIndex += toIgnore.length;
continue;
}
}
if (s[closingBracketIndex] == openingBracket) {
level++;
}
}
throw `A closing ${closingBracket} is missing.`;
}
// src/SyntaxTreeComponents/Nodes/BranchingNodes/MatrixNode.ts

@@ -695,40 +764,178 @@ var MatrixNode = class extends BranchingNode {

// src/SyntaxTreeComponents/Nodes/BranchingNodes/AscendingBranchingNode.ts
var AscendingBranchingNode = class extends StandardBranchingNode {
getMoveDownSuggestion(fromPlaceholder) {
const currentPlaceholderIndex = this.placeholders.indexOf(fromPlaceholder);
if (currentPlaceholderIndex > 0) {
return this.placeholders[currentPlaceholderIndex - 1];
} else {
return null;
}
// src/LatexParser/parseLatex.ts
function parseLatex(latex, latexConfiguration, latexParserConfiguration) {
let x = latex?.trim();
if (x == null || x == "") {
return new KeyboardMemory();
}
getMoveUpSuggestion(fromPlaceholder) {
const currentPlaceholderIndex = this.placeholders.indexOf(fromPlaceholder);
if (currentPlaceholderIndex < this.placeholders.length - 1) {
return this.placeholders[currentPlaceholderIndex + 1];
} else {
return null;
const k = new KeyboardMemory();
while (x != "") {
if (x[0] == " ") {
x = x.trimStart();
continue;
}
if (x.startsWith(latexParserConfiguration.decimalSeparator)) {
insert(k, new DecimalSeparatorNode(latexParserConfiguration.decimalSeparator));
x = x.slice(latexParserConfiguration.decimalSeparator.length);
continue;
}
if (["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"].includes(x[0]) || latexParserConfiguration.additionalDigits?.includes(x[0])) {
insert(k, new DigitNode(x[0]));
x = x.slice(1);
continue;
}
let handled = false;
if (x.startsWith(String.raw`\begin{`)) {
const matrixTypeAndRest = getBracketPairContent(String.raw`\begin{`, "}", x);
if (!matrixTypeAndRest.content.endsWith("matrix") && !matrixTypeAndRest.content.endsWith("cases")) {
throw String.raw`Expected a word ending with 'matrix' or 'cases' after '\begin{'.`;
}
const matrixContent = matrixTypeAndRest.rest.slice(0, matrixTypeAndRest.rest.indexOf(String.raw`\end{${matrixTypeAndRest.content}}`));
const lines = matrixContent.split(String.raw`\\`);
insert(k, new MatrixNode(matrixTypeAndRest.content, lines[0].split("&").length, lines.length));
for (const line of lines) {
for (const latex2 of line.split("&")) {
const nodes = parseLatex(latex2, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
for (const node of nodes) {
insert(k, node);
k.current = node;
}
moveRight(k);
}
}
const matrixEnd = String.raw`\end{${matrixTypeAndRest.content}}`;
x = x.slice(x.indexOf(matrixEnd) + matrixEnd.length);
continue;
}
if (x.startsWith("\\")) {
for (const prefix of ["\\left\\", "\\right\\", String.raw`\left`, String.raw`\right`]) {
if (x.startsWith(prefix)) {
insert(k, new StandardLeafNode(prefix + x[prefix.length]));
x = x.slice(prefix.length + 1);
handled = true;
break;
}
}
if (handled) {
continue;
}
for (const commandWithBrackets of latexParserConfiguration.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets) {
const opening = commandWithBrackets.slice(0, -3);
const closingBracket1 = commandWithBrackets.slice(-3, -2);
const openingBracket2 = commandWithBrackets.slice(-2, -1);
const closingBracket2 = commandWithBrackets.slice(-1);
if (x.startsWith(opening)) {
const numeratorAndRest = getBracketPairContent(opening, closingBracket1, x);
if (numeratorAndRest.rest[0] != openingBracket2) {
continue;
}
const node = new DescendingBranchingNode(opening, closingBracket1 + openingBracket2, closingBracket2);
insert(k, node);
const numerator = parseLatex(numeratorAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
for (const node2 of numerator) {
insert(k, node2);
k.current = node2;
}
moveRight(k);
const denominatorAndRest = getBracketPairContent(openingBracket2, closingBracket2, numeratorAndRest.rest);
const denominator = parseLatex(denominatorAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
for (const node2 of denominator) {
insert(k, node2);
k.current = node2;
}
k.current = node;
x = denominatorAndRest.rest;
handled = true;
break;
}
}
if (handled) {
continue;
}
const textOpening = String.raw`\text{`;
if (x.startsWith(textOpening)) {
const bracketPairContentAndRest = getBracketPairContent(textOpening, "}", x);
const textNode = new StandardBranchingNode(textOpening, "}");
insert(k, textNode);
for (const character of bracketPairContentAndRest.content) {
insert(k, new StandardLeafNode(character));
}
k.current = textNode;
x = bracketPairContentAndRest.rest;
continue;
}
let command = "\\";
if (isLetter(x[1])) {
for (let i = 1; i < x.length; i++) {
const character = x[i];
if (isLetter(character)) {
command += character;
} else if (character == "{") {
command += character;
const opening = command;
const bracketPairContentAndRest = getBracketPairContent(opening, "}", x);
const placeholderContent = parseLatex(bracketPairContentAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
const branchingNode = new StandardBranchingNode(opening, "}");
insert(k, branchingNode);
for (const node of placeholderContent) {
insert(k, node);
k.current = node;
}
k.current = branchingNode;
x = bracketPairContentAndRest.rest;
handled = true;
break;
} else {
break;
}
}
if (handled) {
continue;
}
insert(k, new StandardLeafNode(command));
x = x.slice(command.length);
} else {
insert(k, new StandardLeafNode("\\" + x[1]));
x = x.slice(2);
}
continue;
}
const various = [
["^{", () => new AscendingBranchingNode("", "^{", "}")],
["_{", () => new DescendingBranchingNode("", "_{", "}")]
];
for (const opening_getTreeNode of various) {
const opening = opening_getTreeNode[0];
if (x.startsWith(opening)) {
const node = opening_getTreeNode[1]();
insertWithEncapsulateCurrent(k, node);
const bracketPairContentAndRest = getBracketPairContent(opening, "}", x);
const secondPlaceholderNodes = parseLatex(bracketPairContentAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
for (const node2 of secondPlaceholderNodes) {
insert(k, node2);
k.current = node2;
}
k.current = node;
x = bracketPairContentAndRest.rest;
handled = true;
break;
}
}
if (handled == true) {
continue;
}
insert(k, new StandardLeafNode(x[0]));
x = x.slice(1);
continue;
}
};
return k;
}
// src/SyntaxTreeComponents/Nodes/BranchingNodes/DescendingBranchingNode.ts
var DescendingBranchingNode = class extends StandardBranchingNode {
getMoveDownSuggestion(fromPlaceholder) {
const currentPlaceholderIndex = this.placeholders.indexOf(fromPlaceholder);
if (currentPlaceholderIndex < this.placeholders.length - 1) {
return this.placeholders[currentPlaceholderIndex + 1];
} else {
return null;
}
// src/LatexParser/LatexParserConfiguration.ts
var LatexParserConfiguration = class {
constructor() {
this.additionalDigits = null;
this.decimalSeparator = ".";
this.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets = [];
}
getMoveUpSuggestion(fromPlaceholder) {
const currentPlaceholderIndex = this.placeholders.indexOf(fromPlaceholder);
if (currentPlaceholderIndex > 0) {
return this.placeholders[currentPlaceholderIndex - 1];
} else {
return null;
}
}
};

@@ -767,2 +974,3 @@

LatexConfiguration,
LatexParserConfiguration,
LeafNode,

@@ -791,4 +999,5 @@ MatrixNode,

moveUp,
parseLatex,
selectLeft,
selectRight
};

@@ -1,1 +0,1 @@

function G(e,r){return e.syntaxTreeRoot.getLatex(e,r)}function B(e){return e.toLowerCase()!=e.toUpperCase()}function q(e){if(e.length==0)return!1;if(B(e[e.length-1]))for(let r=e.length-2;r>=0;r--){let o=e[r];if(!B(o))return o=="\\"}return!1}function g(...e){let r="";for(let o=0;o<e.length;o++){let t=e[o];q(r)&&B(t[0])&&(r+=" "),r+=t}return r}var l=class{constructor(){this.parentNode=null;this.nodes=[]}getLatex(r,o){let t=()=>g(...this.nodes.map(n=>n.getLatex(r,o)));return r.inclusiveSelectionLeftBorder===this?g(o.selectionHightlightStart,t()):this===r.current?this.nodes.length==0?o.activePlaceholderLatex:g(o.activePlaceholderLatex,t()):this.nodes.length==0?o.passivePlaceholderLatex:t()}};var L=class{constructor(){this.syntaxTreeRoot=new l;this.current=this.syntaxTreeRoot;this.selectionDiff=null;this.inclusiveSelectionRightBorder=null;this.inclusiveSelectionLeftBorder=null}};var J=new L;function Q(e,r){return(e instanceof L?e.syntaxTreeRoot:e).getLatex(J,r)}function F(e,r){let o=!1;for(let t=e.length-1;t>=0;t--){let n=e[t];if(!o){n===r&&(o=!0);continue}if(n.nodes.length>0)return n}return null}function f(e){return e.length==0?null:e[e.length-1]}function a(e,r){let o=e.indexOf(r);return o>0?e[o-1]:null}function m(e,r){let o=e.indexOf(r);e.splice(o,1)}var s=class{getLatex(r,o){let t=this.getLatexPart(r,o);return r.selectionDiff!=null&&r.selectionDiff!=0?(r.inclusiveSelectionLeftBorder===this&&(t=g(o.selectionHightlightStart,t)),r.inclusiveSelectionRightBorder===this&&(t=g(t,o.selectionHightlightEnd)),t):r.current===this?g(t,o.activePlaceholderLatex):t}};var c=class extends s{constructor(o){super();this.placeholders=o,this.placeholders.forEach(t=>{t.parentNode=this})}getMoveDownSuggestion(o){return null}getMoveUpSuggestion(o){return null}};function d(e){return e[e.length-1]}var v=class extends s{};var p=class extends v{};function C(e,r,o){for(let t=e-1;t>=0;t--){let n=r[t];if(n instanceof p)m(r,n),o.nodes.unshift(n),n.parentPlaceholder=o;else break}}function b(e){let r=e.parentNode,o=r.parentPlaceholder.nodes.indexOf(r);r.parentPlaceholder.nodes.splice(o,1,...e.nodes);for(let t of e.nodes)t.parentPlaceholder=r.parentPlaceholder}function V(e){if(e.current instanceof l){if(e.current.parentNode==null||e.current.nodes.length>0)return;{let r=F(e.current.parentNode.placeholders,e.current);if(r)e.current.parentNode.placeholders.length==2&&e.current===e.current.parentNode.placeholders[1]&&e.current.nodes.length==0?(b(r),e.current=d(r.nodes)):(r.nodes.pop(),e.current=f(r.nodes)??r);else if(e.current.parentNode.placeholders.every(o=>o.nodes.length==0)){let o=e.current.parentNode.parentPlaceholder,t=a(o.nodes,e.current.parentNode);m(o.nodes,e.current.parentNode),e.current=t??o}else if(e.current.parentNode.placeholders[0]===e.current&&e.current.nodes.length==0&&e.current.parentNode.placeholders.some(o=>o.nodes.length!=0)){let o=a(e.current.parentNode.parentPlaceholder.nodes,e.current.parentNode);if(o!=null)X(o,e.current),e.current=d(e.current.nodes);else{let t=e.current.parentNode.placeholders.filter(n=>n.nodes.length!=0);if(t.length==1){let n=t[0].nodes,i=e.current.parentNode.parentPlaceholder,u=i.nodes.indexOf(e.current.parentNode);for(let N of n)N.parentPlaceholder=i;i.nodes.splice(u,1,...n),e.current=d(n)}}}}}else if(e.current instanceof c&&e.current.placeholders[0].nodes.length>0&&e.current.placeholders.slice(1).every(r=>r.nodes.length==0)){let r=e.current.placeholders[0];b(r),e.current=d(r.nodes)}else if(e.current instanceof c&&e.current.placeholders.some(r=>r.nodes.length>0))e.current=d(e.current.placeholders.flatMap(r=>r.nodes)),V(e);else{let r=a(e.current.parentPlaceholder.nodes,e.current);m(e.current.parentPlaceholder.nodes,e.current),e.current=r??e.current.parentPlaceholder}}function X(e,r){m(r.parentNode.parentPlaceholder.nodes,e),r.nodes.push(e);let o=e.parentPlaceholder;e.parentPlaceholder=r,e instanceof p&&C(o.nodes.length-1,o.nodes,r)}function x(e,r){let o=e.indexOf(r);return o!=-1&&o<e.length-1?e[o+1]:null}function D(e){if(e.current instanceof l)if(e.current.parentNode!=null&&e.current.parentNode.placeholders.every(r=>r.nodes.length==0)){let r=a(e.current.parentNode.parentPlaceholder.nodes,e.current.parentNode);m(e.current.parentNode.parentPlaceholder.nodes,e.current.parentNode),e.current=r??e.current.parentNode.parentPlaceholder}else{let r=e.current.nodes;if(r.length>0)z(e,r[0]);else if(e.current.parentNode!=null){let o=e.current.parentNode,t=o.placeholders;if(t[0]==e.current&&t.length==2){let n=t[1];e.current=a(o.parentPlaceholder.nodes,o)??o.parentPlaceholder,b(n)}else for(let n=t.indexOf(e.current)+1;n<t.length;n++)if(t[n].nodes.length>0){e.current=t[n],D(e);return}}}else{let r=x(e.current.parentPlaceholder.nodes,e.current);r!=null&&z(e,r)}}function z(e,r){r instanceof c?r.placeholders.length==1&&r.placeholders[0].nodes.length>0?b(r.placeholders[0]):r.placeholders.length==2&&r.placeholders[0].nodes.length==0&&r.placeholders[1].nodes.length>0?b(r.placeholders[1]):(e.current=r.placeholders[0],D(e)):m(r.parentPlaceholder.nodes,r)}function O(e){e.selectionDiff=null,e.inclusiveSelectionRightBorder=null,e.inclusiveSelectionLeftBorder=null}function S(e){if(e.selectionDiff==null)throw"Enter selection mode before calling this method.";if(e.selectionDiff==0)return O(e),[];let r=e.selectionDiff;if(e.current instanceof l)return O(e),e.current.nodes.splice(0,r);{let o=e.current.parentPlaceholder.nodes,t=o.indexOf(e.inclusiveSelectionLeftBorder);return e.current=a(o,e.inclusiveSelectionLeftBorder)??e.current.parentPlaceholder,O(e),o.splice(t,Y(r))}}function Y(e){return e<0?-e:e}function Z(e){S(e)}function P(e){if(e.current instanceof l)if(e.current.nodes.length>0){let r=e.current.nodes[0];e.current=r instanceof c?r.placeholders[0]:r}else{if(e.current.parentNode==null)return;e.current=x(e.current.parentNode.placeholders,e.current)??e.current.parentNode}else{let r=x(e.current.parentPlaceholder.nodes,e.current);if(r!=null)e.current=r instanceof c?r.placeholders[0]:r;else{let o=e.current.parentPlaceholder.parentNode;if(o!=null){let t=x(o.placeholders,e.current.parentPlaceholder);e.current=t??o}}}}function T(e,r){if(e.current instanceof l)e.current.nodes.unshift(r),r.parentPlaceholder=e.current;else{let o=e.current.parentPlaceholder,t=o.nodes.indexOf(e.current);o.nodes.splice(t+1,0,r),r.parentPlaceholder=o}P(e)}var h=class extends c{constructor(o,t,...n){let i=n.length+1,u=new Array;for(let N=0;N<i;N++)u.push(new l);super(u);this.before=o,this.then=t,this.rest=n}getLatexPart(o,t){let n=this.before+this.placeholders[0].getLatex(o,t)+this.then;for(let i=0;i<this.rest.length;i++)n+=this.placeholders[i+1].getLatex(o,t)+this.rest[i];return n}};var K=class extends h{constructor(r=String.raw`\left(`,o=String.raw`\right)`){super(r,o)}};function M(e,r){for(let o of e)o.parentPlaceholder=r,r.nodes.push(o)}function w(e,r,o){let t=r.placeholders[0];if(e.current instanceof s){let n=e.current.parentPlaceholder.nodes,i=n.indexOf(e.current);n[i]=r,r.parentPlaceholder=e.current.parentPlaceholder,e.current instanceof K&&o?.deleteOuterRoundBracketsIfAny?(M(e.current.placeholders[0].nodes,t),e.current=x(r.placeholders,t)??r):e.current instanceof p?(t.nodes.push(e.current),e.current.parentPlaceholder=t,C(i,n,t),P(e)):(t.nodes.push(e.current),e.current.parentPlaceholder=t,P(e))}else T(e,r)}function k(e,r){let o=S(e);if(T(e,r),o.length>0){let t=r.placeholders[0];M(o,t),e.current=d(o),P(e)}}function ee(e,r){if(r.placeholders.length<2)throw"Expected 2 placeholders.";let o=S(e),t=r.placeholders[1];M(o,t),w(e,r),e.current=f(o)??t}function re(e){let r=e.current instanceof l?e.current:e.current.parentPlaceholder,o;for(;;){if(r.parentNode==null)return;o=r.parentNode;let t=o.getMoveDownSuggestion(r);if(t!=null){e.current=f(t.nodes)??t;return}r=o.parentPlaceholder}}function oe(e){if(e.current instanceof l){if(e.current.parentNode==null)return;let r=a(e.current.parentNode.placeholders,e.current);if(r!==null)e.current=f(r.nodes)??r;else{let o=e.current.parentNode.parentPlaceholder,t=a(o.nodes,e.current.parentNode);e.current=t??o}}else if(e.current instanceof c){let r=d(e.current.placeholders);e.current=f(r.nodes)??r}else e.current=a(e.current.parentPlaceholder.nodes,e.current)??e.current.parentPlaceholder}function te(e){let r=e.current instanceof l?e.current:e.current.parentPlaceholder,o;for(;;){if(r.parentNode==null)return;o=r.parentNode;let t=o.getMoveUpSuggestion(r);if(t!=null){e.current=f(t.nodes)??t;return}r=o.parentPlaceholder}}function y(e,r){if(e.selectionDiff=r,r==0)e.inclusiveSelectionLeftBorder=null,e.inclusiveSelectionRightBorder=null;else if(e.current instanceof l)e.inclusiveSelectionLeftBorder=e.current,e.inclusiveSelectionRightBorder=e.current.nodes[r-1];else{let o=e.current.parentPlaceholder.nodes,t=o.indexOf(e.current);if(r>0)e.inclusiveSelectionLeftBorder=o[t+1],e.inclusiveSelectionRightBorder=o[t+r];else{let n=t+r+1;if(n<0)throw"The TreeNode at index 0 of the current Placeholder is as far as you can go left if current is a TreeNode.";e.inclusiveSelectionLeftBorder=o[n],e.inclusiveSelectionRightBorder=e.current}}}function ne(e){y(e,0)}function le(e){return e.selectionDiff!=null}function ie(e){let r=e.selectionDiff??0;e.current instanceof s&&e.current.parentPlaceholder.nodes.indexOf(e.current)+r>=0||e.current instanceof l&&r>0?y(e,r-1):e.inclusiveSelectionLeftBorder instanceof s&&e.inclusiveSelectionLeftBorder.parentPlaceholder.nodes.indexOf(e.inclusiveSelectionLeftBorder)==0&&e.inclusiveSelectionLeftBorder.parentPlaceholder.parentNode!=null&&(e.current=e.inclusiveSelectionLeftBorder.parentPlaceholder.parentNode,y(e,-1))}function ce(e){let r=e.selectionDiff??0;if(e.current instanceof l&&r<e.current.nodes.length||e.current instanceof s&&e.current.parentPlaceholder.nodes.indexOf(e.current)+r<e.current.parentPlaceholder.nodes.length-1)y(e,r+1);else if(e.inclusiveSelectionRightBorder instanceof s&&d(e.inclusiveSelectionRightBorder.parentPlaceholder.nodes)==e.inclusiveSelectionRightBorder&&e.inclusiveSelectionRightBorder.parentPlaceholder.parentNode!=null){let o=e.inclusiveSelectionRightBorder.parentPlaceholder.parentNode;e.current=a(o.parentPlaceholder.nodes,o)??o.parentPlaceholder,y(e,1)}}var R=class extends p{constructor(o="."){super();this.latex=typeof o=="string"?()=>o:o}getLatexPart(o,t){return this.latex()}};var I=class extends p{constructor(o){super();this.latex=o}getLatexPart(o,t){return this.latex}};var E=class extends v{constructor(o){super();this.latex=typeof o=="string"?()=>o:o}getLatexPart(o,t){return this.latex()}};var W=class extends c{constructor(o,t,n){let i=[],u=[];for(let N=0;N<n;N++){let $=[];for(let H=0;H<t;H++){let j=new l;$.push(j),u.push(j)}i.push($)}super(u);this.grid=i,this.matrixType=o,this.width=t}getLatexPart(o,t){let n=String.raw`\begin{${this.matrixType}}`;return n+=this.grid.map(i=>i.map(u=>u.getLatex(o,t)).join(" & ")).join(String.raw` \\ `),n+=String.raw`\end{${this.matrixType}}`,n}getMoveDownSuggestion(o){let{rowIndex:t,columnIndex:n}=this.getPositionOf(o);return t+1<this.grid.length?this.grid[t+1][n]:null}getMoveUpSuggestion(o){let{rowIndex:t,columnIndex:n}=this.getPositionOf(o);return t-1>=0?this.grid[t-1][n]:null}getPositionOf(o){let t=this.placeholders.indexOf(o);if(t==-1)throw"The provided Placeholder is not part of this MatrixNode.";let n=Math.floor(t/this.width),i=t-n*this.width;return{rowIndex:n,columnIndex:i}}};var A=class extends h{getMoveDownSuggestion(r){let o=this.placeholders.indexOf(r);return o>0?this.placeholders[o-1]:null}getMoveUpSuggestion(r){let o=this.placeholders.indexOf(r);return o<this.placeholders.length-1?this.placeholders[o+1]:null}};var U=class extends h{getMoveDownSuggestion(r){let o=this.placeholders.indexOf(r);return o<this.placeholders.length-1?this.placeholders[o+1]:null}getMoveUpSuggestion(r){let o=this.placeholders.indexOf(r);return o>0?this.placeholders[o-1]:null}};var _=class{constructor(){this.activePlaceholderShape=String.raw`\blacksquare`;this.passivePlaceholderShape=String.raw`\square`;this.selectionHightlightStart=String.raw`\colorbox{#ADD8E6}{\(\displaystyle`;this.selectionHightlightEnd=String.raw`\)}`}get activePlaceholderLatex(){return this.activePlaceholderColor==null?this.activePlaceholderShape:String.raw`{\color{${this.activePlaceholderColor}}${this.activePlaceholderShape}}`}get passivePlaceholderLatex(){return this.passivePlaceholderColor==null?this.passivePlaceholderShape:String.raw`{\color{${this.passivePlaceholderColor}}${this.passivePlaceholderShape}}`}};export{A as AscendingBranchingNode,c as BranchingNode,R as DecimalSeparatorNode,U as DescendingBranchingNode,I as DigitNode,L as KeyboardMemory,_ as LatexConfiguration,v as LeafNode,W as MatrixNode,l as Placeholder,K as RoundBracketsNode,h as StandardBranchingNode,E as StandardLeafNode,s as TreeNode,V as deleteLeft,D as deleteRight,Z as deleteSelection,ne as enterSelectionMode,G as getEditModeLatex,Q as getViewModeLatex,le as inSelectionMode,T as insert,w as insertWithEncapsulateCurrent,k as insertWithEncapsulateSelection,ee as insertWithEncapsulateSelectionAndPrevious,O as leaveSelectionMode,re as moveDown,oe as moveLeft,P as moveRight,te as moveUp,ie as selectLeft,ce as selectRight};
function ie(e,r){return e.syntaxTreeRoot.getLatex(e,r)}function T(e){return e.toLowerCase()!=e.toUpperCase()}function k(e){if(e.length==0)return!1;if(T(e[e.length-1]))for(let r=e.length-2;r>=0;r--){let t=e[r];if(!T(t))return t=="\\"}return!1}function O(...e){let r="";for(let t=0;t<e.length;t++){let o=e[t];k(r)&&T(o[0])&&(r+=" "),r+=o}return r}var l=class{constructor(){this.parentNode=null;this.nodes=[]}getLatex(r,t){let o=()=>O(...this.nodes.map(n=>n.getLatex(r,t)));return r.inclusiveSelectionLeftBorder===this?O(t.selectionHightlightStart,o()):this===r.current?this.nodes.length==0?t.activePlaceholderLatex:O(t.activePlaceholderLatex,o()):this.nodes.length==0?t.passivePlaceholderLatex:o()}};var L=class{constructor(){this.syntaxTreeRoot=new l;this.current=this.syntaxTreeRoot;this.selectionDiff=null;this.inclusiveSelectionRightBorder=null;this.inclusiveSelectionLeftBorder=null}};var le=new L;function ce(e,r){return(e instanceof L?e.syntaxTreeRoot:e).getLatex(le,r)}function ee(e,r){let t=!1;for(let o=e.length-1;o>=0;o--){let n=e[o];if(!t){n===r&&(t=!0);continue}if(n.nodes.length>0)return n}return null}function v(e){return e.length==0?null:e[e.length-1]}function u(e,r){let t=e.indexOf(r);return t>0?e[t-1]:null}function M(e,r){let t=e.indexOf(r);e.splice(t,1)}var h=class{getLatex(r,t){let o=this.getLatexPart(r,t);return r.selectionDiff!=null&&r.selectionDiff!=0?(r.inclusiveSelectionLeftBorder===this&&(o=O(t.selectionHightlightStart,o)),r.inclusiveSelectionRightBorder===this&&(o=O(o,t.selectionHightlightEnd)),o):r.current===this?O(o,t.activePlaceholderLatex):o}};var p=class extends h{constructor(t){super();this.placeholders=t,this.placeholders.forEach(o=>{o.parentNode=this})}getMoveDownSuggestion(t){return null}getMoveUpSuggestion(t){return null}};function g(e){return e[e.length-1]}var R=class extends h{};var x=class extends R{};function J(e,r,t){for(let o=e-1;o>=0;o--){let n=r[o];if(n instanceof x)M(r,n),t.nodes.unshift(n),n.parentPlaceholder=t;else break}}function D(e){let r=e.parentNode,t=r.parentPlaceholder.nodes.indexOf(r);r.parentPlaceholder.nodes.splice(t,1,...e.nodes);for(let o of e.nodes)o.parentPlaceholder=r.parentPlaceholder}function re(e){if(e.current instanceof l){if(e.current.parentNode==null||e.current.nodes.length>0)return;{let r=ee(e.current.parentNode.placeholders,e.current);if(r)e.current.parentNode.placeholders.length==2&&e.current===e.current.parentNode.placeholders[1]&&e.current.nodes.length==0?(D(r),e.current=g(r.nodes)):(r.nodes.pop(),e.current=v(r.nodes)??r);else if(e.current.parentNode.placeholders.every(t=>t.nodes.length==0)){let t=e.current.parentNode.parentPlaceholder,o=u(t.nodes,e.current.parentNode);M(t.nodes,e.current.parentNode),e.current=o??t}else if(e.current.parentNode.placeholders[0]===e.current&&e.current.nodes.length==0&&e.current.parentNode.placeholders.some(t=>t.nodes.length!=0)){let t=u(e.current.parentNode.parentPlaceholder.nodes,e.current.parentNode);if(t!=null)se(t,e.current),e.current=g(e.current.nodes);else{let o=e.current.parentNode.placeholders.filter(n=>n.nodes.length!=0);if(o.length==1){let n=o[0].nodes,i=e.current.parentNode.parentPlaceholder,d=i.nodes.indexOf(e.current.parentNode);for(let s of n)s.parentPlaceholder=i;i.nodes.splice(d,1,...n),e.current=g(n)}}}}}else if(e.current instanceof p&&e.current.placeholders[0].nodes.length>0&&e.current.placeholders.slice(1).every(r=>r.nodes.length==0)){let r=e.current.placeholders[0];D(r),e.current=g(r.nodes)}else if(e.current instanceof p&&e.current.placeholders.some(r=>r.nodes.length>0))e.current=g(e.current.placeholders.flatMap(r=>r.nodes)),re(e);else{let r=u(e.current.parentPlaceholder.nodes,e.current);M(e.current.parentPlaceholder.nodes,e.current),e.current=r??e.current.parentPlaceholder}}function se(e,r){M(r.parentNode.parentPlaceholder.nodes,e),r.nodes.push(e);let t=e.parentPlaceholder;e.parentPlaceholder=r,e instanceof x&&J(t.nodes.length-1,t.nodes,r)}function w(e,r){let t=e.indexOf(r);return t!=-1&&t<e.length-1?e[t+1]:null}function Q(e){if(e.current instanceof l)if(e.current.parentNode!=null&&e.current.parentNode.placeholders.every(r=>r.nodes.length==0)){let r=u(e.current.parentNode.parentPlaceholder.nodes,e.current.parentNode);M(e.current.parentNode.parentPlaceholder.nodes,e.current.parentNode),e.current=r??e.current.parentNode.parentPlaceholder}else{let r=e.current.nodes;if(r.length>0)te(e,r[0]);else if(e.current.parentNode!=null){let t=e.current.parentNode,o=t.placeholders;if(o[0]==e.current&&o.length==2){let n=o[1];e.current=u(t.parentPlaceholder.nodes,t)??t.parentPlaceholder,D(n)}else for(let n=o.indexOf(e.current)+1;n<o.length;n++)if(o[n].nodes.length>0){e.current=o[n],Q(e);return}}}else{let r=w(e.current.parentPlaceholder.nodes,e.current);r!=null&&te(e,r)}}function te(e,r){r instanceof p?r.placeholders.length==1&&r.placeholders[0].nodes.length>0?D(r.placeholders[0]):r.placeholders.length==2&&r.placeholders[0].nodes.length==0&&r.placeholders[1].nodes.length>0?D(r.placeholders[1]):(e.current=r.placeholders[0],Q(e)):M(r.parentPlaceholder.nodes,r)}function H(e){e.selectionDiff=null,e.inclusiveSelectionRightBorder=null,e.inclusiveSelectionLeftBorder=null}function I(e){if(e.selectionDiff==null)throw"Enter selection mode before calling this method.";if(e.selectionDiff==0)return H(e),[];let r=e.selectionDiff;if(e.current instanceof l)return H(e),e.current.nodes.splice(0,r);{let t=e.current.parentPlaceholder.nodes,o=t.indexOf(e.inclusiveSelectionLeftBorder);return e.current=u(t,e.inclusiveSelectionLeftBorder)??e.current.parentPlaceholder,H(e),t.splice(o,ae(r))}}function ae(e){return e<0?-e:e}function de(e){I(e)}function b(e){if(e.current instanceof l)if(e.current.nodes.length>0){let r=e.current.nodes[0];e.current=r instanceof p?r.placeholders[0]:r}else{if(e.current.parentNode==null)return;e.current=w(e.current.parentNode.placeholders,e.current)??e.current.parentNode}else{let r=w(e.current.parentPlaceholder.nodes,e.current);if(r!=null)e.current=r instanceof p?r.placeholders[0]:r;else{let t=e.current.parentPlaceholder.parentNode;if(t!=null){let o=w(t.placeholders,e.current.parentPlaceholder);e.current=o??t}}}}function a(e,r){if(e.current instanceof l)e.current.nodes.unshift(r),r.parentPlaceholder=e.current;else{let t=e.current.parentPlaceholder,o=t.nodes.indexOf(e.current);t.nodes.splice(o+1,0,r),r.parentPlaceholder=t}b(e)}var P=class extends p{constructor(t,o,...n){let i=n.length+1,d=new Array;for(let s=0;s<i;s++)d.push(new l);super(d);this.before=t,this.then=o,this.rest=n}getLatexPart(t,o){let n=this.before+this.placeholders[0].getLatex(t,o)+this.then;for(let i=0;i<this.rest.length;i++)n+=this.placeholders[i+1].getLatex(t,o)+this.rest[i];return n}};var j=class extends P{constructor(r=String.raw`\left(`,t=String.raw`\right)`){super(r,t)}};function E(e,r){for(let t of e)t.parentPlaceholder=r,r.nodes.push(t)}function q(e,r,t){let o=r.placeholders[0];if(e.current instanceof h){let n=e.current.parentPlaceholder.nodes,i=n.indexOf(e.current);n[i]=r,r.parentPlaceholder=e.current.parentPlaceholder,e.current instanceof j&&t?.deleteOuterRoundBracketsIfAny?(E(e.current.placeholders[0].nodes,o),e.current=w(r.placeholders,o)??r):e.current instanceof x?(o.nodes.push(e.current),e.current.parentPlaceholder=o,J(i,n,o),b(e)):(o.nodes.push(e.current),e.current.parentPlaceholder=o,b(e))}else a(e,r)}function fe(e,r){let t=I(e);if(a(e,r),t.length>0){let o=r.placeholders[0];E(t,o),e.current=g(t),b(e)}}function pe(e,r){if(r.placeholders.length<2)throw"Expected 2 placeholders.";let t=I(e),o=r.placeholders[1];E(t,o),q(e,r),e.current=v(t)??o}function me(e){let r=e.current instanceof l?e.current:e.current.parentPlaceholder,t;for(;;){if(r.parentNode==null)return;t=r.parentNode;let o=t.getMoveDownSuggestion(r);if(o!=null){e.current=v(o.nodes)??o;return}r=t.parentPlaceholder}}function ue(e){if(e.current instanceof l){if(e.current.parentNode==null)return;let r=u(e.current.parentNode.placeholders,e.current);if(r!==null)e.current=v(r.nodes)??r;else{let t=e.current.parentNode.parentPlaceholder,o=u(t.nodes,e.current.parentNode);e.current=o??t}}else if(e.current instanceof p){let r=g(e.current.placeholders);e.current=v(r.nodes)??r}else e.current=u(e.current.parentPlaceholder.nodes,e.current)??e.current.parentPlaceholder}function he(e){let r=e.current instanceof l?e.current:e.current.parentPlaceholder,t;for(;;){if(r.parentNode==null)return;t=r.parentNode;let o=t.getMoveUpSuggestion(r);if(o!=null){e.current=v(o.nodes)??o;return}r=t.parentPlaceholder}}function K(e,r){if(e.selectionDiff=r,r==0)e.inclusiveSelectionLeftBorder=null,e.inclusiveSelectionRightBorder=null;else if(e.current instanceof l)e.inclusiveSelectionLeftBorder=e.current,e.inclusiveSelectionRightBorder=e.current.nodes[r-1];else{let t=e.current.parentPlaceholder.nodes,o=t.indexOf(e.current);if(r>0)e.inclusiveSelectionLeftBorder=t[o+1],e.inclusiveSelectionRightBorder=t[o+r];else{let n=o+r+1;if(n<0)throw"The TreeNode at index 0 of the current Placeholder is as far as you can go left if current is a TreeNode.";e.inclusiveSelectionLeftBorder=t[n],e.inclusiveSelectionRightBorder=e.current}}}function ge(e){K(e,0)}function xe(e){return e.selectionDiff!=null}function Pe(e){let r=e.selectionDiff??0;e.current instanceof h&&e.current.parentPlaceholder.nodes.indexOf(e.current)+r>=0||e.current instanceof l&&r>0?K(e,r-1):e.inclusiveSelectionLeftBorder instanceof h&&e.inclusiveSelectionLeftBorder.parentPlaceholder.nodes.indexOf(e.inclusiveSelectionLeftBorder)==0&&e.inclusiveSelectionLeftBorder.parentPlaceholder.parentNode!=null&&(e.current=e.inclusiveSelectionLeftBorder.parentPlaceholder.parentNode,K(e,-1))}function ye(e){let r=e.selectionDiff??0;if(e.current instanceof l&&r<e.current.nodes.length||e.current instanceof h&&e.current.parentPlaceholder.nodes.indexOf(e.current)+r<e.current.parentPlaceholder.nodes.length-1)K(e,r+1);else if(e.inclusiveSelectionRightBorder instanceof h&&g(e.inclusiveSelectionRightBorder.parentPlaceholder.nodes)==e.inclusiveSelectionRightBorder&&e.inclusiveSelectionRightBorder.parentPlaceholder.parentNode!=null){let t=e.inclusiveSelectionRightBorder.parentPlaceholder.parentNode;e.current=u(t.parentPlaceholder.nodes,t)??t.parentPlaceholder,K(e,1)}}var F=class extends P{getMoveDownSuggestion(r){let t=this.placeholders.indexOf(r);return t>0?this.placeholders[t-1]:null}getMoveUpSuggestion(r){let t=this.placeholders.indexOf(r);return t<this.placeholders.length-1?this.placeholders[t+1]:null}};var V=class extends x{constructor(t="."){super();this.latex=typeof t=="string"?()=>t:t}getLatexPart(t,o){return this.latex()}};var A=class extends P{getMoveDownSuggestion(r){let t=this.placeholders.indexOf(r);return t<this.placeholders.length-1?this.placeholders[t+1]:null}getMoveUpSuggestion(r){let t=this.placeholders.indexOf(r);return t>0?this.placeholders[t-1]:null}};var z=class extends x{constructor(t){super();this.latex=t}getLatexPart(t,o){return this.latex}};var B=class extends R{constructor(t){super();this.latex=typeof t=="string"?()=>t:t}getLatexPart(t,o){return this.latex()}};function C(e,r,t){let o=e.slice(-1),n=t.slice(e.length),i=0;for(let d=0;d<n.length;d++){if(n[d]==r){if(i==0)return{content:n.slice(0,d),rest:n.slice(d+1)};i--;continue}let s=["\\"+o,"\\"+r,String.raw`\left`+o,String.raw`\right`+r],m=n.slice(d);for(let c of s)if(m.length>=c.length&&m.startsWith(c)){d+=c.length;continue}n[d]==o&&i++}throw`A closing ${r} is missing.`}var G=class extends p{constructor(t,o,n){let i=[],d=[];for(let s=0;s<n;s++){let m=[];for(let c=0;c<o;c++){let f=new l;m.push(f),d.push(f)}i.push(m)}super(d);this.grid=i,this.matrixType=t,this.width=o}getLatexPart(t,o){let n=String.raw`\begin{${this.matrixType}}`;return n+=this.grid.map(i=>i.map(d=>d.getLatex(t,o)).join(" & ")).join(String.raw` \\ `),n+=String.raw`\end{${this.matrixType}}`,n}getMoveDownSuggestion(t){let{rowIndex:o,columnIndex:n}=this.getPositionOf(t);return o+1<this.grid.length?this.grid[o+1][n]:null}getMoveUpSuggestion(t){let{rowIndex:o,columnIndex:n}=this.getPositionOf(t);return o-1>=0?this.grid[o-1][n]:null}getPositionOf(t){let o=this.placeholders.indexOf(t);if(o==-1)throw"The provided Placeholder is not part of this MatrixNode.";let n=Math.floor(o/this.width),i=o-n*this.width;return{rowIndex:n,columnIndex:i}}};function _(e,r,t){let o=e?.trim();if(o==null||o=="")return new L;let n=new L;for(;o!="";){if(o[0]==" "){o=o.trimStart();continue}if(o.startsWith(t.decimalSeparator)){a(n,new V(t.decimalSeparator)),o=o.slice(t.decimalSeparator.length);continue}if(["1","2","3","4","5","6","7","8","9","0"].includes(o[0])||t.additionalDigits?.includes(o[0])){a(n,new z(o[0])),o=o.slice(1);continue}let i=!1;if(o.startsWith(String.raw`\begin{`)){let s=C(String.raw`\begin{`,"}",o);if(!s.content.endsWith("matrix")&&!s.content.endsWith("cases"))throw String.raw`Expected a word ending with 'matrix' or 'cases' after '\begin{'.`;let c=s.rest.slice(0,s.rest.indexOf(String.raw`\end{${s.content}}`)).split(String.raw`\\`);a(n,new G(s.content,c[0].split("&").length,c.length));for(let y of c)for(let N of y.split("&")){let W=_(N,r,t).syntaxTreeRoot.nodes;for(let S of W)a(n,S),n.current=S;b(n)}let f=String.raw`\end{${s.content}}`;o=o.slice(o.indexOf(f)+f.length);continue}if(o.startsWith("\\")){for(let c of["\\left\\","\\right\\",String.raw`\left`,String.raw`\right`])if(o.startsWith(c)){a(n,new B(c+o[c.length])),o=o.slice(c.length+1),i=!0;break}if(i)continue;for(let c of t.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets){let f=c.slice(0,-3),y=c.slice(-3,-2),N=c.slice(-2,-1),W=c.slice(-1);if(o.startsWith(f)){let S=C(f,y,o);if(S.rest[0]!=N)continue;let $=new A(f,y+N,W);a(n,$);let oe=_(S.content,r,t).syntaxTreeRoot.nodes;for(let U of oe)a(n,U),n.current=U;b(n);let Z=C(N,W,S.rest),ne=_(Z.content,r,t).syntaxTreeRoot.nodes;for(let U of ne)a(n,U),n.current=U;n.current=$,o=Z.rest,i=!0;break}}if(i)continue;let s=String.raw`\text{`;if(o.startsWith(s)){let c=C(s,"}",o),f=new P(s,"}");a(n,f);for(let y of c.content)a(n,new B(y));n.current=f,o=c.rest;continue}let m="\\";if(T(o[1])){for(let c=1;c<o.length;c++){let f=o[c];if(T(f))m+=f;else if(f=="{"){m+=f;let y=m,N=C(y,"}",o),W=_(N.content,r,t).syntaxTreeRoot.nodes,S=new P(y,"}");a(n,S);for(let $ of W)a(n,$),n.current=$;n.current=S,o=N.rest,i=!0;break}else break}if(i)continue;a(n,new B(m)),o=o.slice(m.length)}else a(n,new B("\\"+o[1])),o=o.slice(2);continue}let d=[["^{",()=>new F("","^{","}")],["_{",()=>new A("","_{","}")]];for(let s of d){let m=s[0];if(o.startsWith(m)){let c=s[1]();q(n,c);let f=C(m,"}",o),y=_(f.content,r,t).syntaxTreeRoot.nodes;for(let N of y)a(n,N),n.current=N;n.current=c,o=f.rest,i=!0;break}}i!=!0&&(a(n,new B(o[0])),o=o.slice(1))}return n}var X=class{constructor(){this.additionalDigits=null;this.decimalSeparator=".";this.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets=[]}};var Y=class{constructor(){this.activePlaceholderShape=String.raw`\blacksquare`;this.passivePlaceholderShape=String.raw`\square`;this.selectionHightlightStart=String.raw`\colorbox{#ADD8E6}{\(\displaystyle`;this.selectionHightlightEnd=String.raw`\)}`}get activePlaceholderLatex(){return this.activePlaceholderColor==null?this.activePlaceholderShape:String.raw`{\color{${this.activePlaceholderColor}}${this.activePlaceholderShape}}`}get passivePlaceholderLatex(){return this.passivePlaceholderColor==null?this.passivePlaceholderShape:String.raw`{\color{${this.passivePlaceholderColor}}${this.passivePlaceholderShape}}`}};export{F as AscendingBranchingNode,p as BranchingNode,V as DecimalSeparatorNode,A as DescendingBranchingNode,z as DigitNode,L as KeyboardMemory,Y as LatexConfiguration,X as LatexParserConfiguration,R as LeafNode,G as MatrixNode,l as Placeholder,j as RoundBracketsNode,P as StandardBranchingNode,B as StandardLeafNode,h as TreeNode,re as deleteLeft,Q as deleteRight,de as deleteSelection,ge as enterSelectionMode,ie as getEditModeLatex,ce as getViewModeLatex,xe as inSelectionMode,a as insert,q as insertWithEncapsulateCurrent,fe as insertWithEncapsulateSelection,pe as insertWithEncapsulateSelectionAndPrevious,H as leaveSelectionMode,me as moveDown,ue as moveLeft,b as moveRight,he as moveUp,_ as parseLatex,Pe as selectLeft,ye as selectRight};

@@ -1,7 +0,7 @@

ISC License
BSD Zero Clause License
Copyright © MathKeyboardEngine
Copyright (c) MathKeyboardEngine
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

@@ -23,3 +23,3 @@ {

],
"version": "v1.0.1",
"version": "v1.1.0-alpha",
"types": "./dist/MathKeyboardEngine.d.ts",

@@ -59,3 +59,3 @@ "exports": {

"author": "MathKeyboardEngine",
"license": "ISC",
"license": "0BSD",
"bugs": {

@@ -62,0 +62,0 @@ "url": "https://github.com/MathKeyboardEngine/MathKeyboardEngine/issues"

@@ -12,3 +12,6 @@ [![](https://badgen.net/npm/v/mathkeyboardengine?label=latest%20release)](https://www.jsdelivr.com/package/npm/mathkeyboardengine?path=dist)

- [MathKeyboardEngine for Python](https://github.com/MathKeyboardEngine/MathKeyboardEngine.Python#readme).
- [MathKeyboardEngine for Swift](https://github.com/MathKeyboardEngine/MathKeyboardEngine.Swift#readme).
- [MathKeyboardEngine for other languages](https://github.com/MathKeyboardEngine).
#### An execution timeline

@@ -21,2 +24,3 @@

#### Let me test it now!

@@ -26,2 +30,3 @@

#### Pros and cons?

@@ -46,2 +51,3 @@

## How to use this library

@@ -150,2 +156,19 @@

## License
The MathKeyboardEngine repositories use the most permissive licensing available. The "BSD Zero Clause License" ([0BSD](https://choosealicense.com/licenses/0bsd/)) allows for<br/>
commercial + non-commercial use, closed + open source, with + without modifications, etc. and [is equivalent](https://github.com/github/choosealicense.com/issues/805) to licenses like:
- "MIT No Attribution License" ([MIT-0](https://choosealicense.com/licenses/mit-0//)).
- "The Unlicense" ([Unlicense](https://choosealicense.com/licenses/unlicense/)).
- "CC0" ([CC0](https://choosealicense.com/licenses/cc0/)).
The "BSD Zero Clause License" ([0BSD](https://choosealicense.com/licenses/0bsd/)) does not have the condition
> (...), provided that the above copyright notice and this permission notice appear in all copies.
which is part of the "MIT License" ([MIT](https://choosealicense.com/licenses/mit/)) and its shorter equivalent "ISC License" ([ISC](https://choosealicense.com/licenses/isc/)). Apart from that they are all equivalent.
## Ask or contribute

@@ -152,0 +175,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc