msqrt.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*************************************************************
  2. *
  3. * Copyright (c) 2017-2022 The MathJax Consortium
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /**
  18. * @fileoverview Implements the CHTMLmsqrt wrapper for the MmlMsqrt object
  19. *
  20. * @author dpvc@mathjax.org (Davide Cervone)
  21. */
  22. import {CHTMLWrapper, CHTMLConstructor} from '../Wrapper.js';
  23. import {CommonMsqrtMixin} from '../../common/Wrappers/msqrt.js';
  24. import {CHTMLmo} from './mo.js';
  25. import {BBox} from '../../../util/BBox.js';
  26. import {MmlMsqrt} from '../../../core/MmlTree/MmlNodes/msqrt.js';
  27. import {StyleList} from '../../../util/StyleList.js';
  28. /*****************************************************************/
  29. /**
  30. * The CHTMLmsqrt wrapper for the MmlMsqrt object
  31. *
  32. * @template N The HTMLElement node class
  33. * @template T The Text node class
  34. * @template D The Document class
  35. */
  36. export class CHTMLmsqrt<N, T, D> extends CommonMsqrtMixin<CHTMLConstructor<any, any, any>>(CHTMLWrapper) {
  37. /**
  38. * The msqrt wrapper
  39. */
  40. public static kind = MmlMsqrt.prototype.kind;
  41. /**
  42. * @override
  43. */
  44. public static styles: StyleList = {
  45. 'mjx-root': {
  46. display: 'inline-block',
  47. 'white-space': 'nowrap'
  48. },
  49. 'mjx-surd': {
  50. display: 'inline-block',
  51. 'vertical-align': 'top'
  52. },
  53. 'mjx-sqrt': {
  54. display: 'inline-block',
  55. 'padding-top': '.07em'
  56. },
  57. 'mjx-sqrt > mjx-box': {
  58. 'border-top': '.07em solid'
  59. },
  60. 'mjx-sqrt.mjx-tall > mjx-box': {
  61. 'padding-left': '.3em',
  62. 'margin-left': '-.3em'
  63. }
  64. };
  65. /**
  66. * @override
  67. */
  68. public toCHTML(parent: N) {
  69. const surd = this.childNodes[this.surd] as CHTMLmo<N, T, D>;
  70. const base = this.childNodes[this.base];
  71. //
  72. // Get the parameters for the spacing of the parts
  73. //
  74. const sbox = surd.getBBox();
  75. const bbox = base.getOuterBBox();
  76. const [ , q] = this.getPQ(sbox);
  77. const t = this.font.params.rule_thickness;
  78. const H = bbox.h + q + t;
  79. //
  80. // Create the HTML structure for the root
  81. //
  82. const CHTML = this.standardCHTMLnode(parent);
  83. let SURD, BASE, ROOT, root;
  84. if (this.root != null) {
  85. ROOT = this.adaptor.append(CHTML, this.html('mjx-root')) as N;
  86. root = this.childNodes[this.root];
  87. }
  88. const SQRT = this.adaptor.append(CHTML, this.html('mjx-sqrt', {}, [
  89. SURD = this.html('mjx-surd'),
  90. BASE = this.html('mjx-box', {style: {paddingTop: this.em(q)}})
  91. ])) as N;
  92. //
  93. // Add the child content
  94. //
  95. this.addRoot(ROOT, root, sbox, H);
  96. surd.toCHTML(SURD);
  97. base.toCHTML(BASE);
  98. if (surd.size < 0) {
  99. //
  100. // size < 0 means surd is multi-character. The angle glyph at the
  101. // top is hard to align with the horizontal line, so overlap them
  102. // using CSS.
  103. //
  104. this.adaptor.addClass(SQRT, 'mjx-tall');
  105. }
  106. }
  107. /**
  108. * Add root HTML (overridden in mroot)
  109. *
  110. * @param {N} ROOT The container for the root
  111. * @param {CHTMLWrapper} root The wrapped MML root content
  112. * @param {BBox} sbox The bounding box of the surd
  113. * @param {number} H The height of the root as a whole
  114. */
  115. protected addRoot(_ROOT: N, _root: CHTMLWrapper<N, T, D>, _sbox: BBox, _H: number) {
  116. }
  117. }