mfenced.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 SVGmfenced wrapper for the MmlMfenced object
  19. *
  20. * @author dpvc@mathjax.org (Davide Cervone)
  21. */
  22. import {SVGWrapper, SVGConstructor} from '../Wrapper.js';
  23. import {CommonMfencedMixin} from '../../common/Wrappers/mfenced.js';
  24. import {MmlMfenced} from '../../../core/MmlTree/MmlNodes/mfenced.js';
  25. import {SVGinferredMrow} from './mrow.js';
  26. /*****************************************************************/
  27. /**
  28. * The SVGmfenced wrapper for the MmlMfenced object
  29. *
  30. * @template N The HTMLElement node class
  31. * @template T The Text node class
  32. * @template D The Document class
  33. */
  34. export class SVGmfenced<N, T, D> extends CommonMfencedMixin<SVGConstructor<any, any, any>>(SVGWrapper) {
  35. /**
  36. * The mfenced wrapper
  37. */
  38. public static kind = MmlMfenced.prototype.kind;
  39. /**
  40. * An mrow used to render the result
  41. */
  42. public mrow: SVGinferredMrow<N, T, D>;
  43. /**
  44. * @override
  45. */
  46. public toSVG(parent: N) {
  47. const svg = this.standardSVGnode(parent);
  48. this.setChildrenParent(this.mrow); // temporarily change parents to the mrow
  49. this.mrow.toSVG(svg);
  50. this.setChildrenParent(this); // put back the correct parents
  51. }
  52. /**
  53. * @param {SVGWrapper} parent The parent to use for the fenced children
  54. */
  55. protected setChildrenParent(parent: SVGWrapper<N, T, D>) {
  56. for (const child of this.childNodes) {
  57. child.parent = parent;
  58. }
  59. }
  60. }