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

Function svgSpan

static/katex/katex.mjs:7175–7306  ·  view source on GitHub ↗
(group, options)

Source from the content-addressed store, hash-verified

7173};
7174
7175const svgSpan = function svgSpan(group, options) {
7176 // Create a span with inline SVG for the element.
7177 function buildSvgSpan_() {
7178 let viewBoxWidth = 400000; // default
7179
7180 const label = group.label.substr(1);
7181
7182 if (utils.contains(["widehat", "widecheck", "widetilde", "utilde"], label)) {
7183 // Each type in the `if` statement corresponds to one of the ParseNode
7184 // types below. This narrowing is required to access `grp.base`.
7185 const grp = group; // There are four SVG images available for each function.
7186 // Choose a taller image when there are more characters.
7187
7188 const numChars = groupLength(grp.base);
7189 let viewBoxHeight;
7190 let pathName;
7191 let height;
7192
7193 if (numChars > 5) {
7194 if (label === "widehat" || label === "widecheck") {
7195 viewBoxHeight = 420;
7196 viewBoxWidth = 2364;
7197 height = 0.42;
7198 pathName = label + "4";
7199 } else {
7200 viewBoxHeight = 312;
7201 viewBoxWidth = 2340;
7202 height = 0.34;
7203 pathName = "tilde4";
7204 }
7205 } else {
7206 const imgIndex = [1, 1, 2, 2, 3, 3][numChars];
7207
7208 if (label === "widehat" || label === "widecheck") {
7209 viewBoxWidth = [0, 1062, 2364, 2364, 2364][imgIndex];
7210 viewBoxHeight = [0, 239, 300, 360, 420][imgIndex];
7211 height = [0, 0.24, 0.3, 0.3, 0.36, 0.42][imgIndex];
7212 pathName = label + imgIndex;
7213 } else {
7214 viewBoxWidth = [0, 600, 1033, 2339, 2340][imgIndex];
7215 viewBoxHeight = [0, 260, 286, 306, 312][imgIndex];
7216 height = [0, 0.26, 0.286, 0.3, 0.306, 0.34][imgIndex];
7217 pathName = "tilde" + imgIndex;
7218 }
7219 }
7220
7221 const path = new PathNode(pathName);
7222 const svgNode = new SvgNode([path], {
7223 "width": "100%",
7224 "height": height + "em",
7225 "viewBox": `0 0 ${viewBoxWidth} ${viewBoxHeight}`,
7226 "preserveAspectRatio": "none"
7227 });
7228 return {
7229 span: buildCommon.makeSvgSpan([], [svgNode], options),
7230 minWidth: 0,
7231 height
7232 };

Callers

nothing calls this directly

Calls 1

buildSvgSpan_Function · 0.70

Tested by

no test coverage detected