Debian Codegraph @

ts/enrich_mathml/case_embellished.ts

raw symbols SCIP
1 //
2 // Copyright 2015-21 Volker Sorge
3 //
4 // Licensed under the Apache on 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15
16 /**
17 * @file Specialist computations to deal with embellished fences.
18 * @author [email protected] (Volker Sorge)
19 */
20
21 import * as DomUtilscip-typescript npm . . common/`dom_util.ts`/ from '../common/dom_util.js'scip-typescript npm . . common/`dom_util.ts`/;
22 import {
23 SemanticRolescip-typescript npm . . semantic_tree/`semantic_meaning.ts`/SemanticRole#,
24 SemanticTypescip-typescript npm . . semantic_tree/`semantic_meaning.ts`/SemanticType#
25 } from '../semantic_tree/semantic_meaning.js'scip-typescript npm . . semantic_tree/`semantic_meaning.ts`/;
26 import { SemanticNodescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode# } from '../semantic_tree/semantic_node.js'scip-typescript npm . . semantic_tree/`semantic_node.ts`/;
27 import { MMLTAGSscip-typescript npm . . semantic_tree/`semantic_util.ts`/MMLTAGS# } from '../semantic_tree/semantic_util.js'scip-typescript npm . . semantic_tree/`semantic_util.ts`/;
28
29 import { AbstractEnrichCasescip-typescript npm . . enrich_mathml/`abstract_enrich_case.ts`/AbstractEnrichCase# } from './abstract_enrich_case.js'scip-typescript npm . . enrich_mathml/`abstract_enrich_case.ts`/;
30 import { CaseDoubleScriptscip-typescript npm . . enrich_mathml/`case_double_script.ts`/CaseDoubleScript# } from './case_double_script.js'scip-typescript npm . . enrich_mathml/`case_double_script.ts`/;
31 import { CaseMultiscriptsscip-typescript npm . . enrich_mathml/`case_multiscripts.ts`/CaseMultiscripts# } from './case_multiscripts.js'scip-typescript npm . . enrich_mathml/`case_multiscripts.ts`/;
32 import { CaseTensorscip-typescript npm . . enrich_mathml/`case_tensor.ts`/CaseTensor# } from './case_tensor.js'scip-typescript npm . . enrich_mathml/`case_tensor.ts`/;
33 import * as EnrichMathmlscip-typescript npm . . enrich_mathml/`enrich_mathml.ts`/ from './enrich_mathml.js'scip-typescript npm . . enrich_mathml/`enrich_mathml.ts`/;
34 import { addMrowscip-typescript npm . . enrich_mathml/`enrich_attr.ts`/addMrow()., setAttributesscip-typescript npm . . enrich_mathml/`enrich_attr.ts`/setAttributes()., Attributescip-typescript npm . . enrich_mathml/`enrich_attr.ts`/Attribute# } from './enrich_attr.js'scip-typescript npm . . enrich_mathml/`enrich_attr.ts`/;
35
36 export class CaseEmbellishedscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished# extends AbstractEnrichCasescip-typescript npm . . enrich_mathml/`abstract_enrich_case.ts`/AbstractEnrichCase# {
37 /**
38 * Fenced semantic node.
39 */
40 public fencedscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fenced.: SemanticNodescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode# = null;
41
42 /**
43 * Fenced mml node.
44 */
45 public fencedMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMml.: Elementscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Element# = null;
46
47 /**
48 * List of all fenced mml nodes. `fencedMml` is the first.
49 */
50 public fencedMmlNodesscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMmlNodes.: Elementscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Element#[] = [];
51
52 /**
53 * Open Fenced semantic node.
54 */
55 public ofencescip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#ofence.: SemanticNodescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode# = null;
56
57 /**
58 * Open Fenced mml node.
59 */
60 public ofenceMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#ofenceMml.: Elementscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Element# = null;
61
62 /**
63 * Open Fenced node map.
64 */
65 public ofenceMapscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#ofenceMap.: { [key: number]: Elementscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Element# } = {};
66
67 /**
68 * Closed Fenced semantic node.
69 */
70 public cfencescip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#cfence.: SemanticNodescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode# = null;
71
72 /**
73 * Closed Fenced node map.
74 */
75 public cfenceMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#cfenceMml.: Elementscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Element# = null;
76
77 /**
78 * Closed Fenced semantic node.
79 */
80 public cfenceMapscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#cfenceMap.: { [key: number]: Elementscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Element# } = {};
81
82 /**
83 * List of elements that need to get the parents reset.
84 */
85 public parentCleanupscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#parentCleanup.: Elementscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Element#[] = [];
86
87 /**
88 * Applicability test of the case. This method also prevents walking
89 * embellished punctuations twice as they might have already been walked as
90 * content nodes.
91 *
92 * @param semantic The semantic node.
93 * @returns True if case is applicable.
94 */
95 public static testscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#test().(semanticscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#test().(semantic): SemanticNodescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#): boolean {
96 return !!(
97 semanticscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#test().(semantic).mathmlTreescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#mathmlTree. &&
98 semanticscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#test().(semantic).fencePointerscip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#fencePointer. &&
99 // TODO: This needs a cleaner solution at some point.
100 !semanticscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#test().(semantic).mathmlTreescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#mathmlTree..getAttributescip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Element#getAttribute().('data-semantic-type')
101 );
102 }
103
104 /**
105 * Creates an empty semantic node with an associated empty mrow MathML
106 * element.
107 *
108 * @param id The id number of the node.
109 * @returns The new empty node.
110 */
111 private static makeEmptyNode_scip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#makeEmptyNode_().(idscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#makeEmptyNode_().(id): number): SemanticNodescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode# {
112 const mrow = addMrowscip-typescript npm . . enrich_mathml/`enrich_attr.ts`/addMrow().();
113 const empty = new SemanticNodescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#`<constructor>`().(idscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#makeEmptyNode_().(id));
114 empty.typescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#type. = SemanticTypescip-typescript npm . . semantic_tree/`semantic_meaning.ts`/SemanticType#.EMPTYscip-typescript npm . . semantic_tree/`semantic_meaning.ts`/Types#EMPTY.;
115 empty.mathmlTreescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#mathmlTree. = mrow;
116 return empty;
117 }
118
119 /**
120 * Collates the id numbers of the fenced node.
121 *
122 * @param fence The fence expression.
123 * @param ids The list of id numbers.
124 */
125 private static fencedMap_scip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMap_().(
126 fencescip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMap_().(fence): SemanticNodescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#,
127 idsscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMap_().(ids): { [key: number]: Elementscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Element# }
128 ) {
129 idsscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMap_().(ids)[fencescip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMap_().(fence).idscip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#`<constructor>`().(id)] = fencescip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMap_().(fence).mathmlTreescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#mathmlTree.;
130 if (!fencescip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMap_().(fence).embellishedscip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#embellished.) {
131 return;
132 }
133 CaseEmbellishedscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#.fencedMap_scip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMap_().(fencescip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMap_().(fence).childNodesscip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#childNodes.[0], idsscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMap_().(ids));
134 }
135
136 /**
137 * @override
138 */
139 constructorscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#`<constructor>`().(semanticscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#`<constructor>`().(semantic): SemanticNodescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#) {
140 super(semanticscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#`<constructor>`().(semantic));
141 }
142
143 /**
144 * @override
145 */
146 public getMathmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#getMathml().() {
147 this.getFenced_scip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#getFenced_().();
148 // This is the first fenced node, but there can be more than one!
149 this.fencedMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMml. = EnrichMathmlscip-typescript npm . . enrich_mathml/`enrich_mathml.ts`/.walkTreescip-typescript npm . . enrich_mathml/`enrich_mathml.ts`/walkTree().(this.fencedscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fenced. as SemanticNodescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#);
150 this.getFencesMml_scip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#getFencesMml_().();
151 if (this.fencedscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fenced..typescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#type. === SemanticTypescip-typescript npm . . semantic_tree/`semantic_meaning.ts`/SemanticType#.EMPTYscip-typescript npm . . semantic_tree/`semantic_meaning.ts`/Types#EMPTY. && !this.fencedMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMml..parentNodescip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Node#parentNode.) {
152 // Fenced element is empty and new. Insert it before the closing fence so
153 // it can be walked as usual.
154 this.fencedMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMml..setAttributescip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Element#setAttribute().(Attributescip-typescript npm . . enrich_mathml/`enrich_attr.ts`/Attribute#.ADDEDscip-typescript npm . . enrich_mathml/`enrich_attr.ts`/Attribute#ADDED., 'true');
155 this.cfenceMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#cfenceMml..parentNodescip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Node#parentNode..insertBeforescip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Node#insertBefore().(this.fencedMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMml., this.cfenceMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#cfenceMml.);
156 }
157 this.getFencedMml_scip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#getFencedMml_().();
158 const rewrite = this.rewrite_scip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#rewrite_().();
159 return rewrite;
160 }
161
162 /**
163 * Checks if the node is fenced, including vectors, matrices etc.
164 *
165 * @param node A semantic node.
166 * @returns True if the node is a fenced elementd type.
167 */
168 private fencedElementscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedElement().(nodescip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedElement().(node): SemanticNodescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#) {
169 return (
170 nodescip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedElement().(node).typescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#type. === SemanticTypescip-typescript npm . . semantic_tree/`semantic_meaning.ts`/SemanticType#.FENCEDscip-typescript npm . . semantic_tree/`semantic_meaning.ts`/Types#FENCED. ||
171 nodescip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedElement().(node).typescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#type. === SemanticTypescip-typescript npm . . semantic_tree/`semantic_meaning.ts`/SemanticType#.MATRIXscip-typescript npm . . semantic_tree/`semantic_meaning.ts`/Types#MATRIX. ||
172 nodescip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedElement().(node).typescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#type. === SemanticTypescip-typescript npm . . semantic_tree/`semantic_meaning.ts`/SemanticType#.VECTORscip-typescript npm . . semantic_tree/`semantic_meaning.ts`/Types#VECTOR.
173 );
174 }
175
176 /**
177 * Computes the components of the actual fenced node.
178 */
179 private getFenced_scip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#getFenced_().() {
180 let currentNode = this.semanticscip-typescript npm . . enrich_mathml/`abstract_enrich_case.ts`/AbstractEnrichCase#`<constructor>`().(semantic);
181 while (!this.fencedElementscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedElement().(currentNode)) {
182 currentNode = currentNode.childNodesscip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#childNodes.[0];
183 }
184 this.fencedscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fenced. = currentNode.childNodesscip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#childNodes.[0];
185 this.ofencescip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#ofence. = currentNode.contentNodesscip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#contentNodes.[0];
186 this.cfencescip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#cfence. = currentNode.contentNodesscip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#contentNodes.[1];
187 CaseEmbellishedscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#.fencedMap_scip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMap_().(this.ofencescip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#ofence., this.ofenceMapscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#ofenceMap.);
188 CaseEmbellishedscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#.fencedMap_scip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMap_().(this.cfencescip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#cfence., this.cfenceMapscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#cfenceMap.);
189 }
190
191 /**
192 * Retrieve the list of MathMl elements that are fenced.
193 */
194 private getFencedMml_scip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#getFencedMml_().() {
195 let sibling = this.ofenceMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#ofenceMml..nextSiblingscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Node#nextSibling.;
196 sibling = sibling === this.fencedMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMml. ? sibling : this.fencedMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMml.;
197 while (sibling && sibling !== this.cfenceMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#cfenceMml.) {
198 this.fencedMmlNodesscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMmlNodes..pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(sibling as Elementscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Element#);
199 sibling = sibling.nextSiblingscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Node#nextSibling.;
200 }
201 }
202
203 /**
204 * Retrieve the actual MathMl element that forms the outermost layer of the
205 * fences.
206 */
207 private getFencesMml_scip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#getFencesMml_().() {
208 let currentNode = this.semanticscip-typescript npm . . enrich_mathml/`abstract_enrich_case.ts`/AbstractEnrichCase#`<constructor>`().(semantic);
209 const ofenceIds = Objectscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Object#.keysscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/ObjectConstructor#keys().(this.ofenceMapscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#ofenceMap.);
210 const cfenceIds = Objectscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Object#.keysscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/ObjectConstructor#keys().(this.cfenceMapscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#cfenceMap.);
211 while (
212 (!this.ofenceMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#ofenceMml. || !this.cfenceMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#cfenceMml.) &&
213 currentNode !== this.fencedscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fenced.
214 ) {
215 if (
216 ofenceIds.indexOfscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#indexOf().(currentNode.fencePointerscip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#fencePointer.) !== -1 &&
217 !this.ofenceMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#ofenceMml.
218 ) {
219 this.ofenceMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#ofenceMml. = currentNode.mathmlTreescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#mathmlTree.;
220 }
221 if (
222 cfenceIds.indexOfscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#indexOf().(currentNode.fencePointerscip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#fencePointer.) !== -1 &&
223 !this.cfenceMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#cfenceMml.
224 ) {
225 this.cfenceMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#cfenceMml. = currentNode.mathmlTreescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#mathmlTree.;
226 }
227 currentNode = currentNode.childNodesscip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#childNodes.[0];
228 }
229 if (!this.ofenceMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#ofenceMml.) {
230 this.ofenceMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#ofenceMml. = this.ofencescip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#ofence..mathmlTreescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#mathmlTree.;
231 }
232 if (!this.cfenceMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#cfenceMml.) {
233 this.cfenceMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#cfenceMml. = this.cfencescip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#cfence..mathmlTreescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#mathmlTree.;
234 }
235 if (this.ofenceMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#ofenceMml.) {
236 this.ofenceMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#ofenceMml. = EnrichMathmlscip-typescript npm . . enrich_mathml/`enrich_mathml.ts`/.ascendNewNodescip-typescript npm . . enrich_mathml/`enrich_mathml.ts`/ascendNewNode().(this.ofenceMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#ofenceMml.);
237 }
238 if (this.cfenceMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#cfenceMml.) {
239 this.cfenceMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#cfenceMml. = EnrichMathmlscip-typescript npm . . enrich_mathml/`enrich_mathml.ts`/.ascendNewNodescip-typescript npm . . enrich_mathml/`enrich_mathml.ts`/ascendNewNode().(this.cfenceMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#cfenceMml.);
240 }
241 }
242
243 /**
244 * Rewrites the MathML node with embellished fences.
245 *
246 * @returns The new MathML element.
247 */
248 private rewrite_scip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#rewrite_().(): Elementscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Element# {
249 let currentNode = this.semanticscip-typescript npm . . enrich_mathml/`abstract_enrich_case.ts`/AbstractEnrichCase#`<constructor>`().(semantic);
250 let result = null;
251 const newNode = this.introduceNewLayer_scip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#introduceNewLayer_().();
252 // Sets the basics composition.
253 setAttributesscip-typescript npm . . enrich_mathml/`enrich_attr.ts`/setAttributes().(newNode, this.fencedscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fenced..parentscip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#parent. as SemanticNodescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#);
254
255 while (!this.fencedElementscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedElement().(currentNode)) {
256 // Outer embellished node is the one with the fence pointer.
257 const mml = currentNode.mathmlTreescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#mathmlTree. as Elementscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Element#;
258 const specialCase = this.specialCase_scip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#specialCase_().(currentNode, mml);
259 if (specialCase) {
260 currentNode = specialCase;
261 } else {
262 setAttributesscip-typescript npm . . enrich_mathml/`enrich_attr.ts`/setAttributes().(mml, currentNode);
263 const mmlChildren = [];
264 // The base node is rewritten. Walk the remaining nodes.
265 for (let i = 1, child; (child = currentNode.childNodesscip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#childNodes.[i]); i++) {
266 mmlChildren.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(EnrichMathmlscip-typescript npm . . enrich_mathml/`enrich_mathml.ts`/.walkTreescip-typescript npm . . enrich_mathml/`enrich_mathml.ts`/walkTree().(child));
267 }
268 currentNode = currentNode.childNodesscip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#childNodes.[0];
269 }
270
271 // Reordering the nodes in the tree.
272 const dummy = DomUtilscip-typescript npm . . common/`dom_util.ts`/.createElementscip-typescript npm . . common/`dom_util.ts`/createElement().('dummy');
273 const saveChild = mml.childNodesscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Node#childNodes.[0];
274
275 DomUtilscip-typescript npm . . common/`dom_util.ts`/.replaceNodescip-typescript npm . . common/`dom_util.ts`/replaceNode().(mml, dummy);
276 DomUtilscip-typescript npm . . common/`dom_util.ts`/.replaceNodescip-typescript npm . . common/`dom_util.ts`/replaceNode().(newNode, mml);
277 DomUtilscip-typescript npm . . common/`dom_util.ts`/.replaceNodescip-typescript npm . . common/`dom_util.ts`/replaceNode().(mml.childNodesscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Node#childNodes.[0], newNode);
278 DomUtilscip-typescript npm . . common/`dom_util.ts`/.replaceNodescip-typescript npm . . common/`dom_util.ts`/replaceNode().(dummy, saveChild);
279 if (!result) {
280 result = mml;
281 }
282 }
283
284 // Walk the actual fences.
285 EnrichMathmlscip-typescript npm . . enrich_mathml/`enrich_mathml.ts`/.walkTreescip-typescript npm . . enrich_mathml/`enrich_mathml.ts`/walkTree().(this.ofencescip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#ofence. as SemanticNodescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#);
286 EnrichMathmlscip-typescript npm . . enrich_mathml/`enrich_mathml.ts`/.walkTreescip-typescript npm . . enrich_mathml/`enrich_mathml.ts`/walkTree().(this.cfencescip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#cfence. as SemanticNodescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#);
287
288 this.cleanupParents_scip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#cleanupParents_().();
289 return result || newNode;
290 }
291
292 /**
293 * Treatment of special cases like msubsup and rewritten mmultiscripts.
294 *
295 * @param semantic The current semantic node.
296 * @param mml The MathML node associated with the semantic node.
297 * @returns The next semantic node to be rewritten, if
298 * the original semantic node was a special case.
299 */
300 private specialCase_scip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#specialCase_().(semanticscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#specialCase_().(semantic): SemanticNodescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#, mmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#specialCase_().(mml): Elementscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Element#): SemanticNodescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode# {
301 const mmlTag = DomUtilscip-typescript npm . . common/`dom_util.ts`/.tagNamescip-typescript npm . . common/`dom_util.ts`/tagName().(mmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#specialCase_().(mml));
302 let parent = null;
303 let caller;
304 if (mmlTag === MMLTAGSscip-typescript npm . . semantic_tree/`semantic_util.ts`/MMLTAGS#.MSUBSUPscip-typescript npm . . semantic_tree/`semantic_util.ts`/MMLTAGS#MSUBSUP.) {
305 parent = semanticscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#specialCase_().(semantic).childNodesscip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#childNodes.[0];
306 caller = CaseDoubleScriptscip-typescript npm . . enrich_mathml/`case_double_script.ts`/CaseDoubleScript#;
307 } else if (mmlTag === MMLTAGSscip-typescript npm . . semantic_tree/`semantic_util.ts`/MMLTAGS#.MMULTISCRIPTSscip-typescript npm . . semantic_tree/`semantic_util.ts`/MMLTAGS#MMULTISCRIPTS.) {
308 if (
309 semanticscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#specialCase_().(semantic).typescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#type. === SemanticTypescip-typescript npm . . semantic_tree/`semantic_meaning.ts`/SemanticType#.SUPERSCRIPTscip-typescript npm . . semantic_tree/`semantic_meaning.ts`/Types#SUPERSCRIPT. ||
310 semanticscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#specialCase_().(semantic).typescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#type. === SemanticTypescip-typescript npm . . semantic_tree/`semantic_meaning.ts`/SemanticType#.SUBSCRIPTscip-typescript npm . . semantic_tree/`semantic_meaning.ts`/Types#SUBSCRIPT.
311 ) {
312 caller = CaseMultiscriptsscip-typescript npm . . enrich_mathml/`case_multiscripts.ts`/CaseMultiscripts#;
313 } else if (semanticscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#specialCase_().(semantic).typescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#type. === SemanticTypescip-typescript npm . . semantic_tree/`semantic_meaning.ts`/SemanticType#.TENSORscip-typescript npm . . semantic_tree/`semantic_meaning.ts`/Types#TENSOR.) {
314 caller = CaseTensorscip-typescript npm . . enrich_mathml/`case_tensor.ts`/CaseTensor#;
315 }
316 if (
317 caller &&
318 semanticscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#specialCase_().(semantic).childNodesscip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#childNodes.[0] &&
319 semanticscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#specialCase_().(semantic).childNodesscip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#childNodes.[0].rolescip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#role. === SemanticRolescip-typescript npm . . semantic_tree/`semantic_meaning.ts`/SemanticRole#.SUBSUPscip-typescript npm . . semantic_tree/`semantic_meaning.ts`/Roles#SUBSUP.
320 ) {
321 parent = semanticscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#specialCase_().(semantic).childNodesscip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#childNodes.[0];
322 } else {
323 parent = semanticscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#specialCase_().(semantic);
324 }
325 }
326 if (!parent) {
327 return null;
328 }
329 const base = parent.childNodesscip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#childNodes.[0];
330 const empty = CaseEmbellishedscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#.makeEmptyNode_scip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#makeEmptyNode_().(base.idscip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#`<constructor>`().(id));
331 parent.childNodesscip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#childNodes.[0] = empty;
332 mmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#specialCase_().(mml) = new caller(semanticscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#specialCase_().(semantic)).getMathmlscip-typescript npm . . enrich_mathml/`case_double_script.ts`/CaseDoubleScript#getMathml().();
333 parent.childNodesscip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#childNodes.[0] = base;
334 this.parentCleanupscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#parentCleanup..pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(mmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#specialCase_().(mml));
335 return parent.childNodesscip-typescript npm . . semantic_tree/`semantic_node.ts`/SemanticNode#childNodes.[0];
336 }
337
338 /**
339 * Introduces a new layer if necessary before rewriting the fence.
340 *
341 * @returns The node representing the active layer.
342 */
343 private introduceNewLayer_scip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#introduceNewLayer_().(): Elementscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Element# {
344 const fullOfence = this.fullFencescip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fullFence().(this.ofenceMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#ofenceMml.);
345 const fullCfence = this.fullFencescip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fullFence().(this.cfenceMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#cfenceMml.);
346 // Introduce a definite new layer.
347 let newNode = addMrowscip-typescript npm . . enrich_mathml/`enrich_attr.ts`/addMrow().();
348 DomUtilscip-typescript npm . . common/`dom_util.ts`/.replaceNodescip-typescript npm . . common/`dom_util.ts`/replaceNode().(this.fencedMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMml. as Elementscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Element#, newNode);
349 this.fencedMmlNodesscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMmlNodes..forEachscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#forEach().((node) => newNode.appendChildscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Node#appendChild().(node));
350 newNode.insertBeforescip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Node#insertBefore().(fullOfence, this.fencedMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMml.);
351 newNode.appendChildscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Node#appendChild().(fullCfence);
352 // The case of top element math.
353 if (!newNode.parentNodescip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Node#parentNode.) {
354 const mrow = addMrowscip-typescript npm . . enrich_mathml/`enrich_attr.ts`/addMrow().();
355 while (newNode.childNodesscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Node#childNodes..lengthscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/NodeList#length. > 0) {
356 mrow.appendChildscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Node#appendChild().(newNode.childNodesscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Node#childNodes.[0]);
357 }
358 newNode.appendChildscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Node#appendChild().(mrow);
359 newNode = mrow;
360 }
361 return newNode;
362 }
363
364 /**
365 * Retrieves the original embellished fence for the given fence.
366 *
367 * @param fence A simple fence.
368 * @returns The embellished version of that fence. Can be the fence
369 * itself if it was not embellished.
370 */
371 private fullFencescip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fullFence().(fencescip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fullFence().(fence): Elementscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Element#): Elementscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Element# {
372 const parent = this.fencedMmlscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fencedMml..parentNodescip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Node#parentNode.;
373 let currentFence = fencescip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#fullFence().(fence);
374 while (currentFence.parentNodescip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Node#parentNode. && currentFence.parentNodescip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Node#parentNode. !== parent) {
375 currentFence = currentFence.parentNodescip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Node#parentNode. as Elementscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Element#;
376 }
377 return currentFence as Elementscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Element#;
378 }
379
380 /**
381 * Sets the correct parent pointer for MathML nodes treated and collated in
382 * the special cases. In particular we set the parent of the first child of a
383 * node to the parent of the remaining children.
384 */
385 private cleanupParents_scip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#cleanupParents_().() {
386 this.parentCleanupscip-typescript npm . . enrich_mathml/`case_embellished.ts`/CaseEmbellished#parentCleanup..forEachscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#forEach().(function (x) {
387 const parent = (x.childNodesscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Node#childNodes.[1] as Elementscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Element#).getAttributescip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Element#getAttribute().(
388 Attributescip-typescript npm . . enrich_mathml/`enrich_attr.ts`/Attribute#.PARENTscip-typescript npm . . enrich_mathml/`enrich_attr.ts`/Attribute#PARENT.
389 );
390 (x.childNodesscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Node#childNodes.[0] as Elementscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Element#).setAttributescip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/Element#setAttribute().(Attributescip-typescript npm . . enrich_mathml/`enrich_attr.ts`/Attribute#.PARENTscip-typescript npm . . enrich_mathml/`enrich_attr.ts`/Attribute#PARENT., parent);
391 });
392 }
393 }