A world-class math input for the web
1export abstract class TokenFlow {
2 /**
3 * The required number of children for this flow type, or null if there is no fixed requirement.
4 */
5 get requiredLength(): number | null {
6 return null;
7 }
8
9 /**
10 * If a selection range extends from within one child to within another child,
11 * this function determines whether a third child is considered to be "within"
12 * those two children (inclusive of those two) for the purposes of selection highlighting.
13 * @param anchorIndex The index of the first child in the selection range
14 * @param headIndex The index of the second child in the selection range
15 * @param otherIndex The index of the child to test
16 * @returns Whether the child at otherIndex is between the children at anchorIndex and headIndex
17 */
18 isWithin(
19 anchorIndex: number,
20 headIndex: number,
21 otherIndex: number
22 ): boolean {
23 const minIndex = Math.min(anchorIndex, headIndex);
24 const maxIndex = Math.max(anchorIndex, headIndex);
25 return otherIndex >= minIndex && otherIndex <= maxIndex;
26 }
27
28 /**
29 * When navigating vertically (e.g., with the up/down arrow keys), this function provides a list of candidate child indices
30 * to move to from a given child index in the specified direction.
31 * @param direction The direction of navigation ("up" or "down")
32 * @param fromIndex The current child index
33 * @returns An array of candidate child indices to navigate to
34 */
35 verticalCandidates(
36 _direction: "up" | "down",
37 _fromIndex: number,
38 _length: number
39 ): number[] {
40 return [];
41 }
42}