katex 0.16.37 → 0.16.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/katex.mjs CHANGED
@@ -754,6 +754,54 @@ var tallDelim = function tallDelim(label, midHeight) {
754
754
  }
755
755
  };
756
756
 
757
+ /**
758
+ * This node represents a document fragment, which contains elements, but when
759
+ * placed into the DOM doesn't have any representation itself. It only contains
760
+ * children and doesn't have any DOM node properties.
761
+ */
762
+ class DocumentFragment {
763
+ // Never used; needed for satisfying interface.
764
+ constructor(children) {
765
+ this.children = children;
766
+ this.classes = [];
767
+ this.height = 0;
768
+ this.depth = 0;
769
+ this.maxFontSize = 0;
770
+ this.style = {};
771
+ }
772
+ hasClass(className) {
773
+ return this.classes.includes(className);
774
+ }
775
+ /** Convert the fragment into a node. */
776
+ toNode() {
777
+ var frag = document.createDocumentFragment();
778
+ for (var i = 0; i < this.children.length; i++) {
779
+ frag.appendChild(this.children[i].toNode());
780
+ }
781
+ return frag;
782
+ }
783
+ /** Convert the fragment into HTML markup. */
784
+ toMarkup() {
785
+ var markup = "";
786
+ // Simply concatenate the markup for the children together.
787
+ for (var i = 0; i < this.children.length; i++) {
788
+ markup += this.children[i].toMarkup();
789
+ }
790
+ return markup;
791
+ }
792
+ /**
793
+ * Converts the math node into a string, similar to innerText. Applies to
794
+ * MathDomNode's only.
795
+ */
796
+ toText() {
797
+ // To avoid this, we would subclass documentFragment separately for
798
+ // MathML, but polyfills for subclassing is expensive per PR 1469.
799
+ // TODO(ts): Only works for ChildType = MathDomNode.
800
+ var toText = child => child.toText();
801
+ return this.children.map(toText).join("");
802
+ }
803
+ }
804
+
757
805
  /**
758
806
  * This file does conversion between units. In particular, it provides
759
807
  * calculateSize to convert other units into ems.
@@ -1250,6 +1298,13 @@ function assertSpan(group) {
1250
1298
  throw new Error("Expected span<HtmlDomNode> but got " + String(group) + ".");
1251
1299
  }
1252
1300
  }
1301
+ /**
1302
+ * Whether an HtmlDomNode has HtmlDomNode children.
1303
+ * HtmlDomNode is a base type representing a union of
1304
+ * SymbolNode, SvgSpan, DomSpan, Anchor, and documentFragment.
1305
+ * In the last three cases, the children are HtmlDomNode[].
1306
+ */
1307
+ var hasHtmlDomChildren = node => node instanceof Span || node instanceof Anchor || node instanceof DocumentFragment;
1253
1308
 
1254
1309
  // This file is GENERATED by buildMetrics.sh. DO NOT MODIFY.
1255
1310
  var fontMetricsData = {
@@ -4528,54 +4583,6 @@ var wideCharacterFont = (wideChar, mode) => {
4528
4583
  }
4529
4584
  };
4530
4585
 
4531
- /**
4532
- * This node represents a document fragment, which contains elements, but when
4533
- * placed into the DOM doesn't have any representation itself. It only contains
4534
- * children and doesn't have any DOM node properties.
4535
- */
4536
- class DocumentFragment {
4537
- // Never used; needed for satisfying interface.
4538
- constructor(children) {
4539
- this.children = children;
4540
- this.classes = [];
4541
- this.height = 0;
4542
- this.depth = 0;
4543
- this.maxFontSize = 0;
4544
- this.style = {};
4545
- }
4546
- hasClass(className) {
4547
- return this.classes.includes(className);
4548
- }
4549
- /** Convert the fragment into a node. */
4550
- toNode() {
4551
- var frag = document.createDocumentFragment();
4552
- for (var i = 0; i < this.children.length; i++) {
4553
- frag.appendChild(this.children[i].toNode());
4554
- }
4555
- return frag;
4556
- }
4557
- /** Convert the fragment into HTML markup. */
4558
- toMarkup() {
4559
- var markup = "";
4560
- // Simply concatenate the markup for the children together.
4561
- for (var i = 0; i < this.children.length; i++) {
4562
- markup += this.children[i].toMarkup();
4563
- }
4564
- return markup;
4565
- }
4566
- /**
4567
- * Converts the math node into a string, similar to innerText. Applies to
4568
- * MathDomNode's only.
4569
- */
4570
- toText() {
4571
- // To avoid this, we would subclass documentFragment separately for
4572
- // MathML, but polyfills for subclassing is expensive per PR 1469.
4573
- // TODO(ts): Only works for ChildType = MathDomNode.
4574
- var toText = child => child.toText();
4575
- return this.children.map(toText).join("");
4576
- }
4577
- }
4578
-
4579
4586
  /* eslint no-console:0 */
4580
4587
  /**
4581
4588
  * Looks up the given symbol in fontMetrics, after applying any symbol
@@ -6702,6 +6709,14 @@ function checkSymbolNodeType(node) {
6702
6709
  return null;
6703
6710
  }
6704
6711
 
6712
+ var getBaseSymbol = group => {
6713
+ if (group instanceof SymbolNode) {
6714
+ return group;
6715
+ }
6716
+ if (hasHtmlDomChildren(group) && group.children.length === 1) {
6717
+ return getBaseSymbol(group.children[0]);
6718
+ }
6719
+ };
6705
6720
  // NOTE: Unlike most `htmlBuilder`s, this one handles not only "accent", but
6706
6721
  // also "supsub" since an accent can affect super/subscripting.
6707
6722
  var htmlBuilder$a = (grp, options) => {
@@ -6743,17 +6758,10 @@ var htmlBuilder$a = (grp, options) => {
6743
6758
  // and the skewchar.
6744
6759
  var skew = 0;
6745
6760
  if (mustShift) {
6746
- // If the base is a character box, then we want the skew of the
6747
- // innermost character. To do that, we find the innermost character:
6748
- var baseChar = getBaseElem(base);
6749
- // Then, we render its group to get the symbol inside it
6750
- var baseGroup = buildGroup$1(baseChar, options.havingCrampedStyle());
6751
- // Finally, we pull the skew off of the symbol.
6752
- skew = assertSymbolDomNode(baseGroup).skew;
6753
- // Note that we now throw away baseGroup, because the layers we
6754
- // removed with getBaseElem might contain things like \color which
6755
- // we can't get rid of.
6756
- // TODO(emily): Find a better way to get the skew
6761
+ var _getBaseSymbol$skew, _getBaseSymbol;
6762
+ // Read the skew from the rendered base symbol.
6763
+ // This preserves font metrics from font wrappers like \mathbb.
6764
+ skew = (_getBaseSymbol$skew = (_getBaseSymbol = getBaseSymbol(body)) == null ? void 0 : _getBaseSymbol.skew) != null ? _getBaseSymbol$skew : 0;
6757
6765
  }
6758
6766
  var accentBelow = group.label === "\\c";
6759
6767
  // calculate the amount of space between the body and the accent
@@ -16361,7 +16369,7 @@ var renderToHTMLTree = function renderToHTMLTree(expression, options) {
16361
16369
  return renderError(error, expression, settings);
16362
16370
  }
16363
16371
  };
16364
- var version = "0.16.37";
16372
+ var version = "0.16.38";
16365
16373
  var __domTree = {
16366
16374
  Span,
16367
16375
  Anchor,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "katex",
3
- "version": "0.16.37",
3
+ "version": "0.16.38",
4
4
  "description": "Fast math typesetting for the web.",
5
5
  "main": "dist/katex.js",
6
6
  "types": "types/katex.d.ts",
package/src/domTree.ts CHANGED
@@ -621,3 +621,16 @@ export function assertSpan(
621
621
  throw new Error(`Expected span<HtmlDomNode> but got ${String(group)}.`);
622
622
  }
623
623
  }
624
+
625
+ /**
626
+ * Whether an HtmlDomNode has HtmlDomNode children.
627
+ * HtmlDomNode is a base type representing a union of
628
+ * SymbolNode, SvgSpan, DomSpan, Anchor, and documentFragment.
629
+ * In the last three cases, the children are HtmlDomNode[].
630
+ */
631
+ export const hasHtmlDomChildren = (
632
+ node: HtmlDomNode,
633
+ ): node is DomSpan | Anchor | documentFragment =>
634
+ node instanceof Span ||
635
+ node instanceof Anchor ||
636
+ node instanceof DocumentFragment;
@@ -1,10 +1,10 @@
1
1
  import defineFunction, {normalizeArgument} from "../defineFunction";
2
2
  import {makeOrd, makeSpan, makeVList, staticSvg, svgData} from "../buildCommon";
3
- import {getBaseElem, isCharacterBox} from "../utils";
3
+ import {isCharacterBox} from "../utils";
4
4
  import {MathNode} from "../mathMLTree";
5
5
  import {stretchyMathML, stretchySvg} from "../stretchy";
6
6
  import {assertNodeType} from "../parseNode";
7
- import {assertSpan, assertSymbolDomNode} from "../domTree";
7
+ import {assertSpan, assertSymbolDomNode, hasHtmlDomChildren, SymbolNode} from "../domTree";
8
8
  import {makeEm} from "../units";
9
9
 
10
10
  import * as html from "../buildHTML";
@@ -12,6 +12,16 @@ import * as mml from "../buildMathML";
12
12
 
13
13
  import type {ParseNode, AnyParseNode} from "../parseNode";
14
14
  import type {HtmlBuilderSupSub, MathMLBuilder} from "../defineFunction";
15
+ import type {HtmlDomNode} from "../domTree";
16
+
17
+ const getBaseSymbol = (group: HtmlDomNode): SymbolNode | undefined => {
18
+ if (group instanceof SymbolNode) {
19
+ return group;
20
+ }
21
+ if (hasHtmlDomChildren(group) && group.children.length === 1) {
22
+ return getBaseSymbol(group.children[0]);
23
+ }
24
+ };
15
25
 
16
26
  // NOTE: Unlike most `htmlBuilder`s, this one handles not only "accent", but
17
27
  // also "supsub" since an accent can affect super/subscripting.
@@ -61,17 +71,9 @@ export const htmlBuilder: HtmlBuilderSupSub<"accent"> = (grp, options) => {
61
71
  // and the skewchar.
62
72
  let skew = 0;
63
73
  if (mustShift) {
64
- // If the base is a character box, then we want the skew of the
65
- // innermost character. To do that, we find the innermost character:
66
- const baseChar = getBaseElem(base);
67
- // Then, we render its group to get the symbol inside it
68
- const baseGroup = html.buildGroup(baseChar, options.havingCrampedStyle());
69
- // Finally, we pull the skew off of the symbol.
70
- skew = assertSymbolDomNode(baseGroup).skew;
71
- // Note that we now throw away baseGroup, because the layers we
72
- // removed with getBaseElem might contain things like \color which
73
- // we can't get rid of.
74
- // TODO(emily): Find a better way to get the skew
74
+ // Read the skew from the rendered base symbol.
75
+ // This preserves font metrics from font wrappers like \mathbb.
76
+ skew = getBaseSymbol(body)?.skew ?? 0;
75
77
  }
76
78
 
77
79
  const accentBelow = group.label === "\\c";