mtr.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 CHTMLmtr wrapper for the MmlMtr object
  19. * and CHTMLmlabeledtr for MmlMlabeledtr
  20. *
  21. * @author dpvc@mathjax.org (Davide Cervone)
  22. */
  23. import {CHTMLWrapper, CHTMLConstructor, Constructor} from '../Wrapper.js';
  24. import {CommonMtrMixin} from '../../common/Wrappers/mtr.js';
  25. import {CommonMlabeledtrMixin} from '../../common/Wrappers/mtr.js';
  26. import {CHTMLmtable} from './mtable.js';
  27. import {CHTMLmtd} from './mtd.js';
  28. import {MmlMtr, MmlMlabeledtr} from '../../../core/MmlTree/MmlNodes/mtr.js';
  29. import {StyleList} from '../../../util/StyleList.js';
  30. /*****************************************************************/
  31. /**
  32. * The CHTMLmtr wrapper for the MmlMtr 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 CHTMLmtr<N, T, D> extends
  40. CommonMtrMixin<CHTMLmtd<any, any, any>, CHTMLConstructor<any, any, any>>(CHTMLWrapper) {
  41. /**
  42. * The mtr wrapper
  43. */
  44. public static kind = MmlMtr.prototype.kind;
  45. /**
  46. * @override
  47. */
  48. public static styles: StyleList = {
  49. 'mjx-mtr': {
  50. display: 'table-row',
  51. },
  52. 'mjx-mtr[rowalign="top"] > mjx-mtd': {
  53. 'vertical-align': 'top'
  54. },
  55. 'mjx-mtr[rowalign="center"] > mjx-mtd': {
  56. 'vertical-align': 'middle'
  57. },
  58. 'mjx-mtr[rowalign="bottom"] > mjx-mtd': {
  59. 'vertical-align': 'bottom'
  60. },
  61. 'mjx-mtr[rowalign="baseline"] > mjx-mtd': {
  62. 'vertical-align': 'baseline'
  63. },
  64. 'mjx-mtr[rowalign="axis"] > mjx-mtd': {
  65. 'vertical-align': '.25em'
  66. }
  67. };
  68. /**
  69. * @override
  70. */
  71. public toCHTML(parent: N) {
  72. super.toCHTML(parent);
  73. const align = this.node.attributes.get('rowalign') as string;
  74. if (align !== 'baseline') {
  75. this.adaptor.setAttribute(this.chtml, 'rowalign', align);
  76. }
  77. }
  78. }
  79. /*****************************************************************/
  80. /**
  81. * The CHTMLlabeledmtr wrapper for the MmlMlabeledtr object
  82. *
  83. * @template N The HTMLElement node class
  84. * @template T The Text node class
  85. * @template D The Document class
  86. */
  87. export class CHTMLmlabeledtr<N, T, D> extends
  88. CommonMlabeledtrMixin<CHTMLmtd<any, any, any>, Constructor<CHTMLmtr<any, any, any>>>(CHTMLmtr) {
  89. /**
  90. * The mlabeledtr wrapper
  91. */
  92. public static kind = MmlMlabeledtr.prototype.kind;
  93. /**
  94. * @override
  95. */
  96. public static styles: StyleList = {
  97. 'mjx-mlabeledtr': {
  98. display: 'table-row'
  99. },
  100. 'mjx-mlabeledtr[rowalign="top"] > mjx-mtd': {
  101. 'vertical-align': 'top'
  102. },
  103. 'mjx-mlabeledtr[rowalign="center"] > mjx-mtd': {
  104. 'vertical-align': 'middle'
  105. },
  106. 'mjx-mlabeledtr[rowalign="bottom"] > mjx-mtd': {
  107. 'vertical-align': 'bottom'
  108. },
  109. 'mjx-mlabeledtr[rowalign="baseline"] > mjx-mtd': {
  110. 'vertical-align': 'baseline'
  111. },
  112. 'mjx-mlabeledtr[rowalign="axis"] > mjx-mtd': {
  113. 'vertical-align': '.25em'
  114. }
  115. };
  116. /**
  117. * @override
  118. */
  119. public toCHTML(parent: N) {
  120. super.toCHTML(parent);
  121. const child = this.adaptor.firstChild(this.chtml) as N;
  122. if (child) {
  123. //
  124. // Remove label and put it into the labels box inside a row
  125. //
  126. this.adaptor.remove(child);
  127. const align = this.node.attributes.get('rowalign') as string;
  128. const attr = (align !== 'baseline' && align !== 'axis' ? {rowalign: align} : {});
  129. const row = this.html('mjx-mtr', attr, [child]);
  130. this.adaptor.append((this.parent as CHTMLmtable<N, T, D>).labels, row);
  131. }
  132. }
  133. /**
  134. * @override
  135. */
  136. public markUsed() {
  137. super.markUsed();
  138. this.jax.wrapperUsage.add(CHTMLmtr.kind);
  139. }
  140. }