munderover.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*************************************************************
  2. *
  3. * Copyright (c) 2018-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 SVGmunderover wrapper for the MmlMunderover object
  19. * and the special cases SVGmunder and SVGmsup
  20. *
  21. * @author dpvc@mathjax.org (Davide Cervone)
  22. */
  23. import {SVGWrapper, Constructor} from '../Wrapper.js';
  24. import {SVGmsubsup, SVGmsub, SVGmsup} from './msubsup.js';
  25. import {CommonMunderMixin} from '../../common/Wrappers/munderover.js';
  26. import { CommonMoverMixin} from '../../common/Wrappers/munderover.js';
  27. import {CommonMunderoverMixin} from '../../common/Wrappers/munderover.js';
  28. import {MmlMunderover, MmlMunder, MmlMover} from '../../../core/MmlTree/MmlNodes/munderover.js';
  29. /*****************************************************************/
  30. /**
  31. * The SVGmunder wrapper for the MmlMunder 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 SVGmunder<N, T, D> extends
  39. CommonMunderMixin<SVGWrapper<any, any, any>, Constructor<SVGmsub<any, any, any>>>(SVGmsub) {
  40. /**
  41. * The munder wrapper
  42. */
  43. public static kind = MmlMunder.prototype.kind;
  44. /**
  45. * @override
  46. */
  47. public toSVG(parent: N) {
  48. if (this.hasMovableLimits()) {
  49. super.toSVG(parent);
  50. return;
  51. }
  52. const svg = this.standardSVGnode(parent);
  53. const [base, script] = [this.baseChild, this.scriptChild];
  54. const [bbox, sbox] = [base.getOuterBBox(), script.getOuterBBox()];
  55. base.toSVG(svg);
  56. script.toSVG(svg);
  57. const delta = (this.isLineBelow ? 0 : this.getDelta(true));
  58. const v = this.getUnderKV(bbox, sbox)[1];
  59. const [bx, sx] = this.getDeltaW([bbox, sbox], [0, -delta]);
  60. base.place(bx, 0);
  61. script.place(sx, v);
  62. }
  63. }
  64. /*****************************************************************/
  65. /**
  66. * The SVGmover wrapper for the MmlMover object
  67. *
  68. * @template N The HTMLElement node class
  69. * @template T The Text node class
  70. * @template D The Document class
  71. */
  72. // @ts-ignore
  73. export class SVGmover<N, T, D> extends
  74. CommonMoverMixin<SVGWrapper<any, any, any>, Constructor<SVGmsup<any, any, any>>>(SVGmsup) {
  75. /**
  76. * The mover wrapper
  77. */
  78. public static kind = MmlMover.prototype.kind;
  79. /**
  80. * @override
  81. */
  82. public toSVG(parent: N) {
  83. if (this.hasMovableLimits()) {
  84. super.toSVG(parent);
  85. return;
  86. }
  87. const svg = this.standardSVGnode(parent);
  88. const [base, script] = [this.baseChild, this.scriptChild];
  89. const [bbox, sbox] = [base.getOuterBBox(), script.getOuterBBox()];
  90. base.toSVG(svg);
  91. script.toSVG(svg);
  92. const delta = (this.isLineAbove ? 0 : this.getDelta());
  93. const u = this.getOverKU(bbox, sbox)[1];
  94. const [bx, sx] = this.getDeltaW([bbox, sbox], [0, delta]);
  95. base.place(bx, 0);
  96. script.place(sx, u);
  97. }
  98. }
  99. /*****************************************************************/
  100. /*
  101. * The SVGmunderover wrapper for the MmlMunderover object
  102. *
  103. * @template N The HTMLElement node class
  104. * @template T The Text node class
  105. * @template D The Document class
  106. */
  107. // @ts-ignore
  108. export class SVGmunderover<N, T, D> extends
  109. CommonMunderoverMixin<SVGWrapper<any, any, any>, Constructor<SVGmsubsup<any, any, any>>>(SVGmsubsup) {
  110. /**
  111. * The munderover wrapper
  112. */
  113. public static kind = MmlMunderover.prototype.kind;
  114. /**
  115. * @override
  116. */
  117. public toSVG(parent: N) {
  118. if (this.hasMovableLimits()) {
  119. super.toSVG(parent);
  120. return;
  121. }
  122. const svg = this.standardSVGnode(parent);
  123. const [base, over, under] = [this.baseChild, this.overChild, this.underChild];
  124. const [bbox, obox, ubox] = [base.getOuterBBox(), over.getOuterBBox(), under.getOuterBBox()];
  125. base.toSVG(svg);
  126. under.toSVG(svg);
  127. over.toSVG(svg);
  128. const delta = this.getDelta();
  129. const u = this.getOverKU(bbox, obox)[1];
  130. const v = this.getUnderKV(bbox, ubox)[1];
  131. const [bx, ux, ox] = this.getDeltaW([bbox, ubox, obox],
  132. [0, this.isLineBelow ? 0 : -delta, this.isLineAbove ? 0 : delta]);
  133. base.place(bx, 0);
  134. under.place(ux, v);
  135. over.place(ox, u);
  136. }
  137. }