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

73

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;
export declare function getViewModeLatex(x: TreeNode | Placeholder | KeyboardMemory, latexConfiguration: LatexConfiguration): string;
export declare function firstAfterOrNull<T>(array: T[], element: T): T | null;
export declare function 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 isLetter(c: string): boolean;
export declare function lastOrNull<T>(array: T[]): T | null;
export declare function remove<T>(array: T[], element: T): void;
export declare function deleteRight(k: KeyboardMemory): 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 remove<T>(array: T[], element: T): void;
export declare function deleteLeft(k: KeyboardMemory): void;
export declare function deleteRight(k: KeyboardMemory): void;
export declare function deleteSelection(k: KeyboardMemory): void;
export declare function encapsulate(nodes: TreeNode[], encapsulatingPlaceholder: Placeholder): void;
export declare function deleteOuterBranchingNodeButNotItsContents(nonEmptyPlaceholder: Placeholder): void;
export declare function encapsulate(nodes: TreeNode[], encapsulatingPlaceholder: Placeholder): void;
export declare function encapsulateAllPartsOfNumberWithDigitsLeftOfIndex(exclusiveRightIndex: number, siblingNodes: TreeNode[], toPlaceholder: Placeholder): void;
export declare function getFirstNonEmptyOnLeftOf(placeholderArray: Placeholder[], element: Placeholder): Placeholder | null;
export declare function insert(k: KeyboardMemory, toInsert: TreeNode | TreeNode[]): void;
export declare function getFirstNonEmptyOnLeftOf(placeholderArray: Placeholder[], element: Placeholder): Placeholder | null;
export declare function insertWithEncapsulateCurrent(k: KeyboardMemory, newNode: BranchingNode, config?: {

@@ -43,14 +43,12 @@ deleteOuterRoundBracketsIfAny?: boolean;

export declare function insertWithEncapsulateSelectionAndPrevious(k: KeyboardMemory, newNode: BranchingNode): void;
export declare function moveLeft(k: KeyboardMemory): void;
export declare function moveDown(k: KeyboardMemory): void;
export declare function moveRight(k: KeyboardMemory): void;
export declare function moveDown(k: KeyboardMemory): void;
export declare function moveUp(k: KeyboardMemory): void;
export declare function enterSelectionMode(k: KeyboardMemory): void;
export declare function moveUp(k: KeyboardMemory): void;
export declare function popSelection(k: KeyboardMemory): TreeNode[];

@@ -60,2 +58,4 @@

export declare function insertWithEncapsulateSelectionAndPrevious(k: KeyboardMemory, newNode: BranchingNode): void;
export declare function inSelectionMode(k: KeyboardMemory): boolean;

@@ -88,8 +88,2 @@

export declare class LatexParserConfiguration {
additionalDigits: string[] | null;
decimalSeparator: string;
descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets: string[];
}
type BracePairContent = {

@@ -99,3 +93,3 @@ content: string;

};
export declare function getBracketPairContent(opening: string, closingBracket: string, sWithOpening: string): BracePairContent;
export declare function getBracketPairContent(opening: string, closing: string, sWithOpening: string): BracePairContent;
export {};

@@ -112,3 +106,7 @@

export declare abstract class LeafNode extends TreeNode {
export declare class LatexParserConfiguration {
additionalDigits: string[] | null;
decimalSeparator: string;
descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets: string[];
useRoundBracketsNode: boolean;
}

@@ -122,2 +120,5 @@

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

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

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

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

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

@@ -158,5 +159,2 @@ private readonly before;

export declare abstract class PartOfNumberWithDigits extends LeafNode {
}
export declare class DecimalSeparatorNode extends PartOfNumberWithDigits {

@@ -174,2 +172,8 @@ private readonly latex;

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

@@ -181,7 +185,4 @@ private readonly latex;

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

@@ -758,3 +758,3 @@ "use strict";

// src/LatexParser/helpers/getBracketPairContent.ts
function getBracketPairContent(opening, closingBracket, sWithOpening) {
function getBracketPairContent(opening, closing, sWithOpening) {
const openingBracket = opening.slice(-1);

@@ -764,5 +764,5 @@ const s = sWithOpening.slice(opening.length);

for (let closingBracketIndex = 0; closingBracketIndex < s.length; closingBracketIndex++) {
if (s[closingBracketIndex] == closingBracket) {
if (s.substring(closingBracketIndex, closingBracketIndex + closing.length) == closing) {
if (level == 0) {
return { content: s.slice(0, closingBracketIndex), rest: s.slice(closingBracketIndex + 1) };
return { content: s.slice(0, closingBracketIndex), rest: s.slice(closingBracketIndex + closing.length) };
} else {

@@ -773,3 +773,3 @@ level--;

}
const toIgnores = ["\\" + openingBracket, "\\" + closingBracket, String.raw`\left` + openingBracket, String.raw`\right` + closingBracket];
const toIgnores = ["\\" + openingBracket, "\\" + closing, String.raw`\left` + openingBracket, String.raw`\right` + closing];
const currentPosition = s.slice(closingBracketIndex);

@@ -786,3 +786,3 @@ for (const toIgnore of toIgnores) {

}
throw `A closing ${closingBracket} is missing.`;
throw `A closing ${closing} is missing.`;
}

@@ -885,2 +885,14 @@

}
if (latexParserConfiguration.useRoundBracketsNode && (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 bracketsContentNodes = parseLatex(bracketsContentAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
insert(k, bracketsContentNodes);
k.current = bracketsNode;
x = bracketsContentAndRest.rest;
continue;
}
if (x.startsWith("\\")) {

@@ -1004,2 +1016,3 @@ for (const prefix of ["\\left\\", "\\right\\", String.raw`\left`, String.raw`\right`]) {

this.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets = [];
this.useRoundBracketsNode = true;
}

@@ -1006,0 +1019,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:()=>p,DecimalSeparatorNode:()=>F,DescendingBranchingNode:()=>C,DigitNode:()=>V,KeyboardMemory:()=>S,LatexConfiguration:()=>X,LatexParserConfiguration:()=>Q,LeafNode:()=>w,MatrixNode:()=>z,Placeholder:()=>c,RoundBracketsNode:()=>U,StandardBranchingNode:()=>g,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:()=>y,moveUp:()=>pe,parseLatex:()=>E,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 O(...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=()=>O(...this.nodes.map(n=>n.getLatex(o,r)));return o.inclusiveSelectionLeftBorder===this?O(r.selectionHightlightStart,t()):this===o.current?this.nodes.length==0?r.activePlaceholderLatex:O(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 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=O(r.selectionHightlightStart,t)),o.inclusiveSelectionRightBorder===this&&(t=O(t,r.selectionHightlightEnd)),t):o.current===this?O(t,r.activePlaceholderLatex):t}};var p=class extends u{constructor(r){super();this.placeholders=r,this.placeholders.forEach(t=>{t.parentNode=this})}getMoveDownSuggestion(r){return null}getMoveUpSuggestion(r){return null}};function x(e){return e[e.length-1]}var w=class extends u{};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)M(o,n),r.nodes.unshift(n),n.parentPlaceholder=r;else break}}function D(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?(D(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=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)Me(t,e.current),e.current=x(e.current.nodes);else{let n=e.current.parentNode.placeholders.filter(i=>i.nodes.length!=0);if(n.length==1){let i=n[0].nodes,l=e.current.parentNode.parentPlaceholder,N=l.nodes.indexOf(e.current.parentNode);for(let d of i)d.parentPlaceholder=l;l.nodes.splice(N,1,...i),e.current=x(i)}}}}}else if(e.current instanceof p&&e.current.placeholders[0].nodes.length>0&&e.current.placeholders.slice(1).every(r=>r.nodes.length==0)){let r=e.current.placeholders[0];D(r),e.current=x(r.nodes)}else if(e.current instanceof p&&e.current.placeholders.some(r=>r.nodes.length>0))e.current=x(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 Me(e,o){M(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 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);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,D(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 p?o.placeholders.length==1&&o.placeholders[0].nodes.length>0?D(o.placeholders[0]):o.placeholders.length==2&&o.placeholders[0].nodes.length==0&&o.placeholders[1].nodes.length>0?D(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 $(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){$(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 p?r.placeholders[0]:r}else{if(e.current.parentNode==null)return;e.current=(o=K(e.current.parentNode.placeholders,e.current))!=null?o:e.current.parentNode}else{let r=K(e.current.parentPlaceholder.nodes,e.current);if(r!=null)e.current=r instanceof p?r.placeholders[0]:r;else{let t=e.current.parentPlaceholder.parentNode;if(t!=null){let n=K(t.placeholders,e.current.parentPlaceholder);e.current=n!=null?n:t}}}}function 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}y(e)}}var g=class extends p{constructor(r,t,...n){let i=n.length+1,l=new Array;for(let N=0;N<i;N++)l.push(new c);super(l);this.before=r,this.then=t,this.rest=n}getLatexPart(r,t){let n=this.before+this.placeholders[0].getLatex(r,t)+this.then;for(let i=0;i<this.rest.length;i++)n+=this.placeholders[i+1].getLatex(r,t)+this.rest[i];return n}};var U=class extends g{constructor(o=String.raw`\left(`,r=String.raw`\right)`){super(o,r)}};function H(e,o){for(let r of e)r.parentPlaceholder=o,o.nodes.push(r)}function j(e,o,r){var n;let t=o.placeholders[0];if(e.current instanceof u){let i=e.current.parentPlaceholder.nodes,l=i.indexOf(e.current);i[l]=o,o.parentPlaceholder=e.current.parentPlaceholder,e.current instanceof U&&(r!=null&&r.deleteOuterRoundBracketsIfAny)?(H(e.current.placeholders[0].nodes,t),e.current=(n=K(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 a(e,o)}function ce(e,o){let r=$(e);if(a(e,o),r.length>0){let t=o.placeholders[0];H(r,t),e.current=x(r),y(e)}}function se(e,o){var n;if(o.placeholders.length<2)throw"Expected 2 placeholders.";let r=$(e),t=o.placeholders[1];H(r,t),j(e,o),e.current=(n=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 p){let n=x(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 R(e,o){if(e.selectionDiff=o,o==0)e.inclusiveSelectionLeftBorder=null,e.inclusiveSelectionRightBorder=null;else if(e.current instanceof c)e.inclusiveSelectionLeftBorder=e.current,e.inclusiveSelectionRightBorder=e.current.nodes[o-1];else{let r=e.current.parentPlaceholder.nodes,t=r.indexOf(e.current);if(o>0)e.inclusiveSelectionLeftBorder=r[t+1],e.inclusiveSelectionRightBorder=r[t+o];else{let n=t+o+1;if(n<0)throw"The TreeNode at index 0 of the current Placeholder is as far as you can go left if current is a TreeNode.";e.inclusiveSelectionLeftBorder=r[n],e.inclusiveSelectionRightBorder=e.current}}}function fe(e){R(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?R(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,R(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)R(e,o+1);else if(e.inclusiveSelectionRightBorder instanceof u&&x(e.inclusiveSelectionRightBorder.parentPlaceholder.nodes)==e.inclusiveSelectionRightBorder&&e.inclusiveSelectionRightBorder.parentPlaceholder.parentNode!=null){let n=e.inclusiveSelectionRightBorder.parentPlaceholder.parentNode;e.current=(t=h(n.parentPlaceholder.nodes,n))!=null?t:n.parentPlaceholder,R(e,1)}}var q=class extends g{getMoveDownSuggestion(o){let r=this.placeholders.indexOf(o);return r>0?this.placeholders[r-1]:null}getMoveUpSuggestion(o){let r=this.placeholders.indexOf(o);return r<this.placeholders.length-1?this.placeholders[r+1]:null}};var F=class extends P{constructor(r="."){super();this.latex=typeof r=="string"?()=>r:r}getLatexPart(r,t){return this.latex()}};var C=class extends g{getMoveDownSuggestion(o){let r=this.placeholders.indexOf(o);return r<this.placeholders.length-1?this.placeholders[r+1]:null}getMoveUpSuggestion(o){let r=this.placeholders.indexOf(o);return r>0?this.placeholders[r-1]:null}};var V=class extends P{constructor(r){super();this.latex=r}getLatexPart(r,t){return this.latex}};var L=class extends w{constructor(r){super();this.latex=typeof r=="string"?()=>r:r}getLatexPart(r,t){return this.latex()}};function W(e,o,r){let t=e.slice(-1),n=r.slice(e.length),i=0;for(let l=0;l<n.length;l++){if(n[l]==o){if(i==0)return{content:n.slice(0,l),rest:n.slice(l+1)};i--;continue}let N=["\\"+t,"\\"+o,String.raw`\left`+t,String.raw`\right`+o],d=n.slice(l);for(let m of N)if(d.length>=m.length&&d.startsWith(m)){l+=m.length;continue}n[l]==t&&i++}throw`A closing ${o} is missing.`}var z=class extends p{constructor(r,t,n){let i=[],l=[];for(let N=0;N<n;N++){let d=[];for(let m=0;m<t;m++){let s=new c;d.push(s),l.push(s)}i.push(d)}super(l);this.grid=i,this.matrixType=r,this.width=t}getLatexPart(r,t){let n=String.raw`\begin{${this.matrixType}}`;return n+=this.grid.map(i=>i.map(l=>l.getLatex(r,t)).join(" & ")).join(String.raw` \\ `),n+=String.raw`\end{${this.matrixType}}`,n}getMoveDownSuggestion(r){let{rowIndex:t,columnIndex:n}=this.getPositionOf(r);return t+1<this.grid.length?this.grid[t+1][n]:null}getMoveUpSuggestion(r){let{rowIndex:t,columnIndex:n}=this.getPositionOf(r);return t-1>=0?this.grid[t-1][n]:null}getPositionOf(r){let t=this.placeholders.indexOf(r);if(t==-1)throw"The provided Placeholder is not part of this MatrixNode.";let n=Math.floor(t/this.width),i=t-n*this.width;return{rowIndex:n,columnIndex:i}}};function E(e,o,r){var i;let t=e==null?void 0:e.trim();if(t==null||t=="")return new 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=W(String.raw`\begin{`,"}",t);if(!d.content.endsWith("matrix")&&!d.content.endsWith("cases"))throw String.raw`Expected a word ending with 'matrix' or 'cases' after '\begin{'.`;let s=d.rest.slice(0,d.rest.indexOf(String.raw`\end{${d.content}}`)).split(String.raw`\\`);a(n,new z(d.content,s[0].split("&").length,s.length));for(let v of s)for(let B of v.split("&")){let A=E(B,o,r).syntaxTreeRoot.nodes;a(n,A),y(n)}let f=String.raw`\end{${d.content}}`;t=t.slice(t.indexOf(f)+f.length);continue}if(t.startsWith("\\")){for(let s of["\\left\\","\\right\\",String.raw`\left`,String.raw`\right`])if(t.startsWith(s)){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 f=s.slice(0,-3),v=s.slice(-3,-2),B=s.slice(-2,-1),A=s.slice(-1);if(t.startsWith(f)){let I=W(f,v,t);if(I.rest[0]!=B)continue;let k=new C(f,v+B,A);a(n,k);let ge=E(I.content,o,r).syntaxTreeRoot.nodes;a(n,ge),y(n);let ee=W(B,A,I.rest),xe=E(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=W(d,"}",t),f=new g(d,"}");a(n,f);for(let v of s.content)a(n,new L(v));n.current=f,t=s.rest;continue}let m="\\";if(T(t[1])){for(let s=1;s<t.length;s++){let f=t[s];if(T(f))m+=f;else if(f=="{"){m+=f;let v=m,B=W(v,"}",t),A=E(B.content,o,r).syntaxTreeRoot.nodes,I=new g(v,"}");a(n,I),a(n,A),n.current=I,t=B.rest,l=!0;break}else break}if(l)continue;a(n,new L(m)),t=t.slice(m.length)}else a(n,new L("\\"+t[1])),t=t.slice(2);continue}let N=[["^{",()=>new q("","^{","}")],["_{",()=>new C("","_{","}")]];for(let d of N){let m=d[0];if(t.startsWith(m)){let s=d[1]();j(n,s);let f=W(m,"}",t),v=E(f.content,o,r).syntaxTreeRoot.nodes;a(n,v),n.current=s,t=f.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=[]}};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 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);})();

@@ -699,3 +699,3 @@ // src/GetLatex/getEditModeLatex.ts

// src/LatexParser/helpers/getBracketPairContent.ts
function getBracketPairContent(opening, closingBracket, sWithOpening) {
function getBracketPairContent(opening, closing, sWithOpening) {
const openingBracket = opening.slice(-1);

@@ -705,5 +705,5 @@ const s = sWithOpening.slice(opening.length);

for (let closingBracketIndex = 0; closingBracketIndex < s.length; closingBracketIndex++) {
if (s[closingBracketIndex] == closingBracket) {
if (s.substring(closingBracketIndex, closingBracketIndex + closing.length) == closing) {
if (level == 0) {
return { content: s.slice(0, closingBracketIndex), rest: s.slice(closingBracketIndex + 1) };
return { content: s.slice(0, closingBracketIndex), rest: s.slice(closingBracketIndex + closing.length) };
} else {

@@ -714,3 +714,3 @@ level--;

}
const toIgnores = ["\\" + openingBracket, "\\" + closingBracket, String.raw`\left` + openingBracket, String.raw`\right` + closingBracket];
const toIgnores = ["\\" + openingBracket, "\\" + closing, String.raw`\left` + openingBracket, String.raw`\right` + closing];
const currentPosition = s.slice(closingBracketIndex);

@@ -727,3 +727,3 @@ for (const toIgnore of toIgnores) {

}
throw `A closing ${closingBracket} is missing.`;
throw `A closing ${closing} is missing.`;
}

@@ -826,2 +826,14 @@

}
if (latexParserConfiguration.useRoundBracketsNode && (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 bracketsContentNodes = parseLatex(bracketsContentAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
insert(k, bracketsContentNodes);
k.current = bracketsNode;
x = bracketsContentAndRest.rest;
continue;
}
if (x.startsWith("\\")) {

@@ -945,2 +957,3 @@ for (const prefix of ["\\left\\", "\\right\\", String.raw`\left`, String.raw`\right`]) {

this.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets = [];
this.useRoundBracketsNode = true;
}

@@ -947,0 +960,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 O(...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=()=>O(...this.nodes.map(n=>n.getLatex(o,r)));return o.inclusiveSelectionLeftBorder===this?O(r.selectionHightlightStart,t()):this===o.current?this.nodes.length==0?r.activePlaceholderLatex:O(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=O(r.selectionHightlightStart,t)),o.inclusiveSelectionRightBorder===this&&(t=O(t,r.selectionHightlightEnd)),t):o.current===this?O(t,r.activePlaceholderLatex):t}};var f=class extends h{constructor(r){super();this.placeholders=r,this.placeholders.forEach(t=>{t.parentNode=this})}getMoveDownSuggestion(r){return null}getMoveUpSuggestion(r){return null}};function g(e){return e[e.length-1]}var R=class extends h{};var x=class extends R{};function G(e,o,r){for(let t=e-1;t>=0;t--){let n=o[t];if(n instanceof x)L(o,n),r.nodes.unshift(n),n.parentPlaceholder=r;else break}}function D(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?(D(r),e.current=g(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=g(e.current.nodes);else{let n=e.current.parentNode.placeholders.filter(i=>i.nodes.length!=0);if(n.length==1){let i=n[0].nodes,l=e.current.parentNode.parentPlaceholder,y=l.nodes.indexOf(e.current.parentNode);for(let d of i)d.parentPlaceholder=l;l.nodes.splice(y,1,...i),e.current=g(i)}}}}}else if(e.current instanceof f&&e.current.placeholders[0].nodes.length>0&&e.current.placeholders.slice(1).every(r=>r.nodes.length==0)){let r=e.current.placeholders[0];D(r),e.current=g(r.nodes)}else if(e.current instanceof f&&e.current.placeholders.some(r=>r.nodes.length>0))e.current=g(e.current.placeholders.flatMap(r=>r.nodes)),re(e);else{let r=u(e.current.parentPlaceholder.nodes,e.current);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 x&&G(r.nodes.length-1,r.nodes,o)}function w(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,D(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=w(e.current.parentPlaceholder.nodes,e.current);r!=null&&te(e,r)}}function te(e,o){o instanceof f?o.placeholders.length==1&&o.placeholders[0].nodes.length>0?D(o.placeholders[0]):o.placeholders.length==2&&o.placeholders[0].nodes.length==0&&o.placeholders[1].nodes.length>0?D(o.placeholders[1]):(e.current=o.placeholders[0],J(e)):L(o.parentPlaceholder.nodes,o)}function U(e){e.selectionDiff=null,e.inclusiveSelectionRightBorder=null,e.inclusiveSelectionLeftBorder=null}function A(e){var r;if(e.selectionDiff==null)throw"Enter selection mode before calling this method.";if(e.selectionDiff==0)return U(e),[];let o=e.selectionDiff;if(e.current instanceof c)return U(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,U(e),t.splice(n,ae(o))}}function ae(e){return e<0?-e:e}function de(e){A(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 f?r.placeholders[0]:r}else{if(e.current.parentNode==null)return;e.current=(o=w(e.current.parentNode.placeholders,e.current))!=null?o:e.current.parentNode}else{let r=w(e.current.parentPlaceholder.nodes,e.current);if(r!=null)e.current=r instanceof f?r.placeholders[0]:r;else{let t=e.current.parentPlaceholder.parentNode;if(t!=null){let n=w(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}b(e)}}var P=class extends f{constructor(r,t,...n){let i=n.length+1,l=new Array;for(let y=0;y<i;y++)l.push(new c);super(l);this.before=r,this.then=t,this.rest=n}getLatexPart(r,t){let n=this.before+this.placeholders[0].getLatex(r,t)+this.then;for(let i=0;i<this.rest.length;i++)n+=this.placeholders[i+1].getLatex(r,t)+this.rest[i];return n}};var H=class extends P{constructor(o=String.raw`\left(`,r=String.raw`\right)`){super(o,r)}};function I(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 H&&(r!=null&&r.deleteOuterRoundBracketsIfAny)?(I(e.current.placeholders[0].nodes,t),e.current=(n=w(o.placeholders,t))!=null?n:o):e.current instanceof x?(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 a(e,o)}function pe(e,o){let r=A(e);if(a(e,o),r.length>0){let t=o.placeholders[0];I(r,t),e.current=g(r),b(e)}}function fe(e,o){var n;if(o.placeholders.length<2)throw"Expected 2 placeholders.";let r=A(e),t=o.placeholders[1];I(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 f){let n=g(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&&g(e.inclusiveSelectionRightBorder.parentPlaceholder.nodes)==e.inclusiveSelectionRightBorder&&e.inclusiveSelectionRightBorder.parentPlaceholder.parentNode!=null){let n=e.inclusiveSelectionRightBorder.parentPlaceholder.parentNode;e.current=(t=u(n.parentPlaceholder.nodes,n))!=null?t:n.parentPlaceholder,K(e,1)}}var q=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 F=class extends x{constructor(r="."){super();this.latex=typeof r=="string"?()=>r:r}getLatexPart(r,t){return this.latex()}};var _=class extends P{getMoveDownSuggestion(o){let r=this.placeholders.indexOf(o);return r<this.placeholders.length-1?this.placeholders[r+1]:null}getMoveUpSuggestion(o){let r=this.placeholders.indexOf(o);return r>0?this.placeholders[r-1]:null}};var V=class extends x{constructor(r){super();this.latex=r}getLatexPart(r,t){return this.latex}};var M=class extends R{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[l]==o){if(i==0)return{content:n.slice(0,l),rest:n.slice(l+1)};i--;continue}let y=["\\"+t,"\\"+o,String.raw`\left`+t,String.raw`\right`+o],d=n.slice(l);for(let m of y)if(d.length>=m.length&&d.startsWith(m)){l+=m.length;continue}n[l]==t&&i++}throw`A closing ${o} is missing.`}var z=class extends f{constructor(r,t,n){let i=[],l=[];for(let y=0;y<n;y++){let d=[];for(let m=0;m<t;m++){let s=new c;d.push(s),l.push(s)}i.push(d)}super(l);this.grid=i,this.matrixType=r,this.width=t}getLatexPart(r,t){let n=String.raw`\begin{${this.matrixType}}`;return n+=this.grid.map(i=>i.map(l=>l.getLatex(r,t)).join(" & ")).join(String.raw` \\ `),n+=String.raw`\end{${this.matrixType}}`,n}getMoveDownSuggestion(r){let{rowIndex:t,columnIndex:n}=this.getPositionOf(r);return t+1<this.grid.length?this.grid[t+1][n]:null}getMoveUpSuggestion(r){let{rowIndex:t,columnIndex:n}=this.getPositionOf(r);return t-1>=0?this.grid[t-1][n]:null}getPositionOf(r){let t=this.placeholders.indexOf(r);if(t==-1)throw"The provided Placeholder is not part of this MatrixNode.";let n=Math.floor(t/this.width),i=t-n*this.width;return{rowIndex:n,columnIndex:i}}};function $(e,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 N of s)for(let B of N.split("&")){let W=$(B,o,r).syntaxTreeRoot.nodes;a(n,W),b(n)}let p=String.raw`\end{${d.content}}`;t=t.slice(t.indexOf(p)+p.length);continue}if(t.startsWith("\\")){for(let s of["\\left\\","\\right\\",String.raw`\left`,String.raw`\right`])if(t.startsWith(s)){a(n,new M(s+t[s.length])),t=t.slice(s.length+1),l=!0;break}if(l)continue;for(let s of r.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets){let p=s.slice(0,-3),N=s.slice(-3,-2),B=s.slice(-2,-1),W=s.slice(-1);if(t.startsWith(p)){let E=C(p,N,t);if(E.rest[0]!=B)continue;let Y=new _(p,N+B,W);a(n,Y);let oe=$(E.content,o,r).syntaxTreeRoot.nodes;a(n,oe),b(n);let Z=C(B,W,E.rest),ne=$(Z.content,o,r).syntaxTreeRoot.nodes;a(n,ne),n.current=Y,t=Z.rest,l=!0;break}}if(l)continue;let d=String.raw`\text{`;if(t.startsWith(d)){let s=C(d,"}",t),p=new P(d,"}");a(n,p);for(let N of s.content)a(n,new M(N));n.current=p,t=s.rest;continue}let m="\\";if(T(t[1])){for(let s=1;s<t.length;s++){let p=t[s];if(T(p))m+=p;else if(p=="{"){m+=p;let N=m,B=C(N,"}",t),W=$(B.content,o,r).syntaxTreeRoot.nodes,E=new P(N,"}");a(n,E),a(n,W),n.current=E,t=B.rest,l=!0;break}else break}if(l)continue;a(n,new M(m)),t=t.slice(m.length)}else a(n,new M("\\"+t[1])),t=t.slice(2);continue}let y=[["^{",()=>new q("","^{","}")],["_{",()=>new _("","_{","}")]];for(let d of y){let m=d[0];if(t.startsWith(m)){let s=d[1]();j(n,s);let p=C(m,"}",t),N=$(p.content,o,r).syntaxTreeRoot.nodes;a(n,N),n.current=s,t=p.rest,l=!0;break}}l!=!0&&(a(n,new M(t[0])),t=t.slice(1))}return n}var Q=class{constructor(){this.additionalDigits=null;this.decimalSeparator=".";this.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets=[]}};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,f as BranchingNode,F as DecimalSeparatorNode,_ as DescendingBranchingNode,V as DigitNode,S as KeyboardMemory,X as LatexConfiguration,Q as LatexParserConfiguration,R as LeafNode,z as MatrixNode,c as Placeholder,H as RoundBracketsNode,P as StandardBranchingNode,M 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,a as insert,j as insertWithEncapsulateCurrent,pe as insertWithEncapsulateSelection,fe as insertWithEncapsulateSelectionAndPrevious,U as leaveSelectionMode,me as moveDown,ue as moveLeft,b as moveRight,he as moveUp,$ as parseLatex,Pe as selectLeft,ye as selectRight};
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};

@@ -688,3 +688,3 @@ // src/GetLatex/getEditModeLatex.ts

// src/LatexParser/helpers/getBracketPairContent.ts
function getBracketPairContent(opening, closingBracket, sWithOpening) {
function getBracketPairContent(opening, closing, sWithOpening) {
const openingBracket = opening.slice(-1);

@@ -694,5 +694,5 @@ const s = sWithOpening.slice(opening.length);

for (let closingBracketIndex = 0; closingBracketIndex < s.length; closingBracketIndex++) {
if (s[closingBracketIndex] == closingBracket) {
if (s.substring(closingBracketIndex, closingBracketIndex + closing.length) == closing) {
if (level == 0) {
return { content: s.slice(0, closingBracketIndex), rest: s.slice(closingBracketIndex + 1) };
return { content: s.slice(0, closingBracketIndex), rest: s.slice(closingBracketIndex + closing.length) };
} else {

@@ -703,3 +703,3 @@ level--;

}
const toIgnores = ["\\" + openingBracket, "\\" + closingBracket, String.raw`\left` + openingBracket, String.raw`\right` + closingBracket];
const toIgnores = ["\\" + openingBracket, "\\" + closing, String.raw`\left` + openingBracket, String.raw`\right` + closing];
const currentPosition = s.slice(closingBracketIndex);

@@ -716,3 +716,3 @@ for (const toIgnore of toIgnores) {

}
throw `A closing ${closingBracket} is missing.`;
throw `A closing ${closing} is missing.`;
}

@@ -814,2 +814,14 @@

}
if (latexParserConfiguration.useRoundBracketsNode && (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 bracketsContentNodes = parseLatex(bracketsContentAndRest.content, latexConfiguration, latexParserConfiguration).syntaxTreeRoot.nodes;
insert(k, bracketsContentNodes);
k.current = bracketsNode;
x = bracketsContentAndRest.rest;
continue;
}
if (x.startsWith("\\")) {

@@ -933,2 +945,3 @@ for (const prefix of ["\\left\\", "\\right\\", String.raw`\left`, String.raw`\right`]) {

this.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets = [];
this.useRoundBracketsNode = true;
}

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

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

function ne(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 T(...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 l=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 l;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 f=class extends h{constructor(t){super();this.placeholders=t,this.placeholders.forEach(o=>{o.parentNode=this})}getMoveDownSuggestion(t){return null}getMoveUpSuggestion(t){return null}};function g(e){return e[e.length-1]}var K=class extends h{};var x=class extends K{};function z(e,r,t){for(let o=e-1;o>=0;o--){let n=r[o];if(n instanceof x)S(r,n),t.nodes.unshift(n),n.parentPlaceholder=t;else break}}function R(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 l){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?(R(r),e.current=g(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=g(e.current.nodes);else{let o=e.current.parentNode.placeholders.filter(n=>n.nodes.length!=0);if(o.length==1){let n=o[0].nodes,i=e.current.parentNode.parentPlaceholder,d=i.nodes.indexOf(e.current.parentNode);for(let s of n)s.parentPlaceholder=i;i.nodes.splice(d,1,...n),e.current=g(n)}}}}}else if(e.current instanceof f&&e.current.placeholders[0].nodes.length>0&&e.current.placeholders.slice(1).every(r=>r.nodes.length==0)){let r=e.current.placeholders[0];R(r),e.current=g(r.nodes)}else if(e.current instanceof f&&e.current.placeholders.some(r=>r.nodes.length>0))e.current=g(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 x&&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 l)if(e.current.parentNode!=null&&e.current.parentNode.placeholders.every(r=>r.nodes.length==0)){let r=u(e.current.parentNode.parentPlaceholder.nodes,e.current.parentNode);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,R(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 f?r.placeholders.length==1&&r.placeholders[0].nodes.length>0?R(r.placeholders[0]):r.placeholders.length==2&&r.placeholders[0].nodes.length==0&&r.placeholders[1].nodes.length>0?R(r.placeholders[1]):(e.current=r.placeholders[0],G(e)):S(r.parentPlaceholder.nodes,r)}function $(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 $(e),[];let r=e.selectionDiff;if(e.current instanceof l)return $(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,$(e),t.splice(o,se(r))}}function se(e){return e<0?-e:e}function ae(e){E(e)}function v(e){if(e.current instanceof l)if(e.current.nodes.length>0){let r=e.current.nodes[0];e.current=r instanceof f?r.placeholders[0]:r}else{if(e.current.parentNode==null)return;e.current=O(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 f?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 l)e.current.nodes.unshift(r),r.parentPlaceholder=e.current;else{let t=e.current.parentPlaceholder,o=t.nodes.indexOf(e.current);t.nodes.splice(o+1,0,r),r.parentPlaceholder=t}v(e)}}var P=class extends f{constructor(t,o,...n){let i=n.length+1,d=new Array;for(let s=0;s<i;s++)d.push(new l);super(d);this.before=t,this.then=o,this.rest=n}getLatexPart(t,o){let n=this.before+this.placeholders[0].getLatex(t,o)+this.then;for(let i=0;i<this.rest.length;i++)n+=this.placeholders[i+1].getLatex(t,o)+this.rest[i];return n}};var U=class extends P{constructor(r=String.raw`\left(`,t=String.raw`\right)`){super(r,t)}};function A(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 U&&t?.deleteOuterRoundBracketsIfAny?(A(e.current.placeholders[0].nodes,o),e.current=O(r.placeholders,o)??r):e.current instanceof x?(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=E(e);if(a(e,r),t.length>0){let o=r.placeholders[0];A(t,o),e.current=g(t),v(e)}}function pe(e,r){if(r.placeholders.length<2)throw"Expected 2 placeholders.";let t=E(e),o=r.placeholders[1];A(t,o),H(e,r),e.current=N(t)??o}function fe(e){let r=e.current instanceof l?e.current:e.current.parentPlaceholder,t;for(;;){if(r.parentNode==null)return;t=r.parentNode;let o=t.getMoveDownSuggestion(r);if(o!=null){e.current=N(o.nodes)??o;return}r=t.parentPlaceholder}}function me(e){if(e.current instanceof l){if(e.current.parentNode==null)return;let r=u(e.current.parentNode.placeholders,e.current);if(r!==null)e.current=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 f){let r=g(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 l?e.current:e.current.parentPlaceholder,t;for(;;){if(r.parentNode==null)return;t=r.parentNode;let o=t.getMoveUpSuggestion(r);if(o!=null){e.current=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 l)e.inclusiveSelectionLeftBorder=e.current,e.inclusiveSelectionRightBorder=e.current.nodes[r-1];else{let t=e.current.parentPlaceholder.nodes,o=t.indexOf(e.current);if(r>0)e.inclusiveSelectionLeftBorder=t[o+1],e.inclusiveSelectionRightBorder=t[o+r];else{let n=o+r+1;if(n<0)throw"The TreeNode at index 0 of the current Placeholder is as far as you can go left if current is a TreeNode.";e.inclusiveSelectionLeftBorder=t[n],e.inclusiveSelectionRightBorder=e.current}}}function 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 l&&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 l&&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&&g(e.inclusiveSelectionRightBorder.parentPlaceholder.nodes)==e.inclusiveSelectionRightBorder&&e.inclusiveSelectionRightBorder.parentPlaceholder.parentNode!=null){let t=e.inclusiveSelectionRightBorder.parentPlaceholder.parentNode;e.current=u(t.parentPlaceholder.nodes,t)??t.parentPlaceholder,w(e,1)}}var j=class extends P{getMoveDownSuggestion(r){let t=this.placeholders.indexOf(r);return t>0?this.placeholders[t-1]:null}getMoveUpSuggestion(r){let t=this.placeholders.indexOf(r);return t<this.placeholders.length-1?this.placeholders[t+1]:null}};var q=class extends x{constructor(t="."){super();this.latex=typeof t=="string"?()=>t:t}getLatexPart(t,o){return this.latex()}};var I=class extends P{getMoveDownSuggestion(r){let t=this.placeholders.indexOf(r);return t<this.placeholders.length-1?this.placeholders[t+1]:null}getMoveUpSuggestion(r){let t=this.placeholders.indexOf(r);return t>0?this.placeholders[t-1]:null}};var F=class extends x{constructor(t){super();this.latex=t}getLatexPart(t,o){return this.latex}};var L=class extends K{constructor(t){super();this.latex=typeof t=="string"?()=>t:t}getLatexPart(t,o){return this.latex()}};function D(e,r,t){let o=e.slice(-1),n=t.slice(e.length),i=0;for(let d=0;d<n.length;d++){if(n[d]==r){if(i==0)return{content:n.slice(0,d),rest:n.slice(d+1)};i--;continue}let s=["\\"+o,"\\"+r,String.raw`\left`+o,String.raw`\right`+r],m=n.slice(d);for(let c of s)if(m.length>=c.length&&m.startsWith(c)){d+=c.length;continue}n[d]==o&&i++}throw`A closing ${r} is missing.`}var V=class extends f{constructor(t,o,n){let i=[],d=[];for(let s=0;s<n;s++){let m=[];for(let c=0;c<o;c++){let p=new l;m.push(p),d.push(p)}i.push(m)}super(d);this.grid=i,this.matrixType=t,this.width=o}getLatexPart(t,o){let n=String.raw`\begin{${this.matrixType}}`;return n+=this.grid.map(i=>i.map(d=>d.getLatex(t,o)).join(" & ")).join(String.raw` \\ `),n+=String.raw`\end{${this.matrixType}}`,n}getMoveDownSuggestion(t){let{rowIndex:o,columnIndex:n}=this.getPositionOf(t);return o+1<this.grid.length?this.grid[o+1][n]:null}getMoveUpSuggestion(t){let{rowIndex:o,columnIndex:n}=this.getPositionOf(t);return o-1>=0?this.grid[o-1][n]:null}getPositionOf(t){let o=this.placeholders.indexOf(t);if(o==-1)throw"The provided Placeholder is not part of this MatrixNode.";let n=Math.floor(o/this.width),i=o-n*this.width;return{rowIndex:n,columnIndex:i}}};function _(e,r,t){let o=e?.trim();if(o==null||o=="")return new 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=D(String.raw`\begin{`,"}",o);if(!s.content.endsWith("matrix")&&!s.content.endsWith("cases"))throw String.raw`Expected a word ending with 'matrix' or 'cases' after '\begin{'.`;let c=s.rest.slice(0,s.rest.indexOf(String.raw`\end{${s.content}}`)).split(String.raw`\\`);a(n,new V(s.content,c[0].split("&").length,c.length));for(let y of c)for(let M of y.split("&")){let C=_(M,r,t).syntaxTreeRoot.nodes;a(n,C),v(n)}let p=String.raw`\end{${s.content}}`;o=o.slice(o.indexOf(p)+p.length);continue}if(o.startsWith("\\")){for(let c of["\\left\\","\\right\\",String.raw`\left`,String.raw`\right`])if(o.startsWith(c)){a(n,new L(c+o[c.length])),o=o.slice(c.length+1),i=!0;break}if(i)continue;for(let c of t.descendingBranchingNodeSlashCommandsWithTwoPairsOfBrackets){let p=c.slice(0,-3),y=c.slice(-3,-2),M=c.slice(-2,-1),C=c.slice(-1);if(o.startsWith(p)){let W=D(p,y,o);if(W.rest[0]!=M)continue;let X=new I(p,y+M,C);a(n,X);let te=_(W.content,r,t).syntaxTreeRoot.nodes;a(n,te),v(n);let Y=D(M,C,W.rest),oe=_(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 c=D(s,"}",o),p=new P(s,"}");a(n,p);for(let y of c.content)a(n,new L(y));n.current=p,o=c.rest;continue}let m="\\";if(B(o[1])){for(let c=1;c<o.length;c++){let p=o[c];if(B(p))m+=p;else if(p=="{"){m+=p;let y=m,M=D(y,"}",o),C=_(M.content,r,t).syntaxTreeRoot.nodes,W=new P(y,"}");a(n,W),a(n,C),n.current=W,o=M.rest,i=!0;break}else break}if(i)continue;a(n,new L(m)),o=o.slice(m.length)}else a(n,new L("\\"+o[1])),o=o.slice(2);continue}let d=[["^{",()=>new j("","^{","}")],["_{",()=>new I("","_{","}")]];for(let s of d){let m=s[0];if(o.startsWith(m)){let c=s[1]();H(n,c);let p=D(m,"}",o),y=_(p.content,r,t).syntaxTreeRoot.nodes;a(n,y),n.current=c,o=p.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=[]}};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,f as BranchingNode,q as DecimalSeparatorNode,I as DescendingBranchingNode,F as DigitNode,b as KeyboardMemory,Q as LatexConfiguration,J as LatexParserConfiguration,K as LeafNode,V as MatrixNode,l as Placeholder,U as RoundBracketsNode,P 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,$ as leaveSelectionMode,fe as moveDown,me as moveLeft,v as moveRight,ue as moveUp,_ as parseLatex,xe as selectLeft,Pe as selectRight};
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};

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

],
"version": "v1.1.0-alpha.2",
"version": "v1.1.0-alpha.3",
"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