merror.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 SVGmerror wrapper for the MmlMerror object
  19. *
  20. * @author dpvc@mathjax.org (Davide Cervone)
  21. */
  22. import {SVGWrapper} from '../Wrapper.js';
  23. import {MmlMerror} from '../../../core/MmlTree/MmlNodes/merror.js';
  24. import {StyleList} from '../../../util/StyleList.js';
  25. /*****************************************************************/
  26. /**
  27. * The SVGmerror wrapper for the MmlMerror object
  28. *
  29. * @template N The HTMLElement node class
  30. * @template T The Text node class
  31. * @template D The Document class
  32. */
  33. export class SVGmerror<N, T, D> extends SVGWrapper<N, T, D> {
  34. /**
  35. * The merror wrapper
  36. */
  37. public static kind = MmlMerror.prototype.kind;
  38. /**
  39. * @override
  40. */
  41. public static styles: StyleList = {
  42. 'g[data-mml-node="merror"] > g': {
  43. fill: 'red',
  44. stroke: 'red'
  45. },
  46. 'g[data-mml-node="merror"] > rect[data-background]': {
  47. fill: 'yellow',
  48. stroke: 'none'
  49. }
  50. };
  51. /**
  52. * @override
  53. */
  54. public toSVG(parent: N) {
  55. const svg = this.standardSVGnode(parent);
  56. const {h, d, w} = this.getBBox();
  57. this.adaptor.append(this.element, this.svg('rect', {
  58. 'data-background': true,
  59. width: this.fixed(w), height: this.fixed(h + d), y: this.fixed(-d)
  60. }));
  61. const title = this.node.attributes.get('title') as string;
  62. if (title) {
  63. this.adaptor.append(this.element, this.svg('title', {}, [this.adaptor.text(title)]));
  64. }
  65. this.addChildren(svg);
  66. }
  67. }