scriptbase.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 a base class for SVGmsubsup, SVGmunderover
  19. * and their relatives. (Since munderover can become msubsup
  20. * when movablelimits is set, munderover needs to be able to
  21. * do the same thing as msubsup in some cases.)
  22. *
  23. * @author dpvc@mathjax.org (Davide Cervone)
  24. */
  25. import {SVGWrapper, SVGConstructor} from '../Wrapper.js';
  26. import {CommonScriptbaseMixin} from '../../common/Wrappers/scriptbase.js';
  27. /*****************************************************************/
  28. /**
  29. * A base class for msup/msub/msubsup and munder/mover/munderover
  30. * wrapper implementations
  31. *
  32. * @template N The HTMLElement node class
  33. * @template T The Text node class
  34. * @template D The Document class
  35. */
  36. // @ts-ignore
  37. export class SVGscriptbase<N, T, D> extends
  38. CommonScriptbaseMixin<SVGWrapper<any, any, any>, SVGConstructor<any, any, any>>(SVGWrapper) {
  39. /**
  40. * The scriptbase wrapper
  41. */
  42. public static kind = 'scriptbase';
  43. /**
  44. * This gives the common output for msub and msup. It is overridden
  45. * for all the others (msubsup, munder, mover, munderover).
  46. *
  47. * @override
  48. */
  49. public toSVG(parent: N) {
  50. const svg = this.standardSVGnode(parent);
  51. const w = this.getBaseWidth();
  52. const [x, v] = this.getOffset();
  53. this.baseChild.toSVG(svg);
  54. this.scriptChild.toSVG(svg);
  55. this.scriptChild.place(w + x, v);
  56. }
  57. }