msubsup.ts 3.8 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 CHTMLmsubsup wrapper for the MmlMsubsup object
  19. * and the special cases CHTMLmsub and CHTMLmsup
  20. *
  21. * @author dpvc@mathjax.org (Davide Cervone)
  22. */
  23. import {CHTMLWrapper, Constructor} from '../Wrapper.js';
  24. import {CHTMLscriptbase} from './scriptbase.js';
  25. import {CommonMsubMixin} from '../../common/Wrappers/msubsup.js';
  26. import {CommonMsupMixin} from '../../common/Wrappers/msubsup.js';
  27. import {CommonMsubsupMixin} from '../../common/Wrappers/msubsup.js';
  28. import {MmlMsubsup, MmlMsub, MmlMsup} from '../../../core/MmlTree/MmlNodes/msubsup.js';
  29. import {StyleList} from '../../../util/StyleList.js';
  30. /*****************************************************************/
  31. /**
  32. * The CHTMLmsub wrapper for the MmlMsub object
  33. *
  34. * @template N The HTMLElement node class
  35. * @template T The Text node class
  36. * @template D The Document class
  37. */
  38. // @ts-ignore
  39. export class CHTMLmsub<N, T, D> extends
  40. CommonMsubMixin<CHTMLWrapper<any, any, any>, Constructor<CHTMLscriptbase<any, any, any>>>(CHTMLscriptbase) {
  41. /**
  42. * The msub wrapper
  43. */
  44. public static kind = MmlMsub.prototype.kind;
  45. }
  46. /*****************************************************************/
  47. /**
  48. * The CHTMLmsup wrapper for the MmlMsup object
  49. *
  50. * @template N The HTMLElement node class
  51. * @template T The Text node class
  52. * @template D The Document class
  53. */
  54. // @ts-ignore
  55. export class CHTMLmsup<N, T, D> extends
  56. CommonMsupMixin<CHTMLWrapper<any, any, any>, Constructor<CHTMLscriptbase<any, any, any>>>(CHTMLscriptbase) {
  57. /**
  58. * The msup wrapper
  59. */
  60. public static kind = MmlMsup.prototype.kind;
  61. }
  62. /*****************************************************************/
  63. /**
  64. * The CHTMLmsubsup wrapper for the MmlMsubsup object
  65. *
  66. * @template N The HTMLElement node class
  67. * @template T The Text node class
  68. * @template D The Document class
  69. */
  70. // @ts-ignore
  71. export class CHTMLmsubsup<N, T, D> extends
  72. CommonMsubsupMixin<CHTMLWrapper<any, any, any>, Constructor<CHTMLscriptbase<any, any, any>>>(CHTMLscriptbase) {
  73. /**
  74. * The msubsup wrapper
  75. */
  76. public static kind = MmlMsubsup.prototype.kind;
  77. /**
  78. * @override
  79. */
  80. public static styles: StyleList = {
  81. 'mjx-script': {
  82. display: 'inline-block',
  83. 'padding-right': '.05em', // scriptspace
  84. 'padding-left': '.033em' // extra_ic
  85. },
  86. 'mjx-script > mjx-spacer': {
  87. display: 'block'
  88. }
  89. };
  90. /**
  91. * @override
  92. */
  93. public toCHTML(parent: N) {
  94. const adaptor = this.adaptor;
  95. const chtml = this.standardCHTMLnode(parent);
  96. const [base, sup, sub] = [this.baseChild, this.supChild, this.subChild];
  97. const [ , v, q] = this.getUVQ();
  98. const style = {'vertical-align': this.em(v)};
  99. base.toCHTML(chtml);
  100. const stack = adaptor.append(chtml, this.html('mjx-script', {style})) as N;
  101. sup.toCHTML(stack);
  102. adaptor.append(stack, this.html('mjx-spacer', {style: {'margin-top': this.em(q)}}));
  103. sub.toCHTML(stack);
  104. const ic = this.getAdjustedIc();
  105. if (ic) {
  106. adaptor.setStyle(sup.chtml, 'marginLeft', this.em(ic / sup.bbox.rscale));
  107. }
  108. if (this.baseRemoveIc) {
  109. adaptor.setStyle(stack, 'marginLeft', this.em(-this.baseIc));
  110. }
  111. }
  112. }