MCPcopy Create free account
hub / github.com/TruthHun/BookStack / traverseSequence

Function traverseSequence

static/katex/katex.mjs:8491–8521  ·  view source on GitHub ↗
(delim, height, sequence, options)

Source from the content-addressed store, hash-verified

8489
8490
8491const traverseSequence = function traverseSequence(delim, height, sequence, options) {
8492 // Here, we choose the index we should start at in the sequences. In smaller
8493 // sizes (which correspond to larger numbers in style.size) we start earlier
8494 // in the sequence. Thus, scriptscript starts at index 3-3=0, script starts
8495 // at index 3-2=1, text starts at 3-1=2, and display starts at min(2,3-0)=2
8496 const start = Math.min(2, 3 - options.style.size);
8497
8498 for (let i = start; i < sequence.length; i++) {
8499 if (sequence[i].type === "stack") {
8500 // This is always the last delimiter, so we just break the loop now.
8501 break;
8502 }
8503
8504 const metrics = getMetrics(delim, delimTypeToFont(sequence[i]), "math");
8505 let heightDepth = metrics.height + metrics.depth; // Small delimiters are scaled down versions of the same font, so we
8506 // account for the style change size.
8507
8508 if (sequence[i].type === "small") {
8509 const newOptions = options.havingBaseStyle(sequence[i].style);
8510 heightDepth *= newOptions.sizeMultiplier;
8511 } // Check if the delimiter at this size works for the given height.
8512
8513
8514 if (heightDepth > height) {
8515 return sequence[i];
8516 }
8517 } // If we reached the end of the sequence, return the last sequence element.
8518
8519
8520 return sequence[sequence.length - 1];
8521};
8522/**
8523 * Make a delimiter of a given height+depth, with optional centering. Here, we
8524 * traverse the sequences, and create a delimiter that the sequence tells us to.

Callers 2

makeSqrtImageFunction · 0.70
makeCustomSizedDelimFunction · 0.70

Calls 3

getMetricsFunction · 0.85
havingBaseStyleMethod · 0.80
delimTypeToFontFunction · 0.70

Tested by

no test coverage detected