semantics.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 CHTMLsemantics wrapper for the MmlSemantics object
  19. * and the associated wrappers for annotations
  20. *
  21. * @author dpvc@mathjax.org (Davide Cervone)
  22. */
  23. import {CHTMLWrapper, CHTMLConstructor} from '../Wrapper.js';
  24. import {CommonSemanticsMixin} from '../../common/Wrappers/semantics.js';
  25. import {BBox} from '../../../util/BBox.js';
  26. import {MmlSemantics, MmlAnnotation, MmlAnnotationXML} from '../../../core/MmlTree/MmlNodes/semantics.js';
  27. import {XMLNode} from '../../../core/MmlTree/MmlNode.js';
  28. import {StyleList} from '../../../util/StyleList.js';
  29. /*****************************************************************/
  30. /**
  31. * The CHTMLsemantics wrapper for the MmlSemantics object
  32. *
  33. * @template N The HTMLElement node class
  34. * @template T The Text node class
  35. * @template D The Document class
  36. */
  37. // @ts-ignore
  38. export class CHTMLsemantics<N, T, D> extends
  39. CommonSemanticsMixin<CHTMLConstructor<any, any, any>>(CHTMLWrapper) {
  40. /**
  41. * The semantics wrapper
  42. */
  43. public static kind = MmlSemantics.prototype.kind;
  44. /**
  45. * @override
  46. */
  47. public toCHTML(parent: N) {
  48. const chtml = this.standardCHTMLnode(parent);
  49. if (this.childNodes.length) {
  50. this.childNodes[0].toCHTML(chtml);
  51. }
  52. }
  53. }
  54. /*****************************************************************/
  55. /**
  56. * The CHTMLannotation wrapper for the MmlAnnotation object
  57. *
  58. * @template N The HTMLElement node class
  59. * @template T The Text node class
  60. * @template D The Document class
  61. */
  62. export class CHTMLannotation<N, T, D> extends CHTMLWrapper<N, T, D> {
  63. /**
  64. * The annotation wrapper
  65. */
  66. public static kind = MmlAnnotation.prototype.kind;
  67. /**
  68. * @override
  69. */
  70. public toCHTML(parent: N) {
  71. // FIXME: output as plain text
  72. super.toCHTML(parent);
  73. }
  74. /**
  75. * @override
  76. */
  77. public computeBBox() {
  78. // FIXME: compute using the DOM, if possible
  79. return this.bbox;
  80. }
  81. }
  82. /*****************************************************************/
  83. /**
  84. * The CHTMLannotationXML wrapper for the MmlAnnotationXML object
  85. *
  86. * @template N The HTMLElement node class
  87. * @template T The Text node class
  88. * @template D The Document class
  89. */
  90. export class CHTMLannotationXML<N, T, D> extends CHTMLWrapper<N, T, D> {
  91. /**
  92. * The annotation-xml wrapper
  93. */
  94. public static kind = MmlAnnotationXML.prototype.kind;
  95. /**
  96. * @override
  97. */
  98. public static styles: StyleList = {
  99. 'mjx-annotation-xml': {
  100. 'font-family': 'initial',
  101. 'line-height': 'normal'
  102. }
  103. };
  104. }
  105. /*****************************************************************/
  106. /**
  107. * The CHTMLxml wrapper for the XMLNode object
  108. *
  109. * @template N The HTMLElement node class
  110. * @template T The Text node class
  111. * @template D The Document class
  112. */
  113. export class CHTMLxml<N, T, D> extends CHTMLWrapper<N, T, D> {
  114. /**
  115. * The xml wrapper
  116. */
  117. public static kind = XMLNode.prototype.kind;
  118. /**
  119. * Don't set up inline-block styles for this
  120. */
  121. public static autoStyle = false;
  122. /**
  123. * @override
  124. */
  125. public toCHTML(parent: N) {
  126. this.chtml = this.adaptor.append(parent, this.adaptor.clone((this.node as XMLNode).getXML() as N));
  127. }
  128. /**
  129. * @override
  130. */
  131. public computeBBox(bbox: BBox, _recompute: boolean = false) {
  132. const {w, h, d} = this.jax.measureXMLnode((this.node as XMLNode).getXML() as N);
  133. bbox.w = w;
  134. bbox.h = h;
  135. bbox.d = d;
  136. }
  137. /**
  138. * @override
  139. */
  140. protected getStyles() {}
  141. /**
  142. * @override
  143. */
  144. protected getScale() {}
  145. /**
  146. * @override
  147. */
  148. protected getVariant() {}
  149. }