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

Function getVListChildrenAndDepth

static/katex/katex.js:5677–5739  ·  view source on GitHub ↗
(params)

Source from the content-addressed store, hash-verified

5675// This helper function for makeVList makes it easier to enforce type safety by
5676// allowing early exits (returns) in the logic.
5677var getVListChildrenAndDepth = function getVListChildrenAndDepth(params) {
5678 if (params.positionType === "individualShift") {
5679 var oldChildren = params.children;
5680 var children = [oldChildren[0]]; // Add in kerns to the list of params.children to get each element to be
5681 // shifted to the correct specified shift
5682
5683 var _depth = -oldChildren[0].shift - oldChildren[0].elem.depth;
5684
5685 var currPos = _depth;
5686
5687 for (var i = 1; i < oldChildren.length; i++) {
5688 var diff = -oldChildren[i].shift - currPos - oldChildren[i].elem.depth;
5689 var size = diff - (oldChildren[i - 1].elem.height + oldChildren[i - 1].elem.depth);
5690 currPos = currPos + diff;
5691 children.push({
5692 type: "kern",
5693 size: size
5694 });
5695 children.push(oldChildren[i]);
5696 }
5697
5698 return {
5699 children: children,
5700 depth: _depth
5701 };
5702 }
5703
5704 var depth;
5705
5706 if (params.positionType === "top") {
5707 // We always start at the bottom, so calculate the bottom by adding up
5708 // all the sizes
5709 var bottom = params.positionData;
5710
5711 for (var _i = 0; _i < params.children.length; _i++) {
5712 var child = params.children[_i];
5713 bottom -= child.type === "kern" ? child.size : child.elem.height + child.elem.depth;
5714 }
5715
5716 depth = bottom;
5717 } else if (params.positionType === "bottom") {
5718 depth = -params.positionData;
5719 } else {
5720 var firstChild = params.children[0];
5721
5722 if (firstChild.type !== "elem") {
5723 throw new Error('First child must have type "elem".');
5724 }
5725
5726 if (params.positionType === "shift") {
5727 depth = -firstChild.elem.depth - params.positionData;
5728 } else if (params.positionType === "firstBaseline") {
5729 depth = -firstChild.elem.depth;
5730 } else {
5731 throw new Error("Invalid positionType " + params.positionType + ".");
5732 }
5733 }
5734

Callers 1

buildCommon_makeVListFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected