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.1.0-alpha.3 to 1.1.0-alpha.4

55

dist/MathKeyboardEngine.d.ts
export declare function getEditModeLatex(k: KeyboardMemory, latexConfiguration: LatexConfiguration): string;
export declare function firstBeforeOrNull<T>(array: T[], element: T): T | null;
export declare function firstAfterOrNull<T>(array: T[], element: T): T | null;

@@ -7,26 +9,24 @@

export declare function firstBeforeOrNull<T>(array: T[], element: T): T | null;
export declare function lastOrNull<T>(array: T[]): T | null;
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 deleteRight(k: KeyboardMemory): void;
export declare function remove<T>(array: T[], element: T): void;
export declare function endsWithLatexCommand(latex: string): boolean;
export declare function isLetter(c: string): boolean;
export declare function concatLatex(...latexArray: string[]): string;
export declare function deleteLeft(k: KeyboardMemory): void;
export declare function remove<T>(array: T[], element: T): void;
export declare function deleteRight(k: KeyboardMemory): void;
export declare function deleteLeft(k: KeyboardMemory): void;
export declare function endsWithLatexCommand(latex: string): boolean;
export declare function deleteSelection(k: KeyboardMemory): void;
export declare function deleteOuterBranchingNodeButNotItsContents(nonEmptyPlaceholder: Placeholder): void;
export declare function encapsulate(nodes: TreeNode[], encapsulatingPlaceholder: Placeholder): void;
export declare function deleteOuterBranchingNodeButNotItsContents(nonEmptyPlaceholder: Placeholder): void;
export declare function encapsulateAllPartsOfNumberWithDigitsLeftOfIndex(exclusiveRightIndex: number, siblingNodes: TreeNode[], toPlaceholder: Placeholder): void;

@@ -46,8 +46,10 @@

export declare function insertWithEncapsulateSelectionAndPrevious(k: KeyboardMemory, newNode: BranchingNode): void;
export declare function moveDown(k: KeyboardMemory): void;
export declare function moveUp(k: KeyboardMemory): void;
export declare function moveRight(k: KeyboardMemory): void;
export declare function moveUp(k: KeyboardMemory): void;
export declare function enterSelectionMode(k: KeyboardMemory): void;

@@ -57,12 +59,10 @@

export declare function leaveSelectionMode(k: KeyboardMemory): void;
export declare function setSelectionDiff(k: KeyboardMemory, diffWithCurrent: number): void;
export declare function insertWithEncapsulateSelectionAndPrevious(k: KeyboardMemory, newNode: BranchingNode): void;
export declare function selectLeft(k: KeyboardMemory): void;
export declare function inSelectionMode(k: KeyboardMemory): boolean;
export declare function leaveSelectionMode(k: KeyboardMemory): void;
export declare function selectLeft(k: KeyboardMemory): void;
export declare function selectRight(k: KeyboardMemory): void;

@@ -96,4 +96,2 @@

export declare function parseLatex(latex: string | null, latexConfiguration: LatexConfiguration, latexParserConfiguration: LatexParserConfiguration): KeyboardMemory;
export declare abstract class BranchingNode extends TreeNode {

@@ -109,6 +107,7 @@ placeholders: Placeholder[];

decimalSeparator: string;
descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets: string[];
useRoundBracketsNode: boolean;
preferRoundBracketsNode: boolean;
}
export declare function parseLatex(latex: string | null, latexConfiguration: LatexConfiguration, latexParserConfiguration: LatexParserConfiguration): KeyboardMemory;
export declare abstract class TreeNode {

@@ -148,2 +147,5 @@ parentPlaceholder: Placeholder;

export declare abstract class PartOfNumberWithDigits extends LeafNode {
}
export declare class StandardBranchingNode extends BranchingNode {

@@ -169,8 +171,2 @@ private readonly before;

export declare class Placeholder {
parentNode: BranchingNode | null;
nodes: TreeNode[];
getLatex(k: KeyboardMemory, latexConfiguration: LatexConfiguration): string;
}
export declare class StandardLeafNode extends LeafNode {

@@ -182,4 +178,7 @@ private readonly latex;

export declare abstract class PartOfNumberWithDigits extends LeafNode {
export declare class Placeholder {
parentNode: BranchingNode | null;
nodes: TreeNode[];
getLatex(k: KeyboardMemory, latexConfiguration: LatexConfiguration): string;
}

@@ -881,8 +881,8 @@ "use strict";

}
if (latexParserConfiguration.useRoundBracketsNode && (x[0] == "(" || x.startsWith(String.raw`\left(`))) {
if (latexParserConfiguration.preferRoundBracketsNode && (x[0] == "(" || x.startsWith(String.raw`\left(`))) {
const opening = x[0] == "(" ? "(" : String.raw`\left(`;
const closing = x[0] == "(" ? ")" : String.raw`\right)`;
const bracketsContentAndRest = getBracketPairContent(opening, closing, x);
const bracketsNode = new RoundBracketsNode(opening, closing);
insert(k, bracketsNode);
const bracketsContentAndRest = getBracketPairContent(opening, closing, x);
const bracketsContentNodes = parseLatex(bracketsContentAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;

@@ -896,3 +896,3 @@ insert(k, bracketsContentNodes);

for (const prefix of ["\\left\\", "\\right\\", String.raw`\left`, String.raw`\right`]) {
if (x.startsWith(prefix)) {
if (x.startsWith(prefix) && !isLetter(x.slice(prefix.length)[0])) {
insert(k, new StandardLeafNode(prefix + x[prefix.length]));

@@ -907,29 +907,2 @@ x = x.slice(prefix.length + 1);

}
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 numeratorNodes = parseLatex(numeratorAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
insert(k, numeratorNodes);
moveRight(k);
const denominatorAndRest = getBracketPairContent(openingBracket2, closingBracket2, numeratorAndRest.rest);
const denominatorNodes = parseLatex(denominatorAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
insert(k, denominatorNodes);
k.current = node;
x = denominatorAndRest.rest;
handled = true;
break;
}
}
if (handled) {
continue;
}
const textOpening = String.raw`\text{`;

@@ -953,12 +926,24 @@ if (x.startsWith(textOpening)) {

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);
insert(k, placeholderContent);
k.current = branchingNode;
x = bracketPairContentAndRest.rest;
} else if (character == "{" || character == "[") {
const opening = command + character;
const closingBracket1 = character == "{" ? "}" : "]";
const bracketPair1ContentAndRest = getBracketPairContent(opening, closingBracket1, x);
const placeholder1Nodes = parseLatex(bracketPair1ContentAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
if (bracketPair1ContentAndRest.rest[0] == "{") {
const multiPlaceholderBranchingNode = new DescendingBranchingNode(opening, closingBracket1 + "{", "}");
insert(k, multiPlaceholderBranchingNode);
insert(k, placeholder1Nodes);
moveRight(k);
const bracketPair2ContentAndRest = getBracketPairContent("{", "}", bracketPair1ContentAndRest.rest);
const placeholder2Nodes = parseLatex(bracketPair2ContentAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
insert(k, placeholder2Nodes);
k.current = multiPlaceholderBranchingNode;
x = bracketPair2ContentAndRest.rest;
} else {
const singlePlaceholderBranchingNode = new StandardBranchingNode(opening, closingBracket1);
insert(k, singlePlaceholderBranchingNode);
insert(k, placeholder1Nodes);
k.current = singlePlaceholderBranchingNode;
x = bracketPair1ContentAndRest.rest;
}
handled = true;

@@ -981,2 +966,20 @@ break;

}
if (x.startsWith("_{")) {
const opening = "_{";
const closingBracket1 = "}";
const bracketPair1ContentAndRest = getBracketPairContent(opening, closingBracket1, x);
if (bracketPair1ContentAndRest.rest.startsWith("^{")) {
const ascendingBranchingNode = new AscendingBranchingNode(opening, "}^{", "}");
insert(k, ascendingBranchingNode);
const placeholder1Nodes = parseLatex(bracketPair1ContentAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
insert(k, placeholder1Nodes);
moveRight(k);
const bracketPair2ContentAndRest = getBracketPairContent("^{", "}", bracketPair1ContentAndRest.rest);
const placeholder2Nodes = parseLatex(bracketPair2ContentAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
insert(k, placeholder2Nodes);
k.current = ascendingBranchingNode;
x = bracketPair2ContentAndRest.rest;
continue;
}
}
const various = [

@@ -1015,4 +1018,3 @@ ["^{", () => new AscendingBranchingNode("", "^{", "}")],

this.decimalSeparator = ".";
this.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets = [];
this.useRoundBracketsNode = true;
this.preferRoundBracketsNode = true;
}

@@ -1019,0 +1021,0 @@ };

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

"use strict";var mke=(()=>{var Y=Object.defineProperty;var Pe=Object.getOwnPropertyDescriptor;var ye=Object.getOwnPropertyNames;var Ne=Object.prototype.hasOwnProperty;var ve=(e,o)=>{for(var r in o)Y(e,r,{get:o[r],enumerable:!0})},be=(e,o,r,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of ye(o))!Ne.call(e,n)&&n!==r&&Y(e,n,{get:()=>o[n],enumerable:!(t=Pe(o,n))||t.enumerable});return e};var Se=e=>be(Y({},"__esModule",{value:!0}),e);var Te={};ve(Te,{AscendingBranchingNode:()=>q,BranchingNode:()=>m,DecimalSeparatorNode:()=>F,DescendingBranchingNode:()=>E,DigitNode:()=>V,KeyboardMemory:()=>S,LatexConfiguration:()=>X,LatexParserConfiguration:()=>Q,LeafNode:()=>O,MatrixNode:()=>z,Placeholder:()=>c,RoundBracketsNode:()=>R,StandardBranchingNode:()=>x,StandardLeafNode:()=>L,TreeNode:()=>u,deleteLeft:()=>Z,deleteRight:()=>J,deleteSelection:()=>le,enterSelectionMode:()=>fe,getEditModeLatex:()=>re,getViewModeLatex:()=>oe,inSelectionMode:()=>me,insert:()=>a,insertWithEncapsulateCurrent:()=>j,insertWithEncapsulateSelection:()=>ce,insertWithEncapsulateSelectionAndPrevious:()=>se,leaveSelectionMode:()=>$,moveDown:()=>ae,moveLeft:()=>de,moveRight:()=>N,moveUp:()=>pe,parseLatex:()=>W,selectLeft:()=>ue,selectRight:()=>he});function re(e,o){return e.syntaxTreeRoot.getLatex(e,o)}function T(e){return e.toLowerCase()!=e.toUpperCase()}function te(e){if(e.length==0)return!1;if(T(e[e.length-1]))for(let o=e.length-2;o>=0;o--){let r=e[o];if(!T(r))return r=="\\"}return!1}function w(...e){let o="";for(let r=0;r<e.length;r++){let t=e[r];te(o)&&T(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 S=class{constructor(){this.syntaxTreeRoot=new c;this.current=this.syntaxTreeRoot;this.selectionDiff=null;this.inclusiveSelectionRightBorder=null;this.inclusiveSelectionLeftBorder=null}};var Le=new S;function oe(e,o){return(e instanceof S?e.syntaxTreeRoot:e).getLatex(Le,o)}function ne(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 h(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 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 m=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 P(e){return e[e.length-1]}var O=class extends u{};var y=class extends O{};function G(e,o,r){for(let t=e-1;t>=0;t--){let n=o[t];if(n instanceof y)B(o,n),r.nodes.unshift(n),n.parentPlaceholder=r;else break}}function A(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 Z(e){var o;if(e.current instanceof c){if(e.current.parentNode==null||e.current.nodes.length>0)return;{let r=ne(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?(A(r),e.current=P(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=h(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=h(e.current.parentNode.parentPlaceholder.nodes,e.current.parentNode);if(t!=null)Be(t,e.current),e.current=P(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,v=l.nodes.indexOf(e.current.parentNode);for(let d of i)d.parentPlaceholder=l;l.nodes.splice(v,1,...i),e.current=P(i)}}}}}else if(e.current instanceof m&&e.current.placeholders[0].nodes.length>0&&e.current.placeholders.slice(1).every(r=>r.nodes.length==0)){let r=e.current.placeholders[0];A(r),e.current=P(r.nodes)}else if(e.current instanceof m&&e.current.placeholders.some(r=>r.nodes.length>0))e.current=P(e.current.placeholders.flatMap(r=>r.nodes)),Z(e);else{let r=h(e.current.parentPlaceholder.nodes,e.current);B(e.current.parentPlaceholder.nodes,e.current),e.current=r!=null?r:e.current.parentPlaceholder}}function Be(e,o){B(o.parentNode.parentPlaceholder.nodes,e),o.nodes.push(e);let r=e.parentPlaceholder;e.parentPlaceholder=o,e instanceof y&&G(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 J(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);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)ie(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,A(i)}else for(let i=n.indexOf(e.current)+1;i<n.length;i++)if(n[i].nodes.length>0){e.current=n[i],J(e);return}}}else{let r=K(e.current.parentPlaceholder.nodes,e.current);r!=null&&ie(e,r)}}function ie(e,o){o instanceof m?o.placeholders.length==1&&o.placeholders[0].nodes.length>0?A(o.placeholders[0]):o.placeholders.length==2&&o.placeholders[0].nodes.length==0&&o.placeholders[1].nodes.length>0?A(o.placeholders[1]):(e.current=o.placeholders[0],J(e)):B(o.parentPlaceholder.nodes,o)}function $(e){e.selectionDiff=null,e.inclusiveSelectionRightBorder=null,e.inclusiveSelectionLeftBorder=null}function U(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,Me(o))}}function Me(e){return e<0?-e:e}function le(e){U(e)}function N(e){var o;if(e.current instanceof c)if(e.current.nodes.length>0){let r=e.current.nodes[0];e.current=r instanceof m?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 m?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 a(e,o){if(o instanceof Array)for(let r of o)a(e,r),e.current=r;else{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}N(e)}}var x=class extends m{constructor(r,t,...n){let i=n.length+1,l=new Array;for(let v=0;v<i;v++)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 R=class extends x{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 R&&(r!=null&&r.deleteOuterRoundBracketsIfAny)?(H(e.current.placeholders[0].nodes,t),e.current=(n=K(o.placeholders,t))!=null?n:o):e.current instanceof y?(t.nodes.push(e.current),e.current.parentPlaceholder=t,G(l,i,t),N(e)):(t.nodes.push(e.current),e.current.parentPlaceholder=t,N(e))}else a(e,o)}function ce(e,o){let r=U(e);if(a(e,o),r.length>0){let t=o.placeholders[0];H(r,t),e.current=P(r),N(e)}}function se(e,o){var n;if(o.placeholders.length<2)throw"Expected 2 placeholders.";let r=U(e),t=o.placeholders[1];H(r,t),j(e,o),e.current=(n=b(r))!=null?n:t}function ae(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 de(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=b(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 m){let n=P(e.current.placeholders);e.current=(r=b(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=b(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 fe(e){D(e,0)}function me(e){return e.selectionDiff!=null}function ue(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 he(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&&P(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 x{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 y{constructor(r="."){super();this.latex=typeof r=="string"?()=>r:r}getLatexPart(r,t){return this.latex()}};var E=class extends x{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 y{constructor(r){super();this.latex=r}getLatexPart(r,t){return this.latex}};var L=class extends O{constructor(r){super();this.latex=typeof r=="string"?()=>r:r}getLatexPart(r,t){return this.latex()}};function C(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.substring(l,l+o.length)==o){if(i==0)return{content:n.slice(0,l),rest:n.slice(l+o.length)};i--;continue}let v=["\\"+t,"\\"+o,String.raw`\left`+t,String.raw`\right`+o],d=n.slice(l);for(let f of v)if(d.length>=f.length&&d.startsWith(f)){l+=f.length;continue}n[l]==t&&i++}throw`A closing ${o} is missing.`}var z=class extends m{constructor(r,t,n){let i=[],l=[];for(let v=0;v<n;v++){let d=[];for(let f=0;f<t;f++){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 W(e,o,r){var i;let t=e==null?void 0:e.trim();if(t==null||t=="")return new S;let n=new S;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=C(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 g of s)for(let M of g.split("&")){let I=W(M,o,r).syntaxTreeRoot.nodes;a(n,I),N(n)}let p=String.raw`\end{${d.content}}`;t=t.slice(t.indexOf(p)+p.length);continue}if(r.useRoundBracketsNode&&(t[0]=="("||t.startsWith(String.raw`\left(`))){let d=t[0]=="("?"(":String.raw`\left(`,f=t[0]=="("?")":String.raw`\right)`,s=C(d,f,t),p=new R(d,f);a(n,p);let g=W(s.content,o,r).syntaxTreeRoot.nodes;a(n,g),n.current=p,t=s.rest;continue}if(t.startsWith("\\")){for(let s of["\\left\\","\\right\\",String.raw`\left`,String.raw`\right`])if(t.startsWith(s)){a(n,new L(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),g=s.slice(-3,-2),M=s.slice(-2,-1),I=s.slice(-1);if(t.startsWith(p)){let _=C(p,g,t);if(_.rest[0]!=M)continue;let k=new E(p,g+M,I);a(n,k);let ge=W(_.content,o,r).syntaxTreeRoot.nodes;a(n,ge),N(n);let ee=C(M,I,_.rest),xe=W(ee.content,o,r).syntaxTreeRoot.nodes;a(n,xe),n.current=k,t=ee.rest,l=!0;break}}if(l)continue;let d=String.raw`\text{`;if(t.startsWith(d)){let s=C(d,"}",t),p=new x(d,"}");a(n,p);for(let g of s.content)a(n,new L(g));n.current=p,t=s.rest;continue}let f="\\";if(T(t[1])){for(let s=1;s<t.length;s++){let p=t[s];if(T(p))f+=p;else if(p=="{"){f+=p;let g=f,M=C(g,"}",t),I=W(M.content,o,r).syntaxTreeRoot.nodes,_=new x(g,"}");a(n,_),a(n,I),n.current=_,t=M.rest,l=!0;break}else break}if(l)continue;a(n,new L(f)),t=t.slice(f.length)}else a(n,new L("\\"+t[1])),t=t.slice(2);continue}let v=[["^{",()=>new q("","^{","}")],["_{",()=>new E("","_{","}")]];for(let d of v){let f=d[0];if(t.startsWith(f)){let s=d[1]();j(n,s);let p=C(f,"}",t),g=W(p.content,o,r).syntaxTreeRoot.nodes;a(n,g),n.current=s,t=p.rest,l=!0;break}}l!=!0&&(a(n,new L(t[0])),t=t.slice(1))}return n}var Q=class{constructor(){this.additionalDigits=null;this.decimalSeparator=".";this.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets=[];this.useRoundBracketsNode=!0}};var X=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 Se(Te);})();
"use strict";var mke=(()=>{var Y=Object.defineProperty;var xe=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames;var ye=Object.prototype.hasOwnProperty;var Ne=(e,o)=>{for(var r in o)Y(e,r,{get:o[r],enumerable:!0})},ve=(e,o,r,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of Pe(o))!ye.call(e,n)&&n!==r&&Y(e,n,{get:()=>o[n],enumerable:!(t=xe(o,n))||t.enumerable});return e};var be=e=>ve(Y({},"__esModule",{value:!0}),e);var Me={};Ne(Me,{AscendingBranchingNode:()=>I,BranchingNode:()=>m,DecimalSeparatorNode:()=>q,DescendingBranchingNode:()=>_,DigitNode:()=>F,KeyboardMemory:()=>S,LatexConfiguration:()=>X,LatexParserConfiguration:()=>Q,LeafNode:()=>D,MatrixNode:()=>V,Placeholder:()=>c,RoundBracketsNode:()=>W,StandardBranchingNode:()=>P,StandardLeafNode:()=>L,TreeNode:()=>u,deleteLeft:()=>Z,deleteRight:()=>J,deleteSelection:()=>le,enterSelectionMode:()=>fe,getEditModeLatex:()=>re,getViewModeLatex:()=>oe,inSelectionMode:()=>me,insert:()=>a,insertWithEncapsulateCurrent:()=>j,insertWithEncapsulateSelection:()=>ce,insertWithEncapsulateSelectionAndPrevious:()=>se,leaveSelectionMode:()=>$,moveDown:()=>ae,moveLeft:()=>de,moveRight:()=>x,moveUp:()=>pe,parseLatex:()=>w,selectLeft:()=>ue,selectRight:()=>he});function re(e,o){return e.syntaxTreeRoot.getLatex(e,o)}function B(e){return e.toLowerCase()!=e.toUpperCase()}function te(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 R(...e){let o="";for(let r=0;r<e.length;r++){let t=e[r];te(o)&&B(t[0])&&(o+=" "),o+=t}return o}var c=class{constructor(){this.parentNode=null;this.nodes=[]}getLatex(o,r){let t=()=>R(...this.nodes.map(n=>n.getLatex(o,r)));return o.inclusiveSelectionLeftBorder===this?R(r.selectionHightlightStart,t()):this===o.current?this.nodes.length==0?r.activePlaceholderLatex:R(r.activePlaceholderLatex,t()):this.nodes.length==0?r.passivePlaceholderLatex:t()}};var S=class{constructor(){this.syntaxTreeRoot=new c;this.current=this.syntaxTreeRoot;this.selectionDiff=null;this.inclusiveSelectionRightBorder=null;this.inclusiveSelectionLeftBorder=null}};var Se=new S;function oe(e,o){return(e instanceof S?e.syntaxTreeRoot:e).getLatex(Se,o)}function ne(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 h(e,o){let r=e.indexOf(o);return r>0?e[r-1]:null}function M(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=R(r.selectionHightlightStart,t)),o.inclusiveSelectionRightBorder===this&&(t=R(t,r.selectionHightlightEnd)),t):o.current===this?R(t,r.activePlaceholderLatex):t}};var m=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 y(e){return e[e.length-1]}var D=class extends u{};var N=class extends D{};function G(e,o,r){for(let t=e-1;t>=0;t--){let n=o[t];if(n instanceof N)M(o,n),r.nodes.unshift(n),n.parentPlaceholder=r;else break}}function E(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 Z(e){var o;if(e.current instanceof c){if(e.current.parentNode==null||e.current.nodes.length>0)return;{let r=ne(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?(E(r),e.current=y(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=h(t.nodes,e.current.parentNode);M(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)Le(t,e.current),e.current=y(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,v=l.nodes.indexOf(e.current.parentNode);for(let d of i)d.parentPlaceholder=l;l.nodes.splice(v,1,...i),e.current=y(i)}}}}}else if(e.current instanceof m&&e.current.placeholders[0].nodes.length>0&&e.current.placeholders.slice(1).every(r=>r.nodes.length==0)){let r=e.current.placeholders[0];E(r),e.current=y(r.nodes)}else if(e.current instanceof m&&e.current.placeholders.some(r=>r.nodes.length>0))e.current=y(e.current.placeholders.flatMap(r=>r.nodes)),Z(e);else{let r=h(e.current.parentPlaceholder.nodes,e.current);M(e.current.parentPlaceholder.nodes,e.current),e.current=r!=null?r:e.current.parentPlaceholder}}function Le(e,o){M(o.parentNode.parentPlaceholder.nodes,e),o.nodes.push(e);let r=e.parentPlaceholder;e.parentPlaceholder=o,e instanceof N&&G(r.nodes.length-1,r.nodes,o)}function C(e,o){let r=e.indexOf(o);return r!=-1&&r<e.length-1?e[r+1]:null}function J(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);M(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)ie(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,E(i)}else for(let i=n.indexOf(e.current)+1;i<n.length;i++)if(n[i].nodes.length>0){e.current=n[i],J(e);return}}}else{let r=C(e.current.parentPlaceholder.nodes,e.current);r!=null&&ie(e,r)}}function ie(e,o){o instanceof m?o.placeholders.length==1&&o.placeholders[0].nodes.length>0?E(o.placeholders[0]):o.placeholders.length==2&&o.placeholders[0].nodes.length==0&&o.placeholders[1].nodes.length>0?E(o.placeholders[1]):(e.current=o.placeholders[0],J(e)):M(o.parentPlaceholder.nodes,o)}function $(e){e.selectionDiff=null,e.inclusiveSelectionRightBorder=null,e.inclusiveSelectionLeftBorder=null}function U(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,Be(o))}}function Be(e){return e<0?-e:e}function le(e){U(e)}function x(e){var o;if(e.current instanceof c)if(e.current.nodes.length>0){let r=e.current.nodes[0];e.current=r instanceof m?r.placeholders[0]:r}else{if(e.current.parentNode==null)return;e.current=(o=C(e.current.parentNode.placeholders,e.current))!=null?o:e.current.parentNode}else{let r=C(e.current.parentPlaceholder.nodes,e.current);if(r!=null)e.current=r instanceof m?r.placeholders[0]:r;else{let t=e.current.parentPlaceholder.parentNode;if(t!=null){let n=C(t.placeholders,e.current.parentPlaceholder);e.current=n!=null?n:t}}}}function a(e,o){if(o instanceof Array)for(let r of o)a(e,r),e.current=r;else{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}x(e)}}var P=class extends m{constructor(r,t,...n){let i=n.length+1,l=new Array;for(let v=0;v<i;v++)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 W=class extends P{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 W&&(r!=null&&r.deleteOuterRoundBracketsIfAny)?(H(e.current.placeholders[0].nodes,t),e.current=(n=C(o.placeholders,t))!=null?n:o):e.current instanceof N?(t.nodes.push(e.current),e.current.parentPlaceholder=t,G(l,i,t),x(e)):(t.nodes.push(e.current),e.current.parentPlaceholder=t,x(e))}else a(e,o)}function ce(e,o){let r=U(e);if(a(e,o),r.length>0){let t=o.placeholders[0];H(r,t),e.current=y(r),x(e)}}function se(e,o){var n;if(o.placeholders.length<2)throw"Expected 2 placeholders.";let r=U(e),t=o.placeholders[1];H(r,t),j(e,o),e.current=(n=b(r))!=null?n:t}function ae(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 de(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=b(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 m){let n=y(e.current.placeholders);e.current=(r=b(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=b(n.nodes))!=null?t:n;return}o=r.parentPlaceholder}}function A(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 fe(e){A(e,0)}function me(e){return e.selectionDiff!=null}function ue(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?A(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,A(e,-1))}function he(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)A(e,o+1);else if(e.inclusiveSelectionRightBorder instanceof u&&y(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,A(e,1)}}var I=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 q=class extends N{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 F=class extends N{constructor(r){super();this.latex=r}getLatexPart(r,t){return this.latex}};var L=class extends D{constructor(r){super();this.latex=typeof r=="string"?()=>r:r}getLatexPart(r,t){return this.latex()}};function T(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.substring(l,l+o.length)==o){if(i==0)return{content:n.slice(0,l),rest:n.slice(l+o.length)};i--;continue}let v=["\\"+t,"\\"+o,String.raw`\left`+t,String.raw`\right`+o],d=n.slice(l);for(let f of v)if(d.length>=f.length&&d.startsWith(f)){l+=f.length;continue}n[l]==t&&i++}throw`A closing ${o} is missing.`}var V=class extends m{constructor(r,t,n){let i=[],l=[];for(let v=0;v<n;v++){let d=[];for(let f=0;f<t;f++){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 w(e,o,r){var i;let t=e==null?void 0:e.trim();if(t==null||t=="")return new S;let n=new S;for(;t!="";){if(t[0]==" "){t=t.trimStart();continue}if(t.startsWith(r.decimalSeparator)){a(n,new q(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 F(t[0])),t=t.slice(1);continue}let l=!1;if(t.startsWith(String.raw`\begin{`)){let d=T(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 V(d.content,s[0].split("&").length,s.length));for(let g of s)for(let O of g.split("&")){let K=w(O,o,r).syntaxTreeRoot.nodes;a(n,K),x(n)}let p=String.raw`\end{${d.content}}`;t=t.slice(t.indexOf(p)+p.length);continue}if(r.preferRoundBracketsNode&&(t[0]=="("||t.startsWith(String.raw`\left(`))){let d=t[0]=="("?"(":String.raw`\left(`,f=t[0]=="("?")":String.raw`\right)`,s=new W(d,f);a(n,s);let p=T(d,f,t),g=w(p.content,o,r).syntaxTreeRoot.nodes;a(n,g),n.current=s,t=p.rest;continue}if(t.startsWith("\\")){for(let s of["\\left\\","\\right\\",String.raw`\left`,String.raw`\right`])if(t.startsWith(s)&&!B(t.slice(s.length)[0])){a(n,new L(s+t[s.length])),t=t.slice(s.length+1),l=!0;break}if(l)continue;let d=String.raw`\text{`;if(t.startsWith(d)){let s=T(d,"}",t),p=new P(d,"}");a(n,p);for(let g of s.content)a(n,new L(g));n.current=p,t=s.rest;continue}let f="\\";if(B(t[1])){for(let s=1;s<t.length;s++){let p=t[s];if(B(p))f+=p;else if(p=="{"||p=="["){let g=f+p,O=p=="{"?"}":"]",K=T(g,O,t),k=w(K.content,o,r).syntaxTreeRoot.nodes;if(K.rest[0]=="{"){let z=new _(g,O+"{","}");a(n,z),a(n,k),x(n);let ee=T("{","}",K.rest),ge=w(ee.content,o,r).syntaxTreeRoot.nodes;a(n,ge),n.current=z,t=ee.rest}else{let z=new P(g,O);a(n,z),a(n,k),n.current=z,t=K.rest}l=!0;break}else break}if(l)continue;a(n,new L(f)),t=t.slice(f.length)}else a(n,new L("\\"+t[1])),t=t.slice(2);continue}if(t.startsWith("_{")){let d="_{",s=T(d,"}",t);if(s.rest.startsWith("^{")){let p=new I(d,"}^{","}");a(n,p);let g=w(s.content,o,r).syntaxTreeRoot.nodes;a(n,g),x(n);let O=T("^{","}",s.rest),K=w(O.content,o,r).syntaxTreeRoot.nodes;a(n,K),n.current=p,t=O.rest;continue}}let v=[["^{",()=>new I("","^{","}")],["_{",()=>new _("","_{","}")]];for(let d of v){let f=d[0];if(t.startsWith(f)){let s=d[1]();j(n,s);let p=T(f,"}",t),g=w(p.content,o,r).syntaxTreeRoot.nodes;a(n,g),n.current=s,t=p.rest,l=!0;break}}l!=!0&&(a(n,new L(t[0])),t=t.slice(1))}return n}var Q=class{constructor(){this.additionalDigits=null;this.decimalSeparator=".";this.preferRoundBracketsNode=!0}};var X=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 be(Me);})();

@@ -822,8 +822,8 @@ // src/GetLatex/getEditModeLatex.ts

}
if (latexParserConfiguration.useRoundBracketsNode && (x[0] == "(" || x.startsWith(String.raw`\left(`))) {
if (latexParserConfiguration.preferRoundBracketsNode && (x[0] == "(" || x.startsWith(String.raw`\left(`))) {
const opening = x[0] == "(" ? "(" : String.raw`\left(`;
const closing = x[0] == "(" ? ")" : String.raw`\right)`;
const bracketsContentAndRest = getBracketPairContent(opening, closing, x);
const bracketsNode = new RoundBracketsNode(opening, closing);
insert(k, bracketsNode);
const bracketsContentAndRest = getBracketPairContent(opening, closing, x);
const bracketsContentNodes = parseLatex(bracketsContentAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;

@@ -837,3 +837,3 @@ insert(k, bracketsContentNodes);

for (const prefix of ["\\left\\", "\\right\\", String.raw`\left`, String.raw`\right`]) {
if (x.startsWith(prefix)) {
if (x.startsWith(prefix) && !isLetter(x.slice(prefix.length)[0])) {
insert(k, new StandardLeafNode(prefix + x[prefix.length]));

@@ -848,29 +848,2 @@ x = x.slice(prefix.length + 1);

}
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 numeratorNodes = parseLatex(numeratorAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
insert(k, numeratorNodes);
moveRight(k);
const denominatorAndRest = getBracketPairContent(openingBracket2, closingBracket2, numeratorAndRest.rest);
const denominatorNodes = parseLatex(denominatorAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
insert(k, denominatorNodes);
k.current = node;
x = denominatorAndRest.rest;
handled = true;
break;
}
}
if (handled) {
continue;
}
const textOpening = String.raw`\text{`;

@@ -894,12 +867,24 @@ if (x.startsWith(textOpening)) {

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);
insert(k, placeholderContent);
k.current = branchingNode;
x = bracketPairContentAndRest.rest;
} else if (character == "{" || character == "[") {
const opening = command + character;
const closingBracket1 = character == "{" ? "}" : "]";
const bracketPair1ContentAndRest = getBracketPairContent(opening, closingBracket1, x);
const placeholder1Nodes = parseLatex(bracketPair1ContentAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
if (bracketPair1ContentAndRest.rest[0] == "{") {
const multiPlaceholderBranchingNode = new DescendingBranchingNode(opening, closingBracket1 + "{", "}");
insert(k, multiPlaceholderBranchingNode);
insert(k, placeholder1Nodes);
moveRight(k);
const bracketPair2ContentAndRest = getBracketPairContent("{", "}", bracketPair1ContentAndRest.rest);
const placeholder2Nodes = parseLatex(bracketPair2ContentAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
insert(k, placeholder2Nodes);
k.current = multiPlaceholderBranchingNode;
x = bracketPair2ContentAndRest.rest;
} else {
const singlePlaceholderBranchingNode = new StandardBranchingNode(opening, closingBracket1);
insert(k, singlePlaceholderBranchingNode);
insert(k, placeholder1Nodes);
k.current = singlePlaceholderBranchingNode;
x = bracketPair1ContentAndRest.rest;
}
handled = true;

@@ -922,2 +907,20 @@ break;

}
if (x.startsWith("_{")) {
const opening = "_{";
const closingBracket1 = "}";
const bracketPair1ContentAndRest = getBracketPairContent(opening, closingBracket1, x);
if (bracketPair1ContentAndRest.rest.startsWith("^{")) {
const ascendingBranchingNode = new AscendingBranchingNode(opening, "}^{", "}");
insert(k, ascendingBranchingNode);
const placeholder1Nodes = parseLatex(bracketPair1ContentAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
insert(k, placeholder1Nodes);
moveRight(k);
const bracketPair2ContentAndRest = getBracketPairContent("^{", "}", bracketPair1ContentAndRest.rest);
const placeholder2Nodes = parseLatex(bracketPair2ContentAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
insert(k, placeholder2Nodes);
k.current = ascendingBranchingNode;
x = bracketPair2ContentAndRest.rest;
continue;
}
}
const various = [

@@ -956,4 +959,3 @@ ["^{", () => new AscendingBranchingNode("", "^{", "}")],

this.decimalSeparator = ".";
this.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets = [];
this.useRoundBracketsNode = true;
this.preferRoundBracketsNode = true;
}

@@ -960,0 +962,0 @@ };

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

function ie(e,o){return e.syntaxTreeRoot.getLatex(e,o)}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 o=e.length-2;o>=0;o--){let r=e[o];if(!T(r))return r=="\\"}return!1}function w(...e){let o="";for(let r=0;r<e.length;r++){let t=e[r];k(o)&&T(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 S=class{constructor(){this.syntaxTreeRoot=new c;this.current=this.syntaxTreeRoot;this.selectionDiff=null;this.inclusiveSelectionRightBorder=null;this.inclusiveSelectionLeftBorder=null}};var le=new S;function ce(e,o){return(e instanceof S?e.syntaxTreeRoot:e).getLatex(le,o)}function ee(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 v(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 L(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 m=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 x(e){return e[e.length-1]}var D=class extends h{};var P=class extends D{};function G(e,o,r){for(let t=e-1;t>=0;t--){let n=o[t];if(n instanceof P)L(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 re(e){var o;if(e.current instanceof c){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?(C(r),e.current=x(r.nodes)):(r.nodes.pop(),e.current=(o=v(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);L(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)se(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 a of i)a.parentPlaceholder=l;l.nodes.splice(N,1,...i),e.current=x(i)}}}}}else if(e.current instanceof m&&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 m&&e.current.placeholders.some(r=>r.nodes.length>0))e.current=x(e.current.placeholders.flatMap(r=>r.nodes)),re(e);else{let r=u(e.current.parentPlaceholder.nodes,e.current);L(e.current.parentPlaceholder.nodes,e.current),e.current=r!=null?r:e.current.parentPlaceholder}}function se(e,o){L(o.parentNode.parentPlaceholder.nodes,e),o.nodes.push(e);let r=e.parentPlaceholder;e.parentPlaceholder=o,e instanceof P&&G(r.nodes.length-1,r.nodes,o)}function O(e,o){let r=e.indexOf(o);return r!=-1&&r<e.length-1?e[r+1]:null}function J(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);L(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)te(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],J(e);return}}}else{let r=O(e.current.parentPlaceholder.nodes,e.current);r!=null&&te(e,r)}}function te(e,o){o instanceof m?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],J(e)):L(o.parentPlaceholder.nodes,o)}function H(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 H(e),[];let o=e.selectionDiff;if(e.current instanceof c)return H(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,H(e),t.splice(n,ae(o))}}function ae(e){return e<0?-e:e}function de(e){_(e)}function b(e){var o;if(e.current instanceof c)if(e.current.nodes.length>0){let r=e.current.nodes[0];e.current=r instanceof m?r.placeholders[0]:r}else{if(e.current.parentNode==null)return;e.current=(o=O(e.current.parentNode.placeholders,e.current))!=null?o:e.current.parentNode}else{let r=O(e.current.parentPlaceholder.nodes,e.current);if(r!=null)e.current=r instanceof m?r.placeholders[0]:r;else{let t=e.current.parentPlaceholder.parentNode;if(t!=null){let n=O(t.placeholders,e.current.parentPlaceholder);e.current=n!=null?n:t}}}}function d(e,o){if(o instanceof Array)for(let r of o)d(e,r),e.current=r;else{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}b(e)}}var y=class extends m{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 W=class extends y{constructor(o=String.raw`\left(`,r=String.raw`\right)`){super(o,r)}};function $(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 h){let i=e.current.parentPlaceholder.nodes,l=i.indexOf(e.current);i[l]=o,o.parentPlaceholder=e.current.parentPlaceholder,e.current instanceof W&&(r!=null&&r.deleteOuterRoundBracketsIfAny)?($(e.current.placeholders[0].nodes,t),e.current=(n=O(o.placeholders,t))!=null?n:o):e.current instanceof P?(t.nodes.push(e.current),e.current.parentPlaceholder=t,G(l,i,t),b(e)):(t.nodes.push(e.current),e.current.parentPlaceholder=t,b(e))}else d(e,o)}function pe(e,o){let r=_(e);if(d(e,o),r.length>0){let t=o.placeholders[0];$(r,t),e.current=x(r),b(e)}}function fe(e,o){var n;if(o.placeholders.length<2)throw"Expected 2 placeholders.";let r=_(e),t=o.placeholders[1];$(r,t),j(e,o),e.current=(n=v(r))!=null?n:t}function me(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=v(n.nodes))!=null?t:n;return}o=r.parentPlaceholder}}function ue(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=v(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 m){let n=x(e.current.placeholders);e.current=(r=v(n.nodes))!=null?r:n}else e.current=(t=u(e.current.parentPlaceholder.nodes,e.current))!=null?t:e.current.parentPlaceholder}function he(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=v(n.nodes))!=null?t:n;return}o=r.parentPlaceholder}}function K(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 ge(e){K(e,0)}function xe(e){return e.selectionDiff!=null}function Pe(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?K(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,K(e,-1))}function ye(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)K(e,o+1);else if(e.inclusiveSelectionRightBorder instanceof h&&x(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,K(e,1)}}var q=class extends y{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 U=class extends y{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 B=class extends D{constructor(r){super();this.latex=typeof r=="string"?()=>r:r}getLatexPart(r,t){return this.latex()}};function R(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.substring(l,l+o.length)==o){if(i==0)return{content:n.slice(0,l),rest:n.slice(l+o.length)};i--;continue}let N=["\\"+t,"\\"+o,String.raw`\left`+t,String.raw`\right`+o],a=n.slice(l);for(let f of N)if(a.length>=f.length&&a.startsWith(f)){l+=f.length;continue}n[l]==t&&i++}throw`A closing ${o} is missing.`}var z=class extends m{constructor(r,t,n){let i=[],l=[];for(let N=0;N<n;N++){let a=[];for(let f=0;f<t;f++){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 A(e,o,r){var i;let t=e==null?void 0:e.trim();if(t==null||t=="")return new S;let n=new S;for(;t!="";){if(t[0]==" "){t=t.trimStart();continue}if(t.startsWith(r.decimalSeparator)){d(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])){d(n,new V(t[0])),t=t.slice(1);continue}let l=!1;if(t.startsWith(String.raw`\begin{`)){let a=R(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 z(a.content,s[0].split("&").length,s.length));for(let g of s)for(let M of g.split("&")){let E=A(M,o,r).syntaxTreeRoot.nodes;d(n,E),b(n)}let p=String.raw`\end{${a.content}}`;t=t.slice(t.indexOf(p)+p.length);continue}if(r.useRoundBracketsNode&&(t[0]=="("||t.startsWith(String.raw`\left(`))){let a=t[0]=="("?"(":String.raw`\left(`,f=t[0]=="("?")":String.raw`\right)`,s=R(a,f,t),p=new W(a,f);d(n,p);let g=A(s.content,o,r).syntaxTreeRoot.nodes;d(n,g),n.current=p,t=s.rest;continue}if(t.startsWith("\\")){for(let s of["\\left\\","\\right\\",String.raw`\left`,String.raw`\right`])if(t.startsWith(s)){d(n,new B(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),g=s.slice(-3,-2),M=s.slice(-2,-1),E=s.slice(-1);if(t.startsWith(p)){let I=R(p,g,t);if(I.rest[0]!=M)continue;let Y=new U(p,g+M,E);d(n,Y);let oe=A(I.content,o,r).syntaxTreeRoot.nodes;d(n,oe),b(n);let Z=R(M,E,I.rest),ne=A(Z.content,o,r).syntaxTreeRoot.nodes;d(n,ne),n.current=Y,t=Z.rest,l=!0;break}}if(l)continue;let a=String.raw`\text{`;if(t.startsWith(a)){let s=R(a,"}",t),p=new y(a,"}");d(n,p);for(let g of s.content)d(n,new B(g));n.current=p,t=s.rest;continue}let f="\\";if(T(t[1])){for(let s=1;s<t.length;s++){let p=t[s];if(T(p))f+=p;else if(p=="{"){f+=p;let g=f,M=R(g,"}",t),E=A(M.content,o,r).syntaxTreeRoot.nodes,I=new y(g,"}");d(n,I),d(n,E),n.current=I,t=M.rest,l=!0;break}else break}if(l)continue;d(n,new B(f)),t=t.slice(f.length)}else d(n,new B("\\"+t[1])),t=t.slice(2);continue}let N=[["^{",()=>new q("","^{","}")],["_{",()=>new U("","_{","}")]];for(let a of N){let f=a[0];if(t.startsWith(f)){let s=a[1]();j(n,s);let p=R(f,"}",t),g=A(p.content,o,r).syntaxTreeRoot.nodes;d(n,g),n.current=s,t=p.rest,l=!0;break}}l!=!0&&(d(n,new B(t[0])),t=t.slice(1))}return n}var Q=class{constructor(){this.additionalDigits=null;this.decimalSeparator=".";this.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets=[];this.useRoundBracketsNode=!0}};var X=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{q as AscendingBranchingNode,m as BranchingNode,F as DecimalSeparatorNode,U as DescendingBranchingNode,V as DigitNode,S as KeyboardMemory,X as LatexConfiguration,Q as LatexParserConfiguration,D as LeafNode,z as MatrixNode,c as Placeholder,W as RoundBracketsNode,y as StandardBranchingNode,B as StandardLeafNode,h as TreeNode,re as deleteLeft,J as deleteRight,de as deleteSelection,ge as enterSelectionMode,ie as getEditModeLatex,ce as getViewModeLatex,xe as inSelectionMode,d as insert,j as insertWithEncapsulateCurrent,pe as insertWithEncapsulateSelection,fe as insertWithEncapsulateSelectionAndPrevious,H as leaveSelectionMode,me as moveDown,ue as moveLeft,b as moveRight,he as moveUp,A as parseLatex,Pe as selectLeft,ye as selectRight};
function ne(e,o){return e.syntaxTreeRoot.getLatex(e,o)}function S(e){return e.toLowerCase()!=e.toUpperCase()}function k(e){if(e.length==0)return!1;if(S(e[e.length-1]))for(let o=e.length-2;o>=0;o--){let r=e[o];if(!S(r))return r=="\\"}return!1}function K(...e){let o="";for(let r=0;r<e.length;r++){let t=e[r];k(o)&&S(t[0])&&(o+=" "),o+=t}return o}var c=class{constructor(){this.parentNode=null;this.nodes=[]}getLatex(o,r){let t=()=>K(...this.nodes.map(n=>n.getLatex(o,r)));return o.inclusiveSelectionLeftBorder===this?K(r.selectionHightlightStart,t()):this===o.current?this.nodes.length==0?r.activePlaceholderLatex:K(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 ie=new L;function le(e,o){return(e instanceof L?e.syntaxTreeRoot:e).getLatex(ie,o)}function ee(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=K(r.selectionHightlightStart,t)),o.inclusiveSelectionRightBorder===this&&(t=K(t,r.selectionHightlightEnd)),t):o.current===this?K(t,r.activePlaceholderLatex):t}};var m=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 x(e){return e[e.length-1]}var W=class extends h{};var P=class extends W{};function G(e,o,r){for(let t=e-1;t>=0;t--){let n=o[t];if(n instanceof P)B(o,n),r.nodes.unshift(n),n.parentPlaceholder=r;else break}}function A(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 re(e){var o;if(e.current instanceof c){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?(A(r),e.current=x(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)ce(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,v=l.nodes.indexOf(e.current.parentNode);for(let a of i)a.parentPlaceholder=l;l.nodes.splice(v,1,...i),e.current=x(i)}}}}}else if(e.current instanceof m&&e.current.placeholders[0].nodes.length>0&&e.current.placeholders.slice(1).every(r=>r.nodes.length==0)){let r=e.current.placeholders[0];A(r),e.current=x(r.nodes)}else if(e.current instanceof m&&e.current.placeholders.some(r=>r.nodes.length>0))e.current=x(e.current.placeholders.flatMap(r=>r.nodes)),re(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 ce(e,o){B(o.parentNode.parentPlaceholder.nodes,e),o.nodes.push(e);let r=e.parentPlaceholder;e.parentPlaceholder=o,e instanceof P&&G(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 J(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)te(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,A(i)}else for(let i=n.indexOf(e.current)+1;i<n.length;i++)if(n[i].nodes.length>0){e.current=n[i],J(e);return}}}else{let r=R(e.current.parentPlaceholder.nodes,e.current);r!=null&&te(e,r)}}function te(e,o){o instanceof m?o.placeholders.length==1&&o.placeholders[0].nodes.length>0?A(o.placeholders[0]):o.placeholders.length==2&&o.placeholders[0].nodes.length==0&&o.placeholders[1].nodes.length>0?A(o.placeholders[1]):(e.current=o.placeholders[0],J(e)):B(o.parentPlaceholder.nodes,o)}function j(e){e.selectionDiff=null,e.inclusiveSelectionRightBorder=null,e.inclusiveSelectionLeftBorder=null}function I(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,se(o))}}function se(e){return e<0?-e:e}function ae(e){I(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 m?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 m?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 d(e,o){if(o instanceof Array)for(let r of o)d(e,r),e.current=r;else{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 N=class extends m{constructor(r,t,...n){let i=n.length+1,l=new Array;for(let v=0;v<i;v++)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 E=class extends N{constructor(o=String.raw`\left(`,r=String.raw`\right)`){super(o,r)}};function _(e,o){for(let r of e)r.parentPlaceholder=o,o.nodes.push(r)}function q(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 E&&(r!=null&&r.deleteOuterRoundBracketsIfAny)?(_(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,G(l,i,t),y(e)):(t.nodes.push(e.current),e.current.parentPlaceholder=t,y(e))}else d(e,o)}function de(e,o){let r=I(e);if(d(e,o),r.length>0){let t=o.placeholders[0];_(r,t),e.current=x(r),y(e)}}function pe(e,o){var n;if(o.placeholders.length<2)throw"Expected 2 placeholders.";let r=I(e),t=o.placeholders[1];_(r,t),q(e,o),e.current=(n=b(r))!=null?n:t}function fe(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 me(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 m){let n=x(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 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.getMoveUpSuggestion(o);if(n!=null){e.current=(t=b(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 he(e){D(e,0)}function ge(e){return e.selectionDiff!=null}function xe(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?D(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,D(e,-1))}function Pe(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)D(e,o+1);else if(e.inclusiveSelectionRightBorder instanceof h&&x(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,D(e,1)}}var $=class extends N{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 U=class extends N{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 W{constructor(r){super();this.latex=typeof r=="string"?()=>r:r}getLatexPart(r,t){return this.latex()}};function T(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.substring(l,l+o.length)==o){if(i==0)return{content:n.slice(0,l),rest:n.slice(l+o.length)};i--;continue}let v=["\\"+t,"\\"+o,String.raw`\left`+t,String.raw`\right`+o],a=n.slice(l);for(let f of v)if(a.length>=f.length&&a.startsWith(f)){l+=f.length;continue}n[l]==t&&i++}throw`A closing ${o} is missing.`}var z=class extends m{constructor(r,t,n){let i=[],l=[];for(let v=0;v<n;v++){let a=[];for(let f=0;f<t;f++){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 C(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)){d(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])){d(n,new V(t[0])),t=t.slice(1);continue}let l=!1;if(t.startsWith(String.raw`\begin{`)){let a=T(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 z(a.content,s[0].split("&").length,s.length));for(let g of s)for(let w of g.split("&")){let O=C(w,o,r).syntaxTreeRoot.nodes;d(n,O),y(n)}let p=String.raw`\end{${a.content}}`;t=t.slice(t.indexOf(p)+p.length);continue}if(r.preferRoundBracketsNode&&(t[0]=="("||t.startsWith(String.raw`\left(`))){let a=t[0]=="("?"(":String.raw`\left(`,f=t[0]=="("?")":String.raw`\right)`,s=new E(a,f);d(n,s);let p=T(a,f,t),g=C(p.content,o,r).syntaxTreeRoot.nodes;d(n,g),n.current=s,t=p.rest;continue}if(t.startsWith("\\")){for(let s of["\\left\\","\\right\\",String.raw`\left`,String.raw`\right`])if(t.startsWith(s)&&!S(t.slice(s.length)[0])){d(n,new M(s+t[s.length])),t=t.slice(s.length+1),l=!0;break}if(l)continue;let a=String.raw`\text{`;if(t.startsWith(a)){let s=T(a,"}",t),p=new N(a,"}");d(n,p);for(let g of s.content)d(n,new M(g));n.current=p,t=s.rest;continue}let f="\\";if(S(t[1])){for(let s=1;s<t.length;s++){let p=t[s];if(S(p))f+=p;else if(p=="{"||p=="["){let g=f+p,w=p=="{"?"}":"]",O=T(g,w,t),Y=C(O.content,o,r).syntaxTreeRoot.nodes;if(O.rest[0]=="{"){let H=new U(g,w+"{","}");d(n,H),d(n,Y),y(n);let Z=T("{","}",O.rest),oe=C(Z.content,o,r).syntaxTreeRoot.nodes;d(n,oe),n.current=H,t=Z.rest}else{let H=new N(g,w);d(n,H),d(n,Y),n.current=H,t=O.rest}l=!0;break}else break}if(l)continue;d(n,new M(f)),t=t.slice(f.length)}else d(n,new M("\\"+t[1])),t=t.slice(2);continue}if(t.startsWith("_{")){let a="_{",s=T(a,"}",t);if(s.rest.startsWith("^{")){let p=new $(a,"}^{","}");d(n,p);let g=C(s.content,o,r).syntaxTreeRoot.nodes;d(n,g),y(n);let w=T("^{","}",s.rest),O=C(w.content,o,r).syntaxTreeRoot.nodes;d(n,O),n.current=p,t=w.rest;continue}}let v=[["^{",()=>new $("","^{","}")],["_{",()=>new U("","_{","}")]];for(let a of v){let f=a[0];if(t.startsWith(f)){let s=a[1]();q(n,s);let p=T(f,"}",t),g=C(p.content,o,r).syntaxTreeRoot.nodes;d(n,g),n.current=s,t=p.rest,l=!0;break}}l!=!0&&(d(n,new M(t[0])),t=t.slice(1))}return n}var Q=class{constructor(){this.additionalDigits=null;this.decimalSeparator=".";this.preferRoundBracketsNode=!0}};var X=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{$ as AscendingBranchingNode,m as BranchingNode,F as DecimalSeparatorNode,U as DescendingBranchingNode,V as DigitNode,L as KeyboardMemory,X as LatexConfiguration,Q as LatexParserConfiguration,W as LeafNode,z as MatrixNode,c as Placeholder,E as RoundBracketsNode,N as StandardBranchingNode,M as StandardLeafNode,h as TreeNode,re as deleteLeft,J as deleteRight,ae as deleteSelection,he as enterSelectionMode,ne as getEditModeLatex,le as getViewModeLatex,ge as inSelectionMode,d as insert,q as insertWithEncapsulateCurrent,de as insertWithEncapsulateSelection,pe as insertWithEncapsulateSelectionAndPrevious,j as leaveSelectionMode,fe as moveDown,me as moveLeft,y as moveRight,ue as moveUp,C as parseLatex,xe as selectLeft,Pe as selectRight};

@@ -810,8 +810,8 @@ // src/GetLatex/getEditModeLatex.ts

}
if (latexParserConfiguration.useRoundBracketsNode && (x[0] == "(" || x.startsWith(String.raw`\left(`))) {
if (latexParserConfiguration.preferRoundBracketsNode && (x[0] == "(" || x.startsWith(String.raw`\left(`))) {
const opening = x[0] == "(" ? "(" : String.raw`\left(`;
const closing = x[0] == "(" ? ")" : String.raw`\right)`;
const bracketsContentAndRest = getBracketPairContent(opening, closing, x);
const bracketsNode = new RoundBracketsNode(opening, closing);
insert(k, bracketsNode);
const bracketsContentAndRest = getBracketPairContent(opening, closing, x);
const bracketsContentNodes = parseLatex(bracketsContentAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;

@@ -825,3 +825,3 @@ insert(k, bracketsContentNodes);

for (const prefix of ["\\left\\", "\\right\\", String.raw`\left`, String.raw`\right`]) {
if (x.startsWith(prefix)) {
if (x.startsWith(prefix) && !isLetter(x.slice(prefix.length)[0])) {
insert(k, new StandardLeafNode(prefix + x[prefix.length]));

@@ -836,29 +836,2 @@ x = x.slice(prefix.length + 1);

}
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 numeratorNodes = parseLatex(numeratorAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
insert(k, numeratorNodes);
moveRight(k);
const denominatorAndRest = getBracketPairContent(openingBracket2, closingBracket2, numeratorAndRest.rest);
const denominatorNodes = parseLatex(denominatorAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
insert(k, denominatorNodes);
k.current = node;
x = denominatorAndRest.rest;
handled = true;
break;
}
}
if (handled) {
continue;
}
const textOpening = String.raw`\text{`;

@@ -882,12 +855,24 @@ if (x.startsWith(textOpening)) {

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);
insert(k, placeholderContent);
k.current = branchingNode;
x = bracketPairContentAndRest.rest;
} else if (character == "{" || character == "[") {
const opening = command + character;
const closingBracket1 = character == "{" ? "}" : "]";
const bracketPair1ContentAndRest = getBracketPairContent(opening, closingBracket1, x);
const placeholder1Nodes = parseLatex(bracketPair1ContentAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
if (bracketPair1ContentAndRest.rest[0] == "{") {
const multiPlaceholderBranchingNode = new DescendingBranchingNode(opening, closingBracket1 + "{", "}");
insert(k, multiPlaceholderBranchingNode);
insert(k, placeholder1Nodes);
moveRight(k);
const bracketPair2ContentAndRest = getBracketPairContent("{", "}", bracketPair1ContentAndRest.rest);
const placeholder2Nodes = parseLatex(bracketPair2ContentAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
insert(k, placeholder2Nodes);
k.current = multiPlaceholderBranchingNode;
x = bracketPair2ContentAndRest.rest;
} else {
const singlePlaceholderBranchingNode = new StandardBranchingNode(opening, closingBracket1);
insert(k, singlePlaceholderBranchingNode);
insert(k, placeholder1Nodes);
k.current = singlePlaceholderBranchingNode;
x = bracketPair1ContentAndRest.rest;
}
handled = true;

@@ -910,2 +895,20 @@ break;

}
if (x.startsWith("_{")) {
const opening = "_{";
const closingBracket1 = "}";
const bracketPair1ContentAndRest = getBracketPairContent(opening, closingBracket1, x);
if (bracketPair1ContentAndRest.rest.startsWith("^{")) {
const ascendingBranchingNode = new AscendingBranchingNode(opening, "}^{", "}");
insert(k, ascendingBranchingNode);
const placeholder1Nodes = parseLatex(bracketPair1ContentAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
insert(k, placeholder1Nodes);
moveRight(k);
const bracketPair2ContentAndRest = getBracketPairContent("^{", "}", bracketPair1ContentAndRest.rest);
const placeholder2Nodes = parseLatex(bracketPair2ContentAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
insert(k, placeholder2Nodes);
k.current = ascendingBranchingNode;
x = bracketPair2ContentAndRest.rest;
continue;
}
}
const various = [

@@ -944,4 +947,3 @@ ["^{", () => new AscendingBranchingNode("", "^{", "}")],

this.decimalSeparator = ".";
this.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets = [];
this.useRoundBracketsNode = true;
this.preferRoundBracketsNode = true;
}

@@ -948,0 +950,0 @@ };

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

function ne(e,r){return e.syntaxTreeRoot.getLatex(e,r)}function M(e){return e.toLowerCase()!=e.toUpperCase()}function Z(e){if(e.length==0)return!1;if(M(e[e.length-1]))for(let r=e.length-2;r>=0;r--){let t=e[r];if(!M(t))return t=="\\"}return!1}function T(...e){let r="";for(let t=0;t<e.length;t++){let o=e[t];Z(r)&&M(o[0])&&(r+=" "),r+=o}return r}var c=class{constructor(){this.parentNode=null;this.nodes=[]}getLatex(r,t){let o=()=>T(...this.nodes.map(n=>n.getLatex(r,t)));return r.inclusiveSelectionLeftBorder===this?T(t.selectionHightlightStart,o()):this===r.current?this.nodes.length==0?t.activePlaceholderLatex:T(t.activePlaceholderLatex,o()):this.nodes.length==0?t.passivePlaceholderLatex:o()}};var b=class{constructor(){this.syntaxTreeRoot=new c;this.current=this.syntaxTreeRoot;this.selectionDiff=null;this.inclusiveSelectionRightBorder=null;this.inclusiveSelectionLeftBorder=null}};var ie=new b;function le(e,r){return(e instanceof b?e.syntaxTreeRoot:e).getLatex(ie,r)}function k(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 N(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 S(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=T(t.selectionHightlightStart,o)),r.inclusiveSelectionRightBorder===this&&(o=T(o,t.selectionHightlightEnd)),o):r.current===this?T(o,t.activePlaceholderLatex):o}};var m=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 x(e){return e[e.length-1]}var R=class extends h{};var P=class extends R{};function z(e,r,t){for(let o=e-1;o>=0;o--){let n=r[o];if(n instanceof P)S(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 ee(e){if(e.current instanceof c){if(e.current.parentNode==null||e.current.nodes.length>0)return;{let r=k(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=x(r.nodes)):(r.nodes.pop(),e.current=N(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);S(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)ce(t,e.current),e.current=x(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,p=i.nodes.indexOf(e.current.parentNode);for(let s of n)s.parentPlaceholder=i;i.nodes.splice(p,1,...n),e.current=x(n)}}}}}else if(e.current instanceof m&&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=x(r.nodes)}else if(e.current instanceof m&&e.current.placeholders.some(r=>r.nodes.length>0))e.current=x(e.current.placeholders.flatMap(r=>r.nodes)),ee(e);else{let r=u(e.current.parentPlaceholder.nodes,e.current);S(e.current.parentPlaceholder.nodes,e.current),e.current=r??e.current.parentPlaceholder}}function ce(e,r){S(r.parentNode.parentPlaceholder.nodes,e),r.nodes.push(e);let t=e.parentPlaceholder;e.parentPlaceholder=r,e instanceof P&&z(t.nodes.length-1,t.nodes,r)}function O(e,r){let t=e.indexOf(r);return t!=-1&&t<e.length-1?e[t+1]:null}function G(e){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);S(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)re(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],G(e);return}}}else{let r=O(e.current.parentPlaceholder.nodes,e.current);r!=null&&re(e,r)}}function re(e,r){r instanceof m?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],G(e)):S(r.parentPlaceholder.nodes,r)}function U(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 U(e),[];let r=e.selectionDiff;if(e.current instanceof c)return U(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,U(e),t.splice(o,se(r))}}function se(e){return e<0?-e:e}function ae(e){I(e)}function v(e){if(e.current instanceof c)if(e.current.nodes.length>0){let r=e.current.nodes[0];e.current=r instanceof m?r.placeholders[0]:r}else{if(e.current.parentNode==null)return;e.current=O(e.current.parentNode.placeholders,e.current)??e.current.parentNode}else{let r=O(e.current.parentPlaceholder.nodes,e.current);if(r!=null)e.current=r instanceof m?r.placeholders[0]:r;else{let t=e.current.parentPlaceholder.parentNode;if(t!=null){let o=O(t.placeholders,e.current.parentPlaceholder);e.current=o??t}}}}function a(e,r){if(r instanceof Array)for(let t of r)a(e,t),e.current=t;else{if(e.current instanceof c)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}v(e)}}var y=class extends m{constructor(t,o,...n){let i=n.length+1,p=new Array;for(let s=0;s<i;s++)p.push(new c);super(p);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 C=class extends y{constructor(r=String.raw`\left(`,t=String.raw`\right)`){super(r,t)}};function _(e,r){for(let t of e)t.parentPlaceholder=r,r.nodes.push(t)}function H(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 C&&t?.deleteOuterRoundBracketsIfAny?(_(e.current.placeholders[0].nodes,o),e.current=O(r.placeholders,o)??r):e.current instanceof P?(o.nodes.push(e.current),e.current.parentPlaceholder=o,z(i,n,o),v(e)):(o.nodes.push(e.current),e.current.parentPlaceholder=o,v(e))}else a(e,r)}function de(e,r){let t=I(e);if(a(e,r),t.length>0){let o=r.placeholders[0];_(t,o),e.current=x(t),v(e)}}function pe(e,r){if(r.placeholders.length<2)throw"Expected 2 placeholders.";let t=I(e),o=r.placeholders[1];_(t,o),H(e,r),e.current=N(t)??o}function fe(e){let r=e.current instanceof c?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=N(o.nodes)??o;return}r=t.parentPlaceholder}}function me(e){if(e.current instanceof c){if(e.current.parentNode==null)return;let r=u(e.current.parentNode.placeholders,e.current);if(r!==null)e.current=N(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 m){let r=x(e.current.placeholders);e.current=N(r.nodes)??r}else e.current=u(e.current.parentPlaceholder.nodes,e.current)??e.current.parentPlaceholder}function ue(e){let r=e.current instanceof c?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=N(o.nodes)??o;return}r=t.parentPlaceholder}}function w(e,r){if(e.selectionDiff=r,r==0)e.inclusiveSelectionLeftBorder=null,e.inclusiveSelectionRightBorder=null;else if(e.current instanceof c)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 he(e){w(e,0)}function ge(e){return e.selectionDiff!=null}function xe(e){let r=e.selectionDiff??0;e.current instanceof h&&e.current.parentPlaceholder.nodes.indexOf(e.current)+r>=0||e.current instanceof c&&r>0?w(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,w(e,-1))}function Pe(e){let r=e.selectionDiff??0;if(e.current instanceof c&&r<e.current.nodes.length||e.current instanceof h&&e.current.parentPlaceholder.nodes.indexOf(e.current)+r<e.current.parentPlaceholder.nodes.length-1)w(e,r+1);else if(e.inclusiveSelectionRightBorder instanceof h&&x(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,w(e,1)}}var j=class extends y{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 q=class extends P{constructor(t="."){super();this.latex=typeof t=="string"?()=>t:t}getLatexPart(t,o){return this.latex()}};var $=class extends y{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 F=class extends P{constructor(t){super();this.latex=t}getLatexPart(t,o){return this.latex}};var L=class extends R{constructor(t){super();this.latex=typeof t=="string"?()=>t:t}getLatexPart(t,o){return this.latex()}};function K(e,r,t){let o=e.slice(-1),n=t.slice(e.length),i=0;for(let p=0;p<n.length;p++){if(n.substring(p,p+r.length)==r){if(i==0)return{content:n.slice(0,p),rest:n.slice(p+r.length)};i--;continue}let s=["\\"+o,"\\"+r,String.raw`\left`+o,String.raw`\right`+r],f=n.slice(p);for(let l of s)if(f.length>=l.length&&f.startsWith(l)){p+=l.length;continue}n[p]==o&&i++}throw`A closing ${r} is missing.`}var V=class extends m{constructor(t,o,n){let i=[],p=[];for(let s=0;s<n;s++){let f=[];for(let l=0;l<o;l++){let d=new c;f.push(d),p.push(d)}i.push(f)}super(p);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(p=>p.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 W(e,r,t){let o=e?.trim();if(o==null||o=="")return new b;let n=new b;for(;o!="";){if(o[0]==" "){o=o.trimStart();continue}if(o.startsWith(t.decimalSeparator)){a(n,new q(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 F(o[0])),o=o.slice(1);continue}let i=!1;if(o.startsWith(String.raw`\begin{`)){let s=K(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 l=s.rest.slice(0,s.rest.indexOf(String.raw`\end{${s.content}}`)).split(String.raw`\\`);a(n,new V(s.content,l[0].split("&").length,l.length));for(let g of l)for(let B of g.split("&")){let A=W(B,r,t).syntaxTreeRoot.nodes;a(n,A),v(n)}let d=String.raw`\end{${s.content}}`;o=o.slice(o.indexOf(d)+d.length);continue}if(t.useRoundBracketsNode&&(o[0]=="("||o.startsWith(String.raw`\left(`))){let s=o[0]=="("?"(":String.raw`\left(`,f=o[0]=="("?")":String.raw`\right)`,l=K(s,f,o),d=new C(s,f);a(n,d);let g=W(l.content,r,t).syntaxTreeRoot.nodes;a(n,g),n.current=d,o=l.rest;continue}if(o.startsWith("\\")){for(let l of["\\left\\","\\right\\",String.raw`\left`,String.raw`\right`])if(o.startsWith(l)){a(n,new L(l+o[l.length])),o=o.slice(l.length+1),i=!0;break}if(i)continue;for(let l of t.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets){let d=l.slice(0,-3),g=l.slice(-3,-2),B=l.slice(-2,-1),A=l.slice(-1);if(o.startsWith(d)){let E=K(d,g,o);if(E.rest[0]!=B)continue;let X=new $(d,g+B,A);a(n,X);let te=W(E.content,r,t).syntaxTreeRoot.nodes;a(n,te),v(n);let Y=K(B,A,E.rest),oe=W(Y.content,r,t).syntaxTreeRoot.nodes;a(n,oe),n.current=X,o=Y.rest,i=!0;break}}if(i)continue;let s=String.raw`\text{`;if(o.startsWith(s)){let l=K(s,"}",o),d=new y(s,"}");a(n,d);for(let g of l.content)a(n,new L(g));n.current=d,o=l.rest;continue}let f="\\";if(M(o[1])){for(let l=1;l<o.length;l++){let d=o[l];if(M(d))f+=d;else if(d=="{"){f+=d;let g=f,B=K(g,"}",o),A=W(B.content,r,t).syntaxTreeRoot.nodes,E=new y(g,"}");a(n,E),a(n,A),n.current=E,o=B.rest,i=!0;break}else break}if(i)continue;a(n,new L(f)),o=o.slice(f.length)}else a(n,new L("\\"+o[1])),o=o.slice(2);continue}let p=[["^{",()=>new j("","^{","}")],["_{",()=>new $("","_{","}")]];for(let s of p){let f=s[0];if(o.startsWith(f)){let l=s[1]();H(n,l);let d=K(f,"}",o),g=W(d.content,r,t).syntaxTreeRoot.nodes;a(n,g),n.current=l,o=d.rest,i=!0;break}}i!=!0&&(a(n,new L(o[0])),o=o.slice(1))}return n}var J=class{constructor(){this.additionalDigits=null;this.decimalSeparator=".";this.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets=[];this.useRoundBracketsNode=!0}};var Q=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{j as AscendingBranchingNode,m as BranchingNode,q as DecimalSeparatorNode,$ as DescendingBranchingNode,F as DigitNode,b as KeyboardMemory,Q as LatexConfiguration,J as LatexParserConfiguration,R as LeafNode,V as MatrixNode,c as Placeholder,C as RoundBracketsNode,y as StandardBranchingNode,L as StandardLeafNode,h as TreeNode,ee as deleteLeft,G as deleteRight,ae as deleteSelection,he as enterSelectionMode,ne as getEditModeLatex,le as getViewModeLatex,ge as inSelectionMode,a as insert,H as insertWithEncapsulateCurrent,de as insertWithEncapsulateSelection,pe as insertWithEncapsulateSelectionAndPrevious,U as leaveSelectionMode,fe as moveDown,me as moveLeft,v as moveRight,ue as moveUp,W as parseLatex,xe as selectLeft,Pe as selectRight};
function oe(e,r){return e.syntaxTreeRoot.getLatex(e,r)}function b(e){return e.toLowerCase()!=e.toUpperCase()}function Z(e){if(e.length==0)return!1;if(b(e[e.length-1]))for(let r=e.length-2;r>=0;r--){let t=e[r];if(!b(t))return t=="\\"}return!1}function w(...e){let r="";for(let t=0;t<e.length;t++){let o=e[t];Z(r)&&b(o[0])&&(r+=" "),r+=o}return r}var c=class{constructor(){this.parentNode=null;this.nodes=[]}getLatex(r,t){let o=()=>w(...this.nodes.map(n=>n.getLatex(r,t)));return r.inclusiveSelectionLeftBorder===this?w(t.selectionHightlightStart,o()):this===r.current?this.nodes.length==0?t.activePlaceholderLatex:w(t.activePlaceholderLatex,o()):this.nodes.length==0?t.passivePlaceholderLatex:o()}};var S=class{constructor(){this.syntaxTreeRoot=new c;this.current=this.syntaxTreeRoot;this.selectionDiff=null;this.inclusiveSelectionRightBorder=null;this.inclusiveSelectionLeftBorder=null}};var ne=new S;function ie(e,r){return(e instanceof S?e.syntaxTreeRoot:e).getLatex(ne,r)}function k(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 L(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=w(t.selectionHightlightStart,o)),r.inclusiveSelectionRightBorder===this&&(o=w(o,t.selectionHightlightEnd)),o):r.current===this?w(o,t.activePlaceholderLatex):o}};var m=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 x(e){return e[e.length-1]}var C=class extends h{};var P=class extends C{};function z(e,r,t){for(let o=e-1;o>=0;o--){let n=r[o];if(n instanceof P)L(r,n),t.nodes.unshift(n),n.parentPlaceholder=t;else break}}function W(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 ee(e){if(e.current instanceof c){if(e.current.parentNode==null||e.current.nodes.length>0)return;{let r=k(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?(W(r),e.current=x(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);L(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)le(t,e.current),e.current=x(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,l=e.current.parentNode.parentPlaceholder,p=l.nodes.indexOf(e.current.parentNode);for(let s of n)s.parentPlaceholder=l;l.nodes.splice(p,1,...n),e.current=x(n)}}}}}else if(e.current instanceof m&&e.current.placeholders[0].nodes.length>0&&e.current.placeholders.slice(1).every(r=>r.nodes.length==0)){let r=e.current.placeholders[0];W(r),e.current=x(r.nodes)}else if(e.current instanceof m&&e.current.placeholders.some(r=>r.nodes.length>0))e.current=x(e.current.placeholders.flatMap(r=>r.nodes)),ee(e);else{let r=u(e.current.parentPlaceholder.nodes,e.current);L(e.current.parentPlaceholder.nodes,e.current),e.current=r??e.current.parentPlaceholder}}function le(e,r){L(r.parentNode.parentPlaceholder.nodes,e),r.nodes.push(e);let t=e.parentPlaceholder;e.parentPlaceholder=r,e instanceof P&&z(t.nodes.length-1,t.nodes,r)}function K(e,r){let t=e.indexOf(r);return t!=-1&&t<e.length-1?e[t+1]:null}function G(e){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);L(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)re(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,W(n)}else for(let n=o.indexOf(e.current)+1;n<o.length;n++)if(o[n].nodes.length>0){e.current=o[n],G(e);return}}}else{let r=K(e.current.parentPlaceholder.nodes,e.current);r!=null&&re(e,r)}}function re(e,r){r instanceof m?r.placeholders.length==1&&r.placeholders[0].nodes.length>0?W(r.placeholders[0]):r.placeholders.length==2&&r.placeholders[0].nodes.length==0&&r.placeholders[1].nodes.length>0?W(r.placeholders[1]):(e.current=r.placeholders[0],G(e)):L(r.parentPlaceholder.nodes,r)}function H(e){e.selectionDiff=null,e.inclusiveSelectionRightBorder=null,e.inclusiveSelectionLeftBorder=null}function E(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 c)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,ce(r))}}function ce(e){return e<0?-e:e}function se(e){E(e)}function N(e){if(e.current instanceof c)if(e.current.nodes.length>0){let r=e.current.nodes[0];e.current=r instanceof m?r.placeholders[0]:r}else{if(e.current.parentNode==null)return;e.current=K(e.current.parentNode.placeholders,e.current)??e.current.parentNode}else{let r=K(e.current.parentPlaceholder.nodes,e.current);if(r!=null)e.current=r instanceof m?r.placeholders[0]:r;else{let t=e.current.parentPlaceholder.parentNode;if(t!=null){let o=K(t.placeholders,e.current.parentPlaceholder);e.current=o??t}}}}function a(e,r){if(r instanceof Array)for(let t of r)a(e,t),e.current=t;else{if(e.current instanceof c)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}N(e)}}var y=class extends m{constructor(t,o,...n){let l=n.length+1,p=new Array;for(let s=0;s<l;s++)p.push(new c);super(p);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 l=0;l<this.rest.length;l++)n+=this.placeholders[l+1].getLatex(t,o)+this.rest[l];return n}};var A=class extends y{constructor(r=String.raw`\left(`,t=String.raw`\right)`){super(r,t)}};function I(e,r){for(let t of e)t.parentPlaceholder=r,r.nodes.push(t)}function j(e,r,t){let o=r.placeholders[0];if(e.current instanceof h){let n=e.current.parentPlaceholder.nodes,l=n.indexOf(e.current);n[l]=r,r.parentPlaceholder=e.current.parentPlaceholder,e.current instanceof A&&t?.deleteOuterRoundBracketsIfAny?(I(e.current.placeholders[0].nodes,o),e.current=K(r.placeholders,o)??r):e.current instanceof P?(o.nodes.push(e.current),e.current.parentPlaceholder=o,z(l,n,o),N(e)):(o.nodes.push(e.current),e.current.parentPlaceholder=o,N(e))}else a(e,r)}function ae(e,r){let t=E(e);if(a(e,r),t.length>0){let o=r.placeholders[0];I(t,o),e.current=x(t),N(e)}}function de(e,r){if(r.placeholders.length<2)throw"Expected 2 placeholders.";let t=E(e),o=r.placeholders[1];I(t,o),j(e,r),e.current=v(t)??o}function pe(e){let r=e.current instanceof c?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 fe(e){if(e.current instanceof c){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 m){let r=x(e.current.placeholders);e.current=v(r.nodes)??r}else e.current=u(e.current.parentPlaceholder.nodes,e.current)??e.current.parentPlaceholder}function me(e){let r=e.current instanceof c?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 R(e,r){if(e.selectionDiff=r,r==0)e.inclusiveSelectionLeftBorder=null,e.inclusiveSelectionRightBorder=null;else if(e.current instanceof c)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 ue(e){R(e,0)}function he(e){return e.selectionDiff!=null}function ge(e){let r=e.selectionDiff??0;e.current instanceof h&&e.current.parentPlaceholder.nodes.indexOf(e.current)+r>=0||e.current instanceof c&&r>0?R(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,R(e,-1))}function xe(e){let r=e.selectionDiff??0;if(e.current instanceof c&&r<e.current.nodes.length||e.current instanceof h&&e.current.parentPlaceholder.nodes.indexOf(e.current)+r<e.current.parentPlaceholder.nodes.length-1)R(e,r+1);else if(e.inclusiveSelectionRightBorder instanceof h&&x(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,R(e,1)}}var _=class extends y{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 q=class extends P{constructor(t="."){super();this.latex=typeof t=="string"?()=>t:t}getLatexPart(t,o){return this.latex()}};var $=class extends y{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 F=class extends P{constructor(t){super();this.latex=t}getLatexPart(t,o){return this.latex}};var B=class extends C{constructor(t){super();this.latex=typeof t=="string"?()=>t:t}getLatexPart(t,o){return this.latex()}};function M(e,r,t){let o=e.slice(-1),n=t.slice(e.length),l=0;for(let p=0;p<n.length;p++){if(n.substring(p,p+r.length)==r){if(l==0)return{content:n.slice(0,p),rest:n.slice(p+r.length)};l--;continue}let s=["\\"+o,"\\"+r,String.raw`\left`+o,String.raw`\right`+r],f=n.slice(p);for(let i of s)if(f.length>=i.length&&f.startsWith(i)){p+=i.length;continue}n[p]==o&&l++}throw`A closing ${r} is missing.`}var V=class extends m{constructor(t,o,n){let l=[],p=[];for(let s=0;s<n;s++){let f=[];for(let i=0;i<o;i++){let d=new c;f.push(d),p.push(d)}l.push(f)}super(p);this.grid=l,this.matrixType=t,this.width=o}getLatexPart(t,o){let n=String.raw`\begin{${this.matrixType}}`;return n+=this.grid.map(l=>l.map(p=>p.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),l=o-n*this.width;return{rowIndex:n,columnIndex:l}}};function D(e,r,t){let o=e?.trim();if(o==null||o=="")return new S;let n=new S;for(;o!="";){if(o[0]==" "){o=o.trimStart();continue}if(o.startsWith(t.decimalSeparator)){a(n,new q(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 F(o[0])),o=o.slice(1);continue}let l=!1;if(o.startsWith(String.raw`\begin{`)){let s=M(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 i=s.rest.slice(0,s.rest.indexOf(String.raw`\end{${s.content}}`)).split(String.raw`\\`);a(n,new V(s.content,i[0].split("&").length,i.length));for(let g of i)for(let T of g.split("&")){let O=D(T,r,t).syntaxTreeRoot.nodes;a(n,O),N(n)}let d=String.raw`\end{${s.content}}`;o=o.slice(o.indexOf(d)+d.length);continue}if(t.preferRoundBracketsNode&&(o[0]=="("||o.startsWith(String.raw`\left(`))){let s=o[0]=="("?"(":String.raw`\left(`,f=o[0]=="("?")":String.raw`\right)`,i=new A(s,f);a(n,i);let d=M(s,f,o),g=D(d.content,r,t).syntaxTreeRoot.nodes;a(n,g),n.current=i,o=d.rest;continue}if(o.startsWith("\\")){for(let i of["\\left\\","\\right\\",String.raw`\left`,String.raw`\right`])if(o.startsWith(i)&&!b(o.slice(i.length)[0])){a(n,new B(i+o[i.length])),o=o.slice(i.length+1),l=!0;break}if(l)continue;let s=String.raw`\text{`;if(o.startsWith(s)){let i=M(s,"}",o),d=new y(s,"}");a(n,d);for(let g of i.content)a(n,new B(g));n.current=d,o=i.rest;continue}let f="\\";if(b(o[1])){for(let i=1;i<o.length;i++){let d=o[i];if(b(d))f+=d;else if(d=="{"||d=="["){let g=f+d,T=d=="{"?"}":"]",O=M(g,T,o),X=D(O.content,r,t).syntaxTreeRoot.nodes;if(O.rest[0]=="{"){let U=new $(g,T+"{","}");a(n,U),a(n,X),N(n);let Y=M("{","}",O.rest),te=D(Y.content,r,t).syntaxTreeRoot.nodes;a(n,te),n.current=U,o=Y.rest}else{let U=new y(g,T);a(n,U),a(n,X),n.current=U,o=O.rest}l=!0;break}else break}if(l)continue;a(n,new B(f)),o=o.slice(f.length)}else a(n,new B("\\"+o[1])),o=o.slice(2);continue}if(o.startsWith("_{")){let s="_{",i=M(s,"}",o);if(i.rest.startsWith("^{")){let d=new _(s,"}^{","}");a(n,d);let g=D(i.content,r,t).syntaxTreeRoot.nodes;a(n,g),N(n);let T=M("^{","}",i.rest),O=D(T.content,r,t).syntaxTreeRoot.nodes;a(n,O),n.current=d,o=T.rest;continue}}let p=[["^{",()=>new _("","^{","}")],["_{",()=>new $("","_{","}")]];for(let s of p){let f=s[0];if(o.startsWith(f)){let i=s[1]();j(n,i);let d=M(f,"}",o),g=D(d.content,r,t).syntaxTreeRoot.nodes;a(n,g),n.current=i,o=d.rest,l=!0;break}}l!=!0&&(a(n,new B(o[0])),o=o.slice(1))}return n}var J=class{constructor(){this.additionalDigits=null;this.decimalSeparator=".";this.preferRoundBracketsNode=!0}};var Q=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{_ as AscendingBranchingNode,m as BranchingNode,q as DecimalSeparatorNode,$ as DescendingBranchingNode,F as DigitNode,S as KeyboardMemory,Q as LatexConfiguration,J as LatexParserConfiguration,C as LeafNode,V as MatrixNode,c as Placeholder,A as RoundBracketsNode,y as StandardBranchingNode,B as StandardLeafNode,h as TreeNode,ee as deleteLeft,G as deleteRight,se as deleteSelection,ue as enterSelectionMode,oe as getEditModeLatex,ie as getViewModeLatex,he as inSelectionMode,a as insert,j as insertWithEncapsulateCurrent,ae as insertWithEncapsulateSelection,de as insertWithEncapsulateSelectionAndPrevious,H as leaveSelectionMode,pe as moveDown,fe as moveLeft,N as moveRight,me as moveUp,D as parseLatex,ge as selectLeft,xe as selectRight};

@@ -21,3 +21,3 @@ {

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

@@ -24,0 +24,0 @@ "exports": {

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