case_multiindex.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.CaseMultiindex = void 0;
  4. const DomUtil = require("../common/dom_util.js");
  5. const semantic_meaning_js_1 = require("../semantic_tree/semantic_meaning.js");
  6. const semantic_util_js_1 = require("../semantic_tree/semantic_util.js");
  7. const abstract_enrich_case_js_1 = require("./abstract_enrich_case.js");
  8. const EnrichMathml = require("./enrich_mathml.js");
  9. const enrich_attr_js_1 = require("./enrich_attr.js");
  10. class CaseMultiindex extends abstract_enrich_case_js_1.AbstractEnrichCase {
  11. static multiscriptIndex(index) {
  12. if (index.type === semantic_meaning_js_1.SemanticType.PUNCTUATED &&
  13. index.contentNodes[0].role === semantic_meaning_js_1.SemanticRole.DUMMY) {
  14. return EnrichMathml.collapsePunctuated(index);
  15. }
  16. EnrichMathml.walkTree(index);
  17. return index.id;
  18. }
  19. static createNone_(semantic) {
  20. const newNode = DomUtil.createElement('none');
  21. if (semantic) {
  22. (0, enrich_attr_js_1.setAttributes)(newNode, semantic);
  23. }
  24. newNode.setAttribute(enrich_attr_js_1.Attribute.ADDED, 'true');
  25. return newNode;
  26. }
  27. constructor(semantic) {
  28. super(semantic);
  29. this.mml = semantic.mathmlTree;
  30. }
  31. completeMultiscript(rightIndices, leftIndices) {
  32. const children = DomUtil.toArray(this.mml.childNodes).slice(1);
  33. let childCounter = 0;
  34. const completeIndices = (indices) => {
  35. for (const index of indices) {
  36. const child = children[childCounter];
  37. if (child && index === parseInt(child.getAttribute(enrich_attr_js_1.Attribute.ID))) {
  38. child.setAttribute(enrich_attr_js_1.Attribute.PARENT, this.semantic.id.toString());
  39. childCounter++;
  40. }
  41. else if (!child ||
  42. index !==
  43. parseInt(EnrichMathml.getInnerNode(child).getAttribute(enrich_attr_js_1.Attribute.ID))) {
  44. const query = this.semantic.querySelectorAll((x) => x.id === index);
  45. this.mml.insertBefore(CaseMultiindex.createNone_(query[0]), child || null);
  46. }
  47. else {
  48. EnrichMathml.getInnerNode(child).setAttribute(enrich_attr_js_1.Attribute.PARENT, this.semantic.id.toString());
  49. childCounter++;
  50. }
  51. }
  52. };
  53. completeIndices(rightIndices);
  54. if (children[childCounter] &&
  55. DomUtil.tagName(children[childCounter]) !== semantic_util_js_1.MMLTAGS.MPRESCRIPTS) {
  56. this.mml.insertBefore(children[childCounter], DomUtil.createElement('mprescripts'));
  57. }
  58. else {
  59. childCounter++;
  60. }
  61. completeIndices(leftIndices);
  62. }
  63. }
  64. exports.CaseMultiindex = CaseMultiindex;