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

Function getVListChildrenAndDepth

static/katex/katex.mjs:5646–5707  ·  view source on GitHub ↗
(params)

Source from the content-addressed store, hash-verified

5644// This helper function for makeVList makes it easier to enforce type safety by
5645// allowing early exits (returns) in the logic.
5646const getVListChildrenAndDepth = function getVListChildrenAndDepth(params) {
5647 if (params.positionType === "individualShift") {
5648 const oldChildren = params.children;
5649 const children = [oldChildren[0]]; // Add in kerns to the list of params.children to get each element to be
5650 // shifted to the correct specified shift
5651
5652 const depth = -oldChildren[0].shift - oldChildren[0].elem.depth;
5653 let currPos = depth;
5654
5655 for (let i = 1; i < oldChildren.length; i++) {
5656 const diff = -oldChildren[i].shift - currPos - oldChildren[i].elem.depth;
5657 const size = diff - (oldChildren[i - 1].elem.height + oldChildren[i - 1].elem.depth);
5658 currPos = currPos + diff;
5659 children.push({
5660 type: "kern",
5661 size
5662 });
5663 children.push(oldChildren[i]);
5664 }
5665
5666 return {
5667 children,
5668 depth
5669 };
5670 }
5671
5672 let depth;
5673
5674 if (params.positionType === "top") {
5675 // We always start at the bottom, so calculate the bottom by adding up
5676 // all the sizes
5677 let bottom = params.positionData;
5678
5679 for (let i = 0; i < params.children.length; i++) {
5680 const child = params.children[i];
5681 bottom -= child.type === "kern" ? child.size : child.elem.height + child.elem.depth;
5682 }
5683
5684 depth = bottom;
5685 } else if (params.positionType === "bottom") {
5686 depth = -params.positionData;
5687 } else {
5688 const firstChild = params.children[0];
5689
5690 if (firstChild.type !== "elem") {
5691 throw new Error('First child must have type "elem".');
5692 }
5693
5694 if (params.positionType === "shift") {
5695 depth = -firstChild.elem.depth - params.positionData;
5696 } else if (params.positionType === "firstBaseline") {
5697 depth = -firstChild.elem.depth;
5698 } else {
5699 throw new Error(`Invalid positionType ${params.positionType}.`);
5700 }
5701 }
5702
5703 return {

Callers 1

makeVListFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected