mglyph.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 CHTMLmglyph wrapper for the MmlMglyph object
  19. *
  20. * @author dpvc@mathjax.org (Davide Cervone)
  21. */
  22. import {CHTMLWrapper, CHTMLConstructor} from '../Wrapper.js';
  23. import {CommonMglyphMixin} from '../../common/Wrappers/mglyph.js';
  24. import {MmlMglyph} from '../../../core/MmlTree/MmlNodes/mglyph.js';
  25. import {CHTMLTextNode} from './TextNode.js';
  26. import {StyleList, StyleData} from '../../../util/StyleList.js';
  27. /*****************************************************************/
  28. /**
  29. * The CHTMLmglyph wrapper for the MmlMglyph object
  30. *
  31. * @template N The HTMLElement node class
  32. * @template T The Text node class
  33. * @template D The Document class
  34. */
  35. // @ts-ignore
  36. export class CHTMLmglyph<N, T, D> extends
  37. CommonMglyphMixin<CHTMLConstructor<any, any, any>>(CHTMLWrapper) {
  38. /**
  39. * The mglyph wrapper
  40. */
  41. public static kind = MmlMglyph.prototype.kind;
  42. /**
  43. * @override
  44. */
  45. public static styles: StyleList = {
  46. 'mjx-mglyph > img': {
  47. display: 'inline-block',
  48. border: 0,
  49. padding: 0
  50. }
  51. };
  52. /**
  53. * @override
  54. */
  55. public toCHTML(parent: N) {
  56. const chtml = this.standardCHTMLnode(parent);
  57. if (this.charWrapper) {
  58. (this.charWrapper as CHTMLTextNode<N, T, D>).toCHTML(chtml);
  59. return;
  60. }
  61. const {src, alt} = this.node.attributes.getList('src', 'alt');
  62. const styles: StyleData = {
  63. width: this.em(this.width),
  64. height: this.em(this.height)
  65. };
  66. if (this.valign) {
  67. styles.verticalAlign = this.em(this.valign);
  68. }
  69. const img = this.html('img', {src: src, style: styles, alt: alt, title: alt});
  70. this.adaptor.append(chtml, img);
  71. }
  72. }