mtd.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 CHTMLmtd wrapper for the MmlMtd object
  19. *
  20. * @author dpvc@mathjax.org (Davide Cervone)
  21. */
  22. import {CHTMLWrapper, CHTMLConstructor} from '../Wrapper.js';
  23. import {CommonMtdMixin} from '../../common/Wrappers/mtd.js';
  24. import {MmlMtd} from '../../../core/MmlTree/MmlNodes/mtd.js';
  25. import {StyleList} from '../../../util/StyleList.js';
  26. /*****************************************************************/
  27. /**
  28. * The CHTMLmtd wrapper for the MmlMtd object
  29. *
  30. * @template N The HTMLElement node class
  31. * @template T The Text node class
  32. * @template D The Document class
  33. */
  34. // @ts-ignore
  35. export class CHTMLmtd<N, T, D> extends
  36. CommonMtdMixin<CHTMLConstructor<any, any, any>>(CHTMLWrapper) {
  37. /**
  38. * The mtd wrapper
  39. */
  40. public static kind = MmlMtd.prototype.kind;
  41. /**
  42. * @override
  43. */
  44. public static styles: StyleList = {
  45. 'mjx-mtd': {
  46. display: 'table-cell',
  47. 'text-align': 'center',
  48. 'padding': '.215em .4em'
  49. },
  50. 'mjx-mtd:first-child': {
  51. 'padding-left': 0
  52. },
  53. 'mjx-mtd:last-child': {
  54. 'padding-right': 0
  55. },
  56. 'mjx-mtable > * > mjx-itable > *:first-child > mjx-mtd': {
  57. 'padding-top': 0
  58. },
  59. 'mjx-mtable > * > mjx-itable > *:last-child > mjx-mtd': {
  60. 'padding-bottom': 0
  61. },
  62. 'mjx-tstrut': {
  63. display: 'inline-block',
  64. height: '1em',
  65. 'vertical-align': '-.25em'
  66. },
  67. 'mjx-labels[align="left"] > mjx-mtr > mjx-mtd': {
  68. 'text-align': 'left'
  69. },
  70. 'mjx-labels[align="right"] > mjx-mtr > mjx-mtd': {
  71. 'text-align': 'right'
  72. },
  73. 'mjx-mtd[extra]': {
  74. padding: 0
  75. },
  76. 'mjx-mtd[rowalign="top"]': {
  77. 'vertical-align': 'top'
  78. },
  79. 'mjx-mtd[rowalign="center"]': {
  80. 'vertical-align': 'middle'
  81. },
  82. 'mjx-mtd[rowalign="bottom"]': {
  83. 'vertical-align': 'bottom'
  84. },
  85. 'mjx-mtd[rowalign="baseline"]': {
  86. 'vertical-align': 'baseline'
  87. },
  88. 'mjx-mtd[rowalign="axis"]': {
  89. 'vertical-align': '.25em'
  90. }
  91. };
  92. /**
  93. * @override
  94. */
  95. public toCHTML(parent: N) {
  96. super.toCHTML(parent);
  97. const ralign = this.node.attributes.get('rowalign') as string;
  98. const calign = this.node.attributes.get('columnalign') as string;
  99. const palign = this.parent.node.attributes.get('rowalign') as string;
  100. if (ralign !== palign) {
  101. this.adaptor.setAttribute(this.chtml, 'rowalign', ralign);
  102. }
  103. if (calign !== 'center' &&
  104. (this.parent.kind !== 'mlabeledtr' || this !== this.parent.childNodes[0] ||
  105. calign !== this.parent.parent.node.attributes.get('side'))) {
  106. this.adaptor.setStyle(this.chtml, 'textAlign', calign);
  107. }
  108. //
  109. // If we are using minimum row heights,
  110. // Include a strut to force minimum height and depth
  111. //
  112. if (this.parent.parent.node.getProperty('useHeight')) {
  113. this.adaptor.append(this.chtml, this.html('mjx-tstrut'));
  114. }
  115. }
  116. }