@modusoperandi/licit-import-utils 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/capco.util.d.ts +38 -0
- package/capco.util.js +195 -0
- package/index.d.ts +8 -0
- package/index.js +8 -0
- package/licit-elements.d.ts +878 -0
- package/licit-elements.js +2588 -0
- package/licit-transform.d.ts +360 -0
- package/licit-transform.js +2197 -0
- package/package.json +52 -0
- package/transform.docx.d.ts +16 -0
- package/transform.docx.js +154 -0
- package/transform.utils.d.ts +17 -0
- package/transform.utils.js +155 -0
- package/transform.zip.d.ts +5 -0
- package/transform.zip.js +296 -0
- package/types.d.ts +9 -0
- package/types.js +5 -0
- package/zip.utils.d.ts +6 -0
- package/zip.utils.js +23 -0
|
@@ -0,0 +1,2588 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license MIT
|
|
3
|
+
* @copyright Copyright 2026 Modus Operandi Inc. All Rights Reserved.
|
|
4
|
+
*/
|
|
5
|
+
import { getCapcoFromNode } from './capco.util';
|
|
6
|
+
import { v4 as uuid } from 'uuid';
|
|
7
|
+
const infoIconCircleData = {
|
|
8
|
+
infoIconClass: 'fa fa-info-circle',
|
|
9
|
+
infoIconUnicode: '',
|
|
10
|
+
};
|
|
11
|
+
const infoIconLockData = {
|
|
12
|
+
infoIconClass: 'fa fa-lock',
|
|
13
|
+
infoIconUnicode: '',
|
|
14
|
+
};
|
|
15
|
+
export class LicitElement {
|
|
16
|
+
styleLevel = 0;
|
|
17
|
+
id = '';
|
|
18
|
+
}
|
|
19
|
+
export class LicitDocumentElement extends LicitElement {
|
|
20
|
+
getBaseElement() {
|
|
21
|
+
return {
|
|
22
|
+
type: 'doc',
|
|
23
|
+
attrs: {
|
|
24
|
+
layout: null,
|
|
25
|
+
padding: null,
|
|
26
|
+
width: null,
|
|
27
|
+
},
|
|
28
|
+
content: [],
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
children = [];
|
|
32
|
+
appendElement(element) {
|
|
33
|
+
this.children.push(element);
|
|
34
|
+
}
|
|
35
|
+
render() {
|
|
36
|
+
const element = this.getBaseElement();
|
|
37
|
+
for (const child of this.children) {
|
|
38
|
+
element.content.push(child.render());
|
|
39
|
+
}
|
|
40
|
+
return element;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export class LicitImageElement extends LicitElement {
|
|
44
|
+
source;
|
|
45
|
+
alt;
|
|
46
|
+
width;
|
|
47
|
+
height;
|
|
48
|
+
align;
|
|
49
|
+
constructor(src, altText, width, height, align) {
|
|
50
|
+
super();
|
|
51
|
+
this.source = src;
|
|
52
|
+
this.alt = altText ?? '';
|
|
53
|
+
this.width = width;
|
|
54
|
+
this.height = height;
|
|
55
|
+
this.align = align;
|
|
56
|
+
}
|
|
57
|
+
getBaseElement() {
|
|
58
|
+
return {
|
|
59
|
+
type: 'image',
|
|
60
|
+
attrs: {
|
|
61
|
+
align: null,
|
|
62
|
+
alt: '',
|
|
63
|
+
crop: null,
|
|
64
|
+
height: null,
|
|
65
|
+
rotate: null,
|
|
66
|
+
src: '',
|
|
67
|
+
title: null,
|
|
68
|
+
width: null,
|
|
69
|
+
fitToParent: null,
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
render() {
|
|
74
|
+
const element = this.getBaseElement();
|
|
75
|
+
element.attrs.src = this.source;
|
|
76
|
+
element.attrs.alt = this.alt ?? '';
|
|
77
|
+
element.attrs.align = this.align ?? 'center';
|
|
78
|
+
if (this.width)
|
|
79
|
+
element.attrs.width = this.width;
|
|
80
|
+
if (this.height)
|
|
81
|
+
element.attrs.height = this.height;
|
|
82
|
+
return element;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export class LicitNewImageElement extends LicitElement {
|
|
86
|
+
getBaseElement() {
|
|
87
|
+
return {
|
|
88
|
+
type: 'image',
|
|
89
|
+
attrs: {
|
|
90
|
+
alt: '',
|
|
91
|
+
height: null,
|
|
92
|
+
src: '',
|
|
93
|
+
title: null,
|
|
94
|
+
width: null,
|
|
95
|
+
fitToParent: null,
|
|
96
|
+
simpleImg: 'false',
|
|
97
|
+
capco: this.capco,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
source;
|
|
102
|
+
alt;
|
|
103
|
+
width;
|
|
104
|
+
height;
|
|
105
|
+
capco;
|
|
106
|
+
constructor(src, width, height, altText, capco) {
|
|
107
|
+
super();
|
|
108
|
+
this.source = src;
|
|
109
|
+
this.alt = altText;
|
|
110
|
+
this.height = height;
|
|
111
|
+
this.width = width;
|
|
112
|
+
this.capco = capco ?? '';
|
|
113
|
+
}
|
|
114
|
+
render() {
|
|
115
|
+
const element = this.getBaseElement();
|
|
116
|
+
element.attrs.src = this.source;
|
|
117
|
+
element.attrs.alt = this.alt ?? '';
|
|
118
|
+
element.attrs.width = this.width ?? null;
|
|
119
|
+
element.attrs.height = this.height ?? null;
|
|
120
|
+
return element;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export class LicitParagraphImageElement extends LicitElement {
|
|
124
|
+
getBaseElement() {
|
|
125
|
+
return {
|
|
126
|
+
type: 'paragraph',
|
|
127
|
+
attrs: {
|
|
128
|
+
styleName: 'Normal',
|
|
129
|
+
},
|
|
130
|
+
content: [
|
|
131
|
+
{
|
|
132
|
+
type: 'image',
|
|
133
|
+
attrs: {
|
|
134
|
+
align: 'center',
|
|
135
|
+
alt: this.alt ?? '',
|
|
136
|
+
crop: null,
|
|
137
|
+
height: null,
|
|
138
|
+
rotate: null,
|
|
139
|
+
src: this.source,
|
|
140
|
+
title: null,
|
|
141
|
+
width: null,
|
|
142
|
+
fitToParent: null,
|
|
143
|
+
capco: this.capco ?? '',
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
source;
|
|
150
|
+
alt;
|
|
151
|
+
width;
|
|
152
|
+
height;
|
|
153
|
+
capco;
|
|
154
|
+
align;
|
|
155
|
+
constructor(src, alt, width, height, align) {
|
|
156
|
+
super();
|
|
157
|
+
this.source = src;
|
|
158
|
+
this.alt = alt;
|
|
159
|
+
this.width = width;
|
|
160
|
+
this.height = height;
|
|
161
|
+
this.align = align;
|
|
162
|
+
}
|
|
163
|
+
render() {
|
|
164
|
+
const element = this.getBaseElement();
|
|
165
|
+
if (this.width)
|
|
166
|
+
element.content[0].attrs.width = this.width;
|
|
167
|
+
if (this.height)
|
|
168
|
+
element.content[0].attrs.height = this.height;
|
|
169
|
+
if (this.align)
|
|
170
|
+
element.content[0].attrs.align = this.align;
|
|
171
|
+
return element;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
export class LicitEnhancedImageElement extends LicitElement {
|
|
175
|
+
getBaseElement() {
|
|
176
|
+
return {
|
|
177
|
+
type: 'enhanced_table_figure',
|
|
178
|
+
attrs: {
|
|
179
|
+
id: '',
|
|
180
|
+
figureType: 'figure',
|
|
181
|
+
orientation: 'portrait',
|
|
182
|
+
maximized: false,
|
|
183
|
+
isValidate: true,
|
|
184
|
+
},
|
|
185
|
+
content: [],
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
body;
|
|
189
|
+
capco;
|
|
190
|
+
orientation;
|
|
191
|
+
constructor(orientation) {
|
|
192
|
+
super();
|
|
193
|
+
this.orientation = orientation;
|
|
194
|
+
}
|
|
195
|
+
render() {
|
|
196
|
+
const element = this.getBaseElement();
|
|
197
|
+
if (this.orientation) {
|
|
198
|
+
element.attrs.orientation = this.orientation;
|
|
199
|
+
}
|
|
200
|
+
element.content.push(this.body.render(), this.capco.render());
|
|
201
|
+
return element;
|
|
202
|
+
}
|
|
203
|
+
addBody(bodyObj) {
|
|
204
|
+
this.body = bodyObj;
|
|
205
|
+
}
|
|
206
|
+
addCapco(capcoObj) {
|
|
207
|
+
this.capco = capcoObj;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
export class LicitEnhancedImageBodyElement extends LicitElement {
|
|
211
|
+
image;
|
|
212
|
+
getBaseElement() {
|
|
213
|
+
return {
|
|
214
|
+
type: 'enhanced_table_figure_body',
|
|
215
|
+
content: [],
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
constructor(img) {
|
|
219
|
+
super();
|
|
220
|
+
this.image = img;
|
|
221
|
+
}
|
|
222
|
+
render() {
|
|
223
|
+
const element = this.getBaseElement();
|
|
224
|
+
element.content.push(this.image.render());
|
|
225
|
+
return element;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
export class LicitHeaderElement extends LicitElement {
|
|
229
|
+
getBaseElement() {
|
|
230
|
+
return {
|
|
231
|
+
type: 'paragraph',
|
|
232
|
+
attrs: { styleName: 'Normal' },
|
|
233
|
+
content: [
|
|
234
|
+
{
|
|
235
|
+
type: 'text',
|
|
236
|
+
text: '',
|
|
237
|
+
marks: [
|
|
238
|
+
{
|
|
239
|
+
type: 'mark-font-size',
|
|
240
|
+
attrs: {
|
|
241
|
+
pt: 12,
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
type: 'mark-font-type',
|
|
246
|
+
attrs: {
|
|
247
|
+
name: 'Times New Roman',
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
type: 'strong',
|
|
252
|
+
attrs: { overridden: true },
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
},
|
|
256
|
+
],
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
text;
|
|
260
|
+
subText;
|
|
261
|
+
// override styleLevel: number;
|
|
262
|
+
align = null;
|
|
263
|
+
styleName;
|
|
264
|
+
capco;
|
|
265
|
+
selectionId;
|
|
266
|
+
name = '';
|
|
267
|
+
marks = [];
|
|
268
|
+
constructor(text = '', subText = '', styleLevel = 0, styleName = '', capco = '', node) {
|
|
269
|
+
super();
|
|
270
|
+
this.text = text;
|
|
271
|
+
this.subText = subText;
|
|
272
|
+
this.styleLevel = styleLevel;
|
|
273
|
+
this.styleName = styleName;
|
|
274
|
+
this.capco = capco;
|
|
275
|
+
this.setInnerlinks(node);
|
|
276
|
+
this.marks = this.handleInlineStyles(node);
|
|
277
|
+
}
|
|
278
|
+
render() {
|
|
279
|
+
const element = this.getBaseElement();
|
|
280
|
+
element.content[0].text = this.text;
|
|
281
|
+
if (this.subText.length) {
|
|
282
|
+
element.content.push({
|
|
283
|
+
type: 'text',
|
|
284
|
+
text: this.subText,
|
|
285
|
+
marks: [
|
|
286
|
+
{
|
|
287
|
+
type: 'mark-font-type',
|
|
288
|
+
attrs: {
|
|
289
|
+
name: 'Times New Roman',
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
type: 'mark-font-size',
|
|
294
|
+
attrs: {
|
|
295
|
+
pt: 12,
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
],
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
if (this.marks && this.marks.length > 0) {
|
|
302
|
+
if (element.content[0].type === 'text') {
|
|
303
|
+
element.content[0].marks.push(...this.marks);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
element.attrs.styleName = this.styleName;
|
|
307
|
+
element.attrs.capco = this.capco;
|
|
308
|
+
element.attrs.selectionId = this.selectionId;
|
|
309
|
+
return element;
|
|
310
|
+
}
|
|
311
|
+
//innerLinks
|
|
312
|
+
setInnerlinks(node) {
|
|
313
|
+
if (!node)
|
|
314
|
+
return;
|
|
315
|
+
for (const n of Array.from(node.childNodes)) {
|
|
316
|
+
if (n.nodeName !== 'A') {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
const link = n.getAttribute('id');
|
|
320
|
+
if (!n.href && link) {
|
|
321
|
+
this.name = link;
|
|
322
|
+
this.selectionId = '#' + link;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
handleInlineStyles(node) {
|
|
327
|
+
const marks = [];
|
|
328
|
+
if (node?.style?.length > 0) {
|
|
329
|
+
const nodeStyles = node.getAttribute('style')?.split(';');
|
|
330
|
+
if (nodeStyles?.length > 0) {
|
|
331
|
+
const inlineStyles = getInlineStylesArray(nodeStyles);
|
|
332
|
+
if (inlineStyles.length > 0 && node.textContent !== '') {
|
|
333
|
+
this.mapInlineStylesToMarks(inlineStyles, marks);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return marks;
|
|
338
|
+
}
|
|
339
|
+
mapInlineStylesToMarks(inlineStyles, inlineMarks) {
|
|
340
|
+
for (const inlineStyle of inlineStyles) {
|
|
341
|
+
switch (inlineStyle.toLowerCase()) {
|
|
342
|
+
case 'italic': {
|
|
343
|
+
const em = {
|
|
344
|
+
type: 'em',
|
|
345
|
+
attrs: { overridden: true },
|
|
346
|
+
};
|
|
347
|
+
inlineMarks.push(em);
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
case 'underline': {
|
|
351
|
+
const u = {
|
|
352
|
+
type: 'underline',
|
|
353
|
+
attrs: { overridden: true },
|
|
354
|
+
};
|
|
355
|
+
inlineMarks.push(u);
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
358
|
+
case 'uppercase': {
|
|
359
|
+
this.text = this.text.toUpperCase();
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
case 'lowercase': {
|
|
363
|
+
this.text = this.text.toLowerCase();
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
default: {
|
|
367
|
+
if (inlineStyle.startsWith('color-')) {
|
|
368
|
+
const colorValue = inlineStyle.replace('color-', '');
|
|
369
|
+
if (CSS.supports('color', colorValue)) {
|
|
370
|
+
inlineMarks.push({
|
|
371
|
+
type: 'mark-text-color',
|
|
372
|
+
attrs: { color: colorValue, overridden: true },
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
break;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
//Licit Paragraph node for handling note
|
|
383
|
+
export class LicitParagraphNote extends LicitElement {
|
|
384
|
+
node;
|
|
385
|
+
styleName;
|
|
386
|
+
capco = '';
|
|
387
|
+
constructor(node) {
|
|
388
|
+
super();
|
|
389
|
+
this.node = node;
|
|
390
|
+
this.styleName = node.className ?? 'Normal';
|
|
391
|
+
this.capco = getCapcoFromNode(node);
|
|
392
|
+
}
|
|
393
|
+
getBaseElement() {
|
|
394
|
+
return {
|
|
395
|
+
type: 'paragraph',
|
|
396
|
+
attrs: {
|
|
397
|
+
styleName: this.styleName,
|
|
398
|
+
capco: this.capco,
|
|
399
|
+
},
|
|
400
|
+
content: [],
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
render() {
|
|
404
|
+
const element = this.getBaseElement();
|
|
405
|
+
const text = this.node.textContent;
|
|
406
|
+
const noteName = text.split(':')[0] + ':';
|
|
407
|
+
const noteValue = text.split(':')[1];
|
|
408
|
+
if (noteName && noteValue) {
|
|
409
|
+
const firstContent = {
|
|
410
|
+
type: 'text',
|
|
411
|
+
text: noteName,
|
|
412
|
+
marks: [
|
|
413
|
+
{
|
|
414
|
+
type: 'mark-font-type',
|
|
415
|
+
attrs: {
|
|
416
|
+
name: 'Times New Roman',
|
|
417
|
+
},
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
type: 'mark-font-size',
|
|
421
|
+
attrs: {
|
|
422
|
+
pt: 12,
|
|
423
|
+
},
|
|
424
|
+
},
|
|
425
|
+
{
|
|
426
|
+
type: 'em',
|
|
427
|
+
attrs: { overridden: true },
|
|
428
|
+
},
|
|
429
|
+
],
|
|
430
|
+
};
|
|
431
|
+
element.content.push(firstContent, {
|
|
432
|
+
type: 'text',
|
|
433
|
+
text: noteValue,
|
|
434
|
+
marks: [
|
|
435
|
+
{
|
|
436
|
+
type: 'mark-font-type',
|
|
437
|
+
attrs: {
|
|
438
|
+
name: 'Times New Roman',
|
|
439
|
+
},
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
type: 'mark-font-size',
|
|
443
|
+
attrs: {
|
|
444
|
+
pt: 12,
|
|
445
|
+
},
|
|
446
|
+
},
|
|
447
|
+
],
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
element.content.push({
|
|
452
|
+
type: 'text',
|
|
453
|
+
text: this.node.textContent,
|
|
454
|
+
marks: [
|
|
455
|
+
{
|
|
456
|
+
type: 'mark-font-type',
|
|
457
|
+
attrs: {
|
|
458
|
+
name: 'Times New Roman',
|
|
459
|
+
},
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
type: 'mark-font-size',
|
|
463
|
+
attrs: {
|
|
464
|
+
pt: 12,
|
|
465
|
+
},
|
|
466
|
+
},
|
|
467
|
+
],
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
return element;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
export class LicitParagraphElement extends LicitElement {
|
|
474
|
+
getBaseElement() {
|
|
475
|
+
return {
|
|
476
|
+
type: 'paragraph',
|
|
477
|
+
attrs: {
|
|
478
|
+
styleName: 'Normal',
|
|
479
|
+
},
|
|
480
|
+
content: [
|
|
481
|
+
{
|
|
482
|
+
type: 'text',
|
|
483
|
+
text: '',
|
|
484
|
+
marks: [
|
|
485
|
+
{
|
|
486
|
+
type: 'mark-font-type',
|
|
487
|
+
attrs: {
|
|
488
|
+
name: 'Times New Roman',
|
|
489
|
+
},
|
|
490
|
+
},
|
|
491
|
+
{
|
|
492
|
+
type: 'mark-font-size',
|
|
493
|
+
attrs: {
|
|
494
|
+
pt: 12,
|
|
495
|
+
},
|
|
496
|
+
},
|
|
497
|
+
],
|
|
498
|
+
},
|
|
499
|
+
],
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
text;
|
|
503
|
+
align = null;
|
|
504
|
+
constructor(text = '') {
|
|
505
|
+
super();
|
|
506
|
+
this.text = text;
|
|
507
|
+
}
|
|
508
|
+
render() {
|
|
509
|
+
const element = this.getBaseElement();
|
|
510
|
+
element.content[0].text = this.text; //SL-13
|
|
511
|
+
return element;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
export class NewLicitParagraphElement extends LicitElement {
|
|
515
|
+
text;
|
|
516
|
+
align = 'Left';
|
|
517
|
+
node;
|
|
518
|
+
marks = [];
|
|
519
|
+
styleName = 'Normal';
|
|
520
|
+
selectionId;
|
|
521
|
+
id = '';
|
|
522
|
+
capco = '';
|
|
523
|
+
indent = 0;
|
|
524
|
+
name = '';
|
|
525
|
+
overriddenLineSpacing = false;
|
|
526
|
+
imgContent = [];
|
|
527
|
+
lineSpacing = null;
|
|
528
|
+
overriddenLineSpaceingValue = null;
|
|
529
|
+
overriddenAlignValue = null;
|
|
530
|
+
overriddenAlign = false;
|
|
531
|
+
hangingindent = false;
|
|
532
|
+
reset = null;
|
|
533
|
+
constructor(node, infoIconData, renderedContentList) {
|
|
534
|
+
super();
|
|
535
|
+
let className = node?.getAttribute('class');
|
|
536
|
+
this.id = node?.getAttribute('id');
|
|
537
|
+
this.setInnerlinks(node);
|
|
538
|
+
className ??= node?.getAttribute('className');
|
|
539
|
+
if (className?.toLowerCase() === 'acronym') {
|
|
540
|
+
this.hangingindent = true;
|
|
541
|
+
const rawText = node.textContent?.trim() || '';
|
|
542
|
+
// Split at the first run of multiple spaces (limit to max 10 spaces)
|
|
543
|
+
const parts = rawText.split(/\s{2,10}/);
|
|
544
|
+
const shortForm = parts[0] ?? '';
|
|
545
|
+
const expansion = parts[1] ?? '';
|
|
546
|
+
// Clear the original content
|
|
547
|
+
node.textContent = '';
|
|
548
|
+
const shortNode = document.createElement('span');
|
|
549
|
+
shortNode.className = 'acronym-short';
|
|
550
|
+
shortNode.textContent = shortForm;
|
|
551
|
+
const expansionNode = document.createElement('span');
|
|
552
|
+
expansionNode.className = 'acronym-expansion';
|
|
553
|
+
expansionNode.textContent = expansion;
|
|
554
|
+
node.append(shortNode, expansionNode);
|
|
555
|
+
}
|
|
556
|
+
this.styleName = className || 'Normal';
|
|
557
|
+
this.align = node?.getAttribute('align')
|
|
558
|
+
? node?.getAttribute('align')
|
|
559
|
+
: 'Left';
|
|
560
|
+
this.capco = getCapcoFromNode(node);
|
|
561
|
+
if (undefined === this.selectionId || this.selectionId === '') {
|
|
562
|
+
this.selectionId = uuid();
|
|
563
|
+
}
|
|
564
|
+
this.ConvertMarks(node, infoIconData, renderedContentList);
|
|
565
|
+
}
|
|
566
|
+
setInnerlinks(node) {
|
|
567
|
+
for (const n of Array.from(node?.childNodes ?? [])) {
|
|
568
|
+
if (n.nodeName !== 'A') {
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
const link = n.getAttribute('id');
|
|
572
|
+
if (!n.href && link) {
|
|
573
|
+
this.name = link;
|
|
574
|
+
this.selectionId = '#' + link;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
ConvertMarks(node, infoIconData, renderedContentList) {
|
|
579
|
+
let tMark = [];
|
|
580
|
+
const inlineMarks = this.fetchInlineStyles(node);
|
|
581
|
+
for (const n of Array.from(node?.childNodes ?? [])) {
|
|
582
|
+
let mark_Colour;
|
|
583
|
+
if (n.nodeName === 'A') {
|
|
584
|
+
mark_Colour = n.getAttribute('color');
|
|
585
|
+
}
|
|
586
|
+
if (tMark.length > 0) {
|
|
587
|
+
tMark = [];
|
|
588
|
+
}
|
|
589
|
+
this.modifyChildNodes(n, infoIconData, tMark, mark_Colour, node, renderedContentList, inlineMarks);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
handleTextMark(n, getMark, data) {
|
|
593
|
+
const mark = getMark(n, data);
|
|
594
|
+
if (mark) {
|
|
595
|
+
this.marks.push(mark);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* Modifies and processes the child nodes of a given HTML element, applying various transformations
|
|
600
|
+
* and extracting semantic marks based on the node type. Handles inline styles, anchors, strong/emphasis/underline tags,
|
|
601
|
+
* superscript/subscript, text color/highlight, images, spans, and paragraphs. Updates mark collections and invokes
|
|
602
|
+
* specialized parsing methods for each supported node type.
|
|
603
|
+
*
|
|
604
|
+
* @param n - The current HTML element node to process.
|
|
605
|
+
* @param infoIconData - An array of HTMLOListElement objects containing info icon data.
|
|
606
|
+
* @param tMark - An array of Mark objects representing text marks.
|
|
607
|
+
* @param mark_Colour - The color to apply to marks.
|
|
608
|
+
* @param node - The parent HTML element node.
|
|
609
|
+
* @param renderedContentList - (Optional) An array of Node objects representing rendered content.
|
|
610
|
+
* @param parentInlineMarks - (Optional) An array of Mark objects representing inline stlyes written for parent node.
|
|
611
|
+
*/
|
|
612
|
+
modifyChildNodes(n, infoIconData, tMark, mark_Colour, node, renderedContentList, parentInlineMarks) {
|
|
613
|
+
let em;
|
|
614
|
+
let b;
|
|
615
|
+
let myMark;
|
|
616
|
+
let source;
|
|
617
|
+
let altText;
|
|
618
|
+
let u;
|
|
619
|
+
const styleMarks = [];
|
|
620
|
+
if (parentInlineMarks && parentInlineMarks.length > 0) {
|
|
621
|
+
styleMarks.push(...parentInlineMarks);
|
|
622
|
+
}
|
|
623
|
+
if (n.nodeType === Node.ELEMENT_NODE) {
|
|
624
|
+
const childrenInlineStyles = this.fetchInlineStyles(n);
|
|
625
|
+
styleMarks.push(...childrenInlineStyles);
|
|
626
|
+
}
|
|
627
|
+
switch (n.nodeName) {
|
|
628
|
+
case 'FONT':
|
|
629
|
+
this.parseFont(n, myMark, infoIconData, tMark);
|
|
630
|
+
break;
|
|
631
|
+
case 'A':
|
|
632
|
+
this.parseAnchor(n, myMark, mark_Colour, infoIconData, renderedContentList);
|
|
633
|
+
break;
|
|
634
|
+
case 'STRONG':
|
|
635
|
+
myMark = {
|
|
636
|
+
type: 'text',
|
|
637
|
+
marks: [],
|
|
638
|
+
text: node.textContent,
|
|
639
|
+
};
|
|
640
|
+
b = {
|
|
641
|
+
type: 'strong',
|
|
642
|
+
attrs: { overridden: true },
|
|
643
|
+
};
|
|
644
|
+
this.parseStrong(n, myMark, b, infoIconData);
|
|
645
|
+
break;
|
|
646
|
+
case 'EM':
|
|
647
|
+
myMark = {
|
|
648
|
+
type: 'text',
|
|
649
|
+
marks: [],
|
|
650
|
+
text: n.textContent,
|
|
651
|
+
};
|
|
652
|
+
em = {
|
|
653
|
+
type: 'em',
|
|
654
|
+
attrs: { overridden: true },
|
|
655
|
+
};
|
|
656
|
+
this.parseEmphisis(n, myMark, em, infoIconData);
|
|
657
|
+
break;
|
|
658
|
+
case 'U':
|
|
659
|
+
myMark = {
|
|
660
|
+
type: 'text',
|
|
661
|
+
marks: [],
|
|
662
|
+
text: '',
|
|
663
|
+
};
|
|
664
|
+
u = {
|
|
665
|
+
type: 'underline',
|
|
666
|
+
attrs: { overridden: true },
|
|
667
|
+
};
|
|
668
|
+
this.parseUnderline(n, myMark, u, infoIconData);
|
|
669
|
+
break;
|
|
670
|
+
case 'SUP':
|
|
671
|
+
this.handleTextMark(n, (node, data) => this.getSuperScriptMarks(node, data), infoIconData);
|
|
672
|
+
break;
|
|
673
|
+
case 'SUB':
|
|
674
|
+
if (n.innerText?.trim()) {
|
|
675
|
+
this.marks.push(this.getSubscriptMarks(n));
|
|
676
|
+
}
|
|
677
|
+
break;
|
|
678
|
+
//Case for text color and/or highlight
|
|
679
|
+
case 'MARK-TEXT-HIGHLIGHT':
|
|
680
|
+
this.handleTextMark(n, this.getHighLightAndTextColor);
|
|
681
|
+
break;
|
|
682
|
+
case 'TEXT':
|
|
683
|
+
case '#text': {
|
|
684
|
+
//Set boolean for First sentence bold logic
|
|
685
|
+
const isFirstSentenceBold = checkFirstSentenceBold(node);
|
|
686
|
+
this.handleText(n, myMark, isFirstSentenceBold, styleMarks);
|
|
687
|
+
break;
|
|
688
|
+
}
|
|
689
|
+
case 'BR':
|
|
690
|
+
myMark = {
|
|
691
|
+
type: 'hard_break',
|
|
692
|
+
};
|
|
693
|
+
this.marks.push(myMark);
|
|
694
|
+
break;
|
|
695
|
+
case 'IMG': {
|
|
696
|
+
const imgEl = n;
|
|
697
|
+
source = imgEl?.getAttribute('srcRelative') ?? imgEl?.src;
|
|
698
|
+
altText = imgEl?.alt;
|
|
699
|
+
const width = imgEl?.getAttribute('width') ?? null;
|
|
700
|
+
const height = imgEl?.getAttribute('height') ?? null;
|
|
701
|
+
const align = getElementAlignment(imgEl);
|
|
702
|
+
this.parseImage(source, altText, myMark, width, height, align);
|
|
703
|
+
break;
|
|
704
|
+
}
|
|
705
|
+
// Handling content inside span
|
|
706
|
+
case 'SPAN':
|
|
707
|
+
this.handleSpan(n, myMark, infoIconData, tMark, mark_Colour, renderedContentList, styleMarks);
|
|
708
|
+
break;
|
|
709
|
+
// Handling marks with header subtext (subtext is added as a child paragraph node of the header node)
|
|
710
|
+
case 'P':
|
|
711
|
+
this.handleParagraph(n, infoIconData, tMark, mark_Colour, renderedContentList);
|
|
712
|
+
break;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
handleParagraph(n, infoIconData, tMark, mark_Colour, renderedContentList) {
|
|
716
|
+
for (const cNode of Array.from(n.childNodes)) {
|
|
717
|
+
//Subtext needs to be on the same line as that of header
|
|
718
|
+
if (!(cNode.nodeType === Node.TEXT_NODE &&
|
|
719
|
+
cNode.textContent.trim() === '' &&
|
|
720
|
+
cNode.textContent.includes('\n'))) {
|
|
721
|
+
this.modifyChildNodes(cNode, infoIconData, tMark, mark_Colour, n, renderedContentList);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
handleSpan(n, myMark, infoIconData, tMark, mark_Colour, renderedContentList, styleMarks = []) {
|
|
726
|
+
//Skipping hidden class
|
|
727
|
+
if (n.className.toLowerCase() === 'hidden') {
|
|
728
|
+
return;
|
|
729
|
+
}
|
|
730
|
+
if (this.isEmptySpaceSpan(n)) {
|
|
731
|
+
this.addTrailingSpace();
|
|
732
|
+
}
|
|
733
|
+
if (myMark) {
|
|
734
|
+
//Adding mark for hyperLinks
|
|
735
|
+
if (myMark.type == 'text' && myMark.text) {
|
|
736
|
+
this.setLink(myMark);
|
|
737
|
+
}
|
|
738
|
+
this.marks.push(myMark);
|
|
739
|
+
}
|
|
740
|
+
else {
|
|
741
|
+
for (const cNode of Array.from(n.childNodes)) {
|
|
742
|
+
this.modifyChildNodes(cNode, infoIconData, tMark, mark_Colour, n, renderedContentList, styleMarks);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
isEmptySpaceSpan(node) {
|
|
747
|
+
const hasOnlySpace = node.textContent === '\u00A0' || node.textContent === ' ';
|
|
748
|
+
const hasLetterSpacing = node.style.letterSpacing !== '';
|
|
749
|
+
return hasOnlySpace && hasLetterSpacing;
|
|
750
|
+
}
|
|
751
|
+
isLastCharNotEmpty(str) {
|
|
752
|
+
if (str.length === 0)
|
|
753
|
+
return false;
|
|
754
|
+
return str.at(-1).trim() !== '';
|
|
755
|
+
}
|
|
756
|
+
addTrailingSpace() {
|
|
757
|
+
if (this.marks.at(-1)) {
|
|
758
|
+
const text = this.marks.at(-1).text;
|
|
759
|
+
if (this.isLastCharNotEmpty(text)) {
|
|
760
|
+
this.marks.at(-1).text += ' ';
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
// To find text with URLs
|
|
765
|
+
handleText(textNode, myMark, isFirstSentenceBold, styleMarks) {
|
|
766
|
+
const textContent = textNode.textContent;
|
|
767
|
+
const urlRegex = /(https?:\/\/[^\s]{1,2048})/g;
|
|
768
|
+
const matches = this.checkForLinks(textContent, urlRegex);
|
|
769
|
+
if (matches) {
|
|
770
|
+
this.addLinks(textContent, urlRegex, myMark);
|
|
771
|
+
}
|
|
772
|
+
else {
|
|
773
|
+
// If no URLs, add normal text
|
|
774
|
+
const textMark = {
|
|
775
|
+
type: 'text',
|
|
776
|
+
marks: [],
|
|
777
|
+
text: textContent,
|
|
778
|
+
};
|
|
779
|
+
// Apply inline styles if any
|
|
780
|
+
if (styleMarks && styleMarks.length > 0) {
|
|
781
|
+
for (const styleMark of styleMarks) {
|
|
782
|
+
textMark.marks.push(styleMark);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
if (isFirstSentenceBold) {
|
|
786
|
+
const b = {
|
|
787
|
+
type: 'strong',
|
|
788
|
+
attrs: { overridden: true },
|
|
789
|
+
};
|
|
790
|
+
textMark.marks?.push(b);
|
|
791
|
+
}
|
|
792
|
+
this.addMark(textMark, myMark);
|
|
793
|
+
if (textNode?.parentElement?.className === 'acronym-short') {
|
|
794
|
+
const acronymMark = {
|
|
795
|
+
type: 'mark-hanging-indent',
|
|
796
|
+
attrs: { prefix: 0, overridden: true },
|
|
797
|
+
};
|
|
798
|
+
textMark.marks?.push(acronymMark);
|
|
799
|
+
}
|
|
800
|
+
if (textNode?.parentElement?.className === 'acronym-expansion') {
|
|
801
|
+
const acronymMark = {
|
|
802
|
+
type: 'mark-hanging-indent',
|
|
803
|
+
attrs: { prefix: 1, overridden: true },
|
|
804
|
+
};
|
|
805
|
+
textMark.marks?.push(acronymMark);
|
|
806
|
+
}
|
|
807
|
+
this.marks.push(textMark);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
checkForLinks(text, urlRegex) {
|
|
811
|
+
return urlRegex.exec(text);
|
|
812
|
+
}
|
|
813
|
+
addLinks(text, urlRegex, myMark) {
|
|
814
|
+
const parts = text.split(urlRegex);
|
|
815
|
+
for (const part of parts) {
|
|
816
|
+
if (urlRegex.test(part)) {
|
|
817
|
+
// If it's a URL, create a link mark
|
|
818
|
+
const linkMark = {
|
|
819
|
+
type: 'text',
|
|
820
|
+
marks: [
|
|
821
|
+
{
|
|
822
|
+
type: 'link',
|
|
823
|
+
attrs: {
|
|
824
|
+
href: part,
|
|
825
|
+
target: '_blank',
|
|
826
|
+
rel: 'noopener noreferrer',
|
|
827
|
+
},
|
|
828
|
+
},
|
|
829
|
+
],
|
|
830
|
+
text: part,
|
|
831
|
+
};
|
|
832
|
+
this.addMark(linkMark, myMark);
|
|
833
|
+
this.marks.push(linkMark);
|
|
834
|
+
}
|
|
835
|
+
else {
|
|
836
|
+
// Otherwise, add as normal text
|
|
837
|
+
const textMark = {
|
|
838
|
+
type: 'text',
|
|
839
|
+
marks: [],
|
|
840
|
+
text: part,
|
|
841
|
+
};
|
|
842
|
+
this.addMark(textMark, myMark);
|
|
843
|
+
this.marks.push(textMark);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
addMark(textMark, newMark) {
|
|
848
|
+
for (const mark of newMark?.marks ?? []) {
|
|
849
|
+
textMark.marks.push(mark);
|
|
850
|
+
}
|
|
851
|
+
return textMark;
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* Extracts inline style marks from a DOM node and returns an array of mark objects.
|
|
855
|
+
*
|
|
856
|
+
* This function parses the `style` attribute of the given node, identifies supported inline styles
|
|
857
|
+
* (such as italic, bold, underline, text color, line height, and text alignment), and returns
|
|
858
|
+
* corresponding mark objects with their attributes. It also updates certain instance properties
|
|
859
|
+
* for overridden line spacing and alignment when those styles are detected.
|
|
860
|
+
*
|
|
861
|
+
* @param node - The DOM node from which to extract inline styles.
|
|
862
|
+
* @returns An array of objects representing inline style marks, each with a `type` and optional `attrs`.
|
|
863
|
+
*/
|
|
864
|
+
fetchInlineStyles(node) {
|
|
865
|
+
const inlineMarks = [];
|
|
866
|
+
if (node?.style?.length > 0) {
|
|
867
|
+
const nodeStyles = node.getAttribute('style')?.split(';');
|
|
868
|
+
if (nodeStyles?.length > 0) {
|
|
869
|
+
const inlineStyles = getInlineStylesArray(nodeStyles);
|
|
870
|
+
if (inlineStyles.length > 0 && node.textContent !== '') {
|
|
871
|
+
this.mapInlineStylesToMarks(inlineStyles, inlineMarks);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
if (node?.getAttribute('align')) {
|
|
876
|
+
const alignmentValue = node.getAttribute('align').toLowerCase();
|
|
877
|
+
this.overriddenAlign = true;
|
|
878
|
+
this.align = alignmentValue;
|
|
879
|
+
this.overriddenAlignValue = alignmentValue;
|
|
880
|
+
}
|
|
881
|
+
return inlineMarks;
|
|
882
|
+
}
|
|
883
|
+
mapInlineStylesToMarks(inlineStyles, inlineMarks) {
|
|
884
|
+
for (const inlineStyle of inlineStyles) {
|
|
885
|
+
switch (inlineStyle.toLowerCase()) {
|
|
886
|
+
case 'italic': {
|
|
887
|
+
const em = {
|
|
888
|
+
type: 'em',
|
|
889
|
+
attrs: { overridden: true },
|
|
890
|
+
};
|
|
891
|
+
inlineMarks.push(em);
|
|
892
|
+
break;
|
|
893
|
+
}
|
|
894
|
+
case 'bold': {
|
|
895
|
+
const b = { type: 'strong', attrs: { overridden: true } };
|
|
896
|
+
inlineMarks.push(b);
|
|
897
|
+
break;
|
|
898
|
+
}
|
|
899
|
+
case 'underline': {
|
|
900
|
+
const u = {
|
|
901
|
+
type: 'underline',
|
|
902
|
+
attrs: { overridden: true },
|
|
903
|
+
};
|
|
904
|
+
inlineMarks.push(u);
|
|
905
|
+
break;
|
|
906
|
+
}
|
|
907
|
+
default: {
|
|
908
|
+
this.handleCustomInlineStyle(inlineStyle, inlineMarks);
|
|
909
|
+
break;
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
handleCustomInlineStyle(inlineStyle, inlineMarks) {
|
|
915
|
+
const BASE_FONT_SIZE_PT = 12;
|
|
916
|
+
if (inlineStyle.startsWith('color-')) {
|
|
917
|
+
const colorValue = inlineStyle.replace('color-', '');
|
|
918
|
+
if (CSS.supports('color', colorValue)) {
|
|
919
|
+
inlineMarks.push({
|
|
920
|
+
type: 'mark-text-color',
|
|
921
|
+
attrs: { color: colorValue, overridden: true },
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
else if (inlineStyle.startsWith('line-height-')) {
|
|
926
|
+
const lineHeightValue = inlineStyle.replace('line-height-', '');
|
|
927
|
+
const ptValue = Number.parseFloat(lineHeightValue);
|
|
928
|
+
if (!Number.isNaN(ptValue)) {
|
|
929
|
+
const percentage = (ptValue / BASE_FONT_SIZE_PT) * 100 + '%';
|
|
930
|
+
this.overriddenLineSpacing = true;
|
|
931
|
+
this.lineSpacing = percentage;
|
|
932
|
+
this.overriddenLineSpaceingValue = percentage;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
else if (inlineStyle.startsWith('text-align-')) {
|
|
936
|
+
const alignValue = inlineStyle.replace('text-align-', '');
|
|
937
|
+
this.overriddenAlign = true;
|
|
938
|
+
this.align = alignValue;
|
|
939
|
+
this.overriddenAlignValue = alignValue;
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
parseImage(source, altText, myMark, width, height, align) {
|
|
943
|
+
if (source) {
|
|
944
|
+
const img = new LicitImageElement(source, altText, width, height, align);
|
|
945
|
+
if (img) {
|
|
946
|
+
this.marks.push(img.render());
|
|
947
|
+
}
|
|
948
|
+
if (altText === '/ERR:Unsupported Image Format x-emf') {
|
|
949
|
+
myMark = {
|
|
950
|
+
type: 'text',
|
|
951
|
+
marks: [
|
|
952
|
+
{ type: 'strong', attrs: { overridden: true } },
|
|
953
|
+
{
|
|
954
|
+
type: 'mark-text-color',
|
|
955
|
+
attrs: { color: '#f20d0d', overridden: true },
|
|
956
|
+
},
|
|
957
|
+
],
|
|
958
|
+
text: '/ERR:Unsupported Image Format x-emf',
|
|
959
|
+
};
|
|
960
|
+
this.marks.push(myMark);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
return myMark;
|
|
964
|
+
}
|
|
965
|
+
parseUnderline(n, myMark, u, infoIconData) {
|
|
966
|
+
if (n.childNodes.length === 1) {
|
|
967
|
+
myMark?.marks.push(u);
|
|
968
|
+
myMark = this.parseSubMarks(n.childNodes[0], myMark, true, infoIconData);
|
|
969
|
+
if (myMark) {
|
|
970
|
+
this.marks.push(myMark);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
else {
|
|
974
|
+
for (const unodes of Array.from(n.childNodes)) {
|
|
975
|
+
if (unodes.nodeName === 'TEXT' || unodes.nodeName === '#text') {
|
|
976
|
+
const subMark = {
|
|
977
|
+
type: 'text',
|
|
978
|
+
marks: [],
|
|
979
|
+
text: '',
|
|
980
|
+
};
|
|
981
|
+
subMark.marks.push(u);
|
|
982
|
+
subMark.text = unodes.textContent;
|
|
983
|
+
this.marks.push(subMark);
|
|
984
|
+
}
|
|
985
|
+
else {
|
|
986
|
+
myMark?.marks.push(u);
|
|
987
|
+
myMark = this.parseSubMarks(unodes, myMark, false, infoIconData);
|
|
988
|
+
if (myMark) {
|
|
989
|
+
this.marks.push(myMark);
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
return myMark;
|
|
995
|
+
}
|
|
996
|
+
parseEmphisis(n, myMark, em, infoIconData) {
|
|
997
|
+
if (n.childNodes.length === 1) {
|
|
998
|
+
myMark?.marks.push(em);
|
|
999
|
+
myMark = this.parseSubMarks(n.childNodes[0], myMark, true, infoIconData);
|
|
1000
|
+
if (myMark) {
|
|
1001
|
+
this.marks.push(myMark);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
else {
|
|
1005
|
+
for (const enodes of Array.from(n.childNodes)) {
|
|
1006
|
+
if (enodes.nodeName === 'TEXT' || enodes.nodeName === '#text') {
|
|
1007
|
+
const subMark = {
|
|
1008
|
+
type: 'text',
|
|
1009
|
+
marks: [],
|
|
1010
|
+
text: '',
|
|
1011
|
+
};
|
|
1012
|
+
subMark.marks.push(em);
|
|
1013
|
+
subMark.text = enodes.textContent;
|
|
1014
|
+
this.marks.push(subMark);
|
|
1015
|
+
}
|
|
1016
|
+
else {
|
|
1017
|
+
myMark?.marks.push(em);
|
|
1018
|
+
myMark = this.parseSubMarks(enodes, myMark, false, infoIconData);
|
|
1019
|
+
if (myMark) {
|
|
1020
|
+
this.marks.push(myMark);
|
|
1021
|
+
}
|
|
1022
|
+
else if (enodes.textContent === ' ')
|
|
1023
|
+
this.marks.push(this.getEmptyTextMark());
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
//Handling superscript and subscript with class name
|
|
1028
|
+
this.handleClassName(n.className, myMark);
|
|
1029
|
+
return myMark;
|
|
1030
|
+
}
|
|
1031
|
+
parseStrong(n, myMark, b, infoIconData) {
|
|
1032
|
+
if (n.childNodes.length === 1) {
|
|
1033
|
+
myMark?.marks.push(b);
|
|
1034
|
+
myMark = this.parseSubMarks(n.childNodes[0], myMark, true, infoIconData);
|
|
1035
|
+
if (myMark) {
|
|
1036
|
+
this.marks.push(myMark);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
else {
|
|
1040
|
+
for (const bnodes of Array.from(n.childNodes)) {
|
|
1041
|
+
if (bnodes.nodeName === 'TEXT' || bnodes.nodeName === '#text') {
|
|
1042
|
+
const subMark = {
|
|
1043
|
+
type: 'text',
|
|
1044
|
+
marks: [],
|
|
1045
|
+
text: '',
|
|
1046
|
+
};
|
|
1047
|
+
subMark.marks.push(b);
|
|
1048
|
+
subMark.text = bnodes.textContent;
|
|
1049
|
+
this.marks.push(subMark);
|
|
1050
|
+
}
|
|
1051
|
+
else {
|
|
1052
|
+
myMark?.marks.push(b);
|
|
1053
|
+
myMark = this.parseSubMarks(bnodes, myMark, false, infoIconData);
|
|
1054
|
+
if (myMark) {
|
|
1055
|
+
this.marks.push(myMark);
|
|
1056
|
+
}
|
|
1057
|
+
else {
|
|
1058
|
+
const subMark = {
|
|
1059
|
+
type: 'text',
|
|
1060
|
+
marks: [],
|
|
1061
|
+
text: ' ',
|
|
1062
|
+
};
|
|
1063
|
+
this.marks.push(subMark);
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
return myMark;
|
|
1069
|
+
}
|
|
1070
|
+
parseAnchor(n, myMark, mark_Colour, infoIconData, renderedContentList) {
|
|
1071
|
+
if (n.id === '_LINK_TO_THIS' || n.textContent.trim() === '') {
|
|
1072
|
+
return myMark;
|
|
1073
|
+
}
|
|
1074
|
+
let selectionIdModified;
|
|
1075
|
+
let content;
|
|
1076
|
+
myMark = {
|
|
1077
|
+
type: 'text',
|
|
1078
|
+
marks: [],
|
|
1079
|
+
text: n.textContent,
|
|
1080
|
+
};
|
|
1081
|
+
const isFirstSentenceBold = checkFirstSentenceBold(n.parentElement);
|
|
1082
|
+
if (isFirstSentenceBold) {
|
|
1083
|
+
const b = {
|
|
1084
|
+
type: 'strong',
|
|
1085
|
+
attrs: { overridden: true },
|
|
1086
|
+
};
|
|
1087
|
+
myMark.marks?.push(b);
|
|
1088
|
+
}
|
|
1089
|
+
if (n.hash == '') {
|
|
1090
|
+
selectionIdModified = '';
|
|
1091
|
+
content = '';
|
|
1092
|
+
}
|
|
1093
|
+
else {
|
|
1094
|
+
selectionIdModified = n.hash;
|
|
1095
|
+
if (renderedContentList?.length > 0) {
|
|
1096
|
+
const firstElement = renderedContentList[0];
|
|
1097
|
+
content = firstElement.innerText;
|
|
1098
|
+
renderedContentList.shift();
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
const href = content?.trim?.() ? content : (n.href ?? '');
|
|
1102
|
+
const isLink = href && href.trim() !== '';
|
|
1103
|
+
const lnk = isLink
|
|
1104
|
+
? {
|
|
1105
|
+
type: 'link',
|
|
1106
|
+
attrs: {
|
|
1107
|
+
href: href,
|
|
1108
|
+
rel: n.rel,
|
|
1109
|
+
target: 'blank',
|
|
1110
|
+
title: null,
|
|
1111
|
+
selectionId: selectionIdModified,
|
|
1112
|
+
},
|
|
1113
|
+
}
|
|
1114
|
+
: null;
|
|
1115
|
+
const clr = {
|
|
1116
|
+
type: 'mark-text-color',
|
|
1117
|
+
attrs: {
|
|
1118
|
+
color: mark_Colour,
|
|
1119
|
+
overridden: true,
|
|
1120
|
+
},
|
|
1121
|
+
};
|
|
1122
|
+
if (n.childNodes.length === 1) {
|
|
1123
|
+
this.applyLinkAndColorMarks(myMark, lnk, clr, mark_Colour);
|
|
1124
|
+
myMark = this.parseSubMarks(n.childNodes[0], myMark, true, infoIconData);
|
|
1125
|
+
if (myMark) {
|
|
1126
|
+
this.marks.push(myMark);
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
else {
|
|
1130
|
+
for (const enodes of Array.from(n.childNodes)) {
|
|
1131
|
+
myMark = this.parseLinkText(enodes, lnk, mark_Colour, clr, myMark, infoIconData);
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
return myMark;
|
|
1135
|
+
}
|
|
1136
|
+
applyLinkAndColorMarks(myMark, lnk, clr, mark_Colour) {
|
|
1137
|
+
if (lnk) {
|
|
1138
|
+
myMark?.marks.push(lnk);
|
|
1139
|
+
if (mark_Colour) {
|
|
1140
|
+
myMark?.marks.push(clr);
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
parseLinkText(enodes, lnk, mark_Colour, clr, myMark, infoIconData) {
|
|
1145
|
+
if (enodes.nodeName === 'TEXT' || enodes.nodeName === '#text') {
|
|
1146
|
+
const subMark = {
|
|
1147
|
+
type: 'text',
|
|
1148
|
+
marks: [],
|
|
1149
|
+
text: '',
|
|
1150
|
+
};
|
|
1151
|
+
subMark.marks.push(lnk);
|
|
1152
|
+
if (mark_Colour) {
|
|
1153
|
+
subMark.marks.push(clr);
|
|
1154
|
+
}
|
|
1155
|
+
subMark.text = enodes.textContent;
|
|
1156
|
+
this.marks.push(subMark);
|
|
1157
|
+
}
|
|
1158
|
+
else if (enodes.textContent.trim() !== '') {
|
|
1159
|
+
myMark?.marks.push(lnk);
|
|
1160
|
+
if (mark_Colour) {
|
|
1161
|
+
myMark?.marks.push(clr);
|
|
1162
|
+
}
|
|
1163
|
+
myMark = this.parseSubMarks(enodes, myMark, false, infoIconData);
|
|
1164
|
+
if (myMark) {
|
|
1165
|
+
this.marks.push(myMark);
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
return myMark;
|
|
1169
|
+
}
|
|
1170
|
+
setLink(myMark) {
|
|
1171
|
+
const urlRegex = /(https?:\/\/[^\s]{1,2048})/g;
|
|
1172
|
+
if (urlRegex.test(myMark.text)) {
|
|
1173
|
+
const linkMark = {
|
|
1174
|
+
type: 'link',
|
|
1175
|
+
attrs: {
|
|
1176
|
+
href: myMark.text,
|
|
1177
|
+
target: '_blank',
|
|
1178
|
+
rel: 'noopener noreferrer',
|
|
1179
|
+
},
|
|
1180
|
+
};
|
|
1181
|
+
myMark.marks.push(linkMark);
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
parseFont(n, myMark, infoIconData, tMark) {
|
|
1185
|
+
if (!this.hasFontDetails(n)) {
|
|
1186
|
+
return myMark;
|
|
1187
|
+
}
|
|
1188
|
+
myMark = {
|
|
1189
|
+
type: 'text',
|
|
1190
|
+
marks: [],
|
|
1191
|
+
text: n.textContent,
|
|
1192
|
+
};
|
|
1193
|
+
const f = {
|
|
1194
|
+
type: 'mark-font-type',
|
|
1195
|
+
attrs: {
|
|
1196
|
+
name: n.getAttribute?.('style')
|
|
1197
|
+
? n.getAttribute('style').valueOf(0).split(':')[1]
|
|
1198
|
+
: n.parentNode.getAttribute('style').valueOf(0).split(':')[1],
|
|
1199
|
+
},
|
|
1200
|
+
};
|
|
1201
|
+
if (n.childNodes.length === 1) {
|
|
1202
|
+
myMark?.marks.push(f);
|
|
1203
|
+
return this.parseSubMarks(n.childNodes[0], myMark, true, infoIconData);
|
|
1204
|
+
}
|
|
1205
|
+
let subMark;
|
|
1206
|
+
let innerFontMark;
|
|
1207
|
+
myMark?.marks.push(f);
|
|
1208
|
+
for (const fnodes of n.childNodes) {
|
|
1209
|
+
if (fnodes.nodeName === 'IMG') {
|
|
1210
|
+
return;
|
|
1211
|
+
}
|
|
1212
|
+
if (fnodes.nodeName === 'TEXT' || fnodes.nodeName === '#text') {
|
|
1213
|
+
subMark = {
|
|
1214
|
+
type: 'text',
|
|
1215
|
+
marks: [],
|
|
1216
|
+
text: '',
|
|
1217
|
+
};
|
|
1218
|
+
subMark.marks.push(f);
|
|
1219
|
+
subMark.text = fnodes.textContent;
|
|
1220
|
+
tMark.push(subMark);
|
|
1221
|
+
}
|
|
1222
|
+
else if (fnodes.nodeName === 'FONT') {
|
|
1223
|
+
innerFontMark = {
|
|
1224
|
+
type: 'text',
|
|
1225
|
+
marks: [],
|
|
1226
|
+
text: '',
|
|
1227
|
+
};
|
|
1228
|
+
myMark = this.parseSubMarks(fnodes, innerFontMark, false, infoIconData);
|
|
1229
|
+
if (myMark?.text && myMark.text.trim() !== '') {
|
|
1230
|
+
tMark.push(myMark);
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
else {
|
|
1234
|
+
myMark = this.parseSubMarks(fnodes, myMark, false, infoIconData);
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
return myMark;
|
|
1238
|
+
}
|
|
1239
|
+
//Handling superscript and subscript with class name
|
|
1240
|
+
handleClassName(className, mark) {
|
|
1241
|
+
if (className == 'superscript') {
|
|
1242
|
+
const m = {
|
|
1243
|
+
type: 'super',
|
|
1244
|
+
attrs: {
|
|
1245
|
+
overridden: true,
|
|
1246
|
+
},
|
|
1247
|
+
};
|
|
1248
|
+
mark?.marks.push(m);
|
|
1249
|
+
}
|
|
1250
|
+
else if (className == 'subscript') {
|
|
1251
|
+
const m = {
|
|
1252
|
+
type: 'sub',
|
|
1253
|
+
attrs: {
|
|
1254
|
+
overridden: true,
|
|
1255
|
+
},
|
|
1256
|
+
};
|
|
1257
|
+
mark?.marks.push(m);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
getEmptyTextMark() {
|
|
1261
|
+
return {
|
|
1262
|
+
type: 'text',
|
|
1263
|
+
marks: [],
|
|
1264
|
+
text: ' ',
|
|
1265
|
+
};
|
|
1266
|
+
}
|
|
1267
|
+
hasFontDetails(n) {
|
|
1268
|
+
let bOk = false;
|
|
1269
|
+
if (n.getAttribute?.('style')) {
|
|
1270
|
+
bOk = true;
|
|
1271
|
+
}
|
|
1272
|
+
if (!bOk && n.parentNode.getAttribute?.('style')) {
|
|
1273
|
+
bOk = true;
|
|
1274
|
+
}
|
|
1275
|
+
return bOk;
|
|
1276
|
+
}
|
|
1277
|
+
parseSubMarks(n, mark, _hasOneChild, infoIconData) {
|
|
1278
|
+
let retMark = null;
|
|
1279
|
+
let mark_Colour;
|
|
1280
|
+
let em;
|
|
1281
|
+
if (n.nodeName === 'A') {
|
|
1282
|
+
mark_Colour = n.getAttribute('color');
|
|
1283
|
+
}
|
|
1284
|
+
if (n.nodeName === 'BR') {
|
|
1285
|
+
return;
|
|
1286
|
+
}
|
|
1287
|
+
switch (n.nodeName) {
|
|
1288
|
+
case 'FONT':
|
|
1289
|
+
retMark = this.parseFontWithInfoicon(n, mark, retMark, infoIconData);
|
|
1290
|
+
break;
|
|
1291
|
+
case 'MARK-TEXT-HIGHLIGHT':
|
|
1292
|
+
this.handleTextMark(n, this.getHighLightAndTextColor);
|
|
1293
|
+
break;
|
|
1294
|
+
case 'TEXT':
|
|
1295
|
+
case '#text':
|
|
1296
|
+
if (mark === null || mark === undefined) {
|
|
1297
|
+
// ignore
|
|
1298
|
+
}
|
|
1299
|
+
if (mark) {
|
|
1300
|
+
retMark = {
|
|
1301
|
+
type: 'text',
|
|
1302
|
+
marks: mark?.marks,
|
|
1303
|
+
text: n.textContent,
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1306
|
+
else {
|
|
1307
|
+
retMark = {
|
|
1308
|
+
type: 'text',
|
|
1309
|
+
text: n.textContent,
|
|
1310
|
+
};
|
|
1311
|
+
}
|
|
1312
|
+
break;
|
|
1313
|
+
case 'A':
|
|
1314
|
+
retMark = this.parseAnchorWithInfoIcon(n, mark_Colour, mark, retMark, infoIconData);
|
|
1315
|
+
break;
|
|
1316
|
+
case 'STRONG':
|
|
1317
|
+
retMark = this.parseStrongWithInfoicon(n, mark, retMark, infoIconData);
|
|
1318
|
+
break;
|
|
1319
|
+
case 'EM':
|
|
1320
|
+
retMark = this.parseEMWithInfoicon(n, em, mark, retMark, infoIconData);
|
|
1321
|
+
break;
|
|
1322
|
+
case 'U':
|
|
1323
|
+
retMark = this.parseUnderlineWithInfoicon(n, mark, retMark, infoIconData);
|
|
1324
|
+
break;
|
|
1325
|
+
case 'SUP':
|
|
1326
|
+
if (n.textContent.trim() !== '' && n.innerText.trim() !== '') {
|
|
1327
|
+
const sup = this.getSuperScriptMarks(n, infoIconData);
|
|
1328
|
+
retMark = sup || retMark;
|
|
1329
|
+
}
|
|
1330
|
+
break;
|
|
1331
|
+
case 'SUB':
|
|
1332
|
+
if (n.textContent.trim() !== '') {
|
|
1333
|
+
this.marks.push(this.getSubscriptMarks(n));
|
|
1334
|
+
}
|
|
1335
|
+
break;
|
|
1336
|
+
}
|
|
1337
|
+
return retMark;
|
|
1338
|
+
}
|
|
1339
|
+
parseFontWithInfoicon(n, mark, retMark, infoIconData) {
|
|
1340
|
+
if (n.textContent.trim() === '') {
|
|
1341
|
+
return retMark;
|
|
1342
|
+
}
|
|
1343
|
+
if (this.hasFontDetails(n)) {
|
|
1344
|
+
const f = {
|
|
1345
|
+
type: 'mark-font-type',
|
|
1346
|
+
attrs: {
|
|
1347
|
+
name: n.getAttribute?.('style')
|
|
1348
|
+
? n.getAttribute('style').valueOf(0).split(':')[1]
|
|
1349
|
+
: n.parentNode.getAttribute('style').valueOf(0).split(':')[1],
|
|
1350
|
+
},
|
|
1351
|
+
};
|
|
1352
|
+
if (n.childNodes.length === 1) {
|
|
1353
|
+
mark?.marks.push(f);
|
|
1354
|
+
retMark = this.parseSubMarks(n.childNodes[0], mark, true, infoIconData);
|
|
1355
|
+
}
|
|
1356
|
+
else {
|
|
1357
|
+
const m = mark?.marks.push(f);
|
|
1358
|
+
retMark = {
|
|
1359
|
+
type: 'text',
|
|
1360
|
+
marks: [],
|
|
1361
|
+
};
|
|
1362
|
+
if (!Number.isNaN(m)) {
|
|
1363
|
+
retMark = mark;
|
|
1364
|
+
}
|
|
1365
|
+
for (const enodes of n.childNodes) {
|
|
1366
|
+
retMark = this.parseSubMarks(enodes, retMark, false, infoIconData);
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
return retMark;
|
|
1371
|
+
}
|
|
1372
|
+
parseUnderlineWithInfoicon(n, mark, retMark, infoIconData) {
|
|
1373
|
+
if (n.textContent.trim() !== '') {
|
|
1374
|
+
const u = {
|
|
1375
|
+
type: 'underline',
|
|
1376
|
+
attrs: { overridden: true },
|
|
1377
|
+
};
|
|
1378
|
+
if (n.childNodes.length === 1) {
|
|
1379
|
+
mark?.marks.push(u);
|
|
1380
|
+
retMark = this.parseSubMarks(n.childNodes[0], mark, true, infoIconData);
|
|
1381
|
+
}
|
|
1382
|
+
else {
|
|
1383
|
+
mark?.marks.push(u);
|
|
1384
|
+
retMark = {
|
|
1385
|
+
type: 'text',
|
|
1386
|
+
marks: mark?.marks,
|
|
1387
|
+
};
|
|
1388
|
+
for (const unodes of Array.from(n.childNodes)) {
|
|
1389
|
+
retMark = this.parseSubMarks(unodes, retMark, false, infoIconData);
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
return retMark;
|
|
1394
|
+
}
|
|
1395
|
+
parseEMWithInfoicon(n, em, mark, retMark, infoIconData) {
|
|
1396
|
+
if (n.textContent.trim() !== '') {
|
|
1397
|
+
em = {
|
|
1398
|
+
type: 'em',
|
|
1399
|
+
attrs: { overridden: true },
|
|
1400
|
+
};
|
|
1401
|
+
if (n.childNodes.length === 1) {
|
|
1402
|
+
mark?.marks.push(em);
|
|
1403
|
+
retMark = this.parseSubMarks(n.childNodes[0], mark, true, infoIconData);
|
|
1404
|
+
}
|
|
1405
|
+
else {
|
|
1406
|
+
mark?.marks.push(em);
|
|
1407
|
+
retMark = {
|
|
1408
|
+
type: 'text',
|
|
1409
|
+
marks: mark?.marks,
|
|
1410
|
+
};
|
|
1411
|
+
for (const enodes of Array.from(n.childNodes)) {
|
|
1412
|
+
retMark = this.parseSubMarks(enodes, retMark, false, infoIconData);
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
return retMark;
|
|
1417
|
+
}
|
|
1418
|
+
parseStrongWithInfoicon(n, mark, retMark, infoIconData) {
|
|
1419
|
+
if (n.textContent.trim() === '') {
|
|
1420
|
+
return retMark;
|
|
1421
|
+
}
|
|
1422
|
+
const b = {
|
|
1423
|
+
type: 'strong',
|
|
1424
|
+
attrs: { overridden: true },
|
|
1425
|
+
};
|
|
1426
|
+
if (n.childNodes.length === 1) {
|
|
1427
|
+
mark?.marks.push(b);
|
|
1428
|
+
retMark = this.parseSubMarks(n.childNodes[0], mark, true, infoIconData);
|
|
1429
|
+
}
|
|
1430
|
+
else {
|
|
1431
|
+
mark?.marks.push(b);
|
|
1432
|
+
retMark = {
|
|
1433
|
+
type: 'text',
|
|
1434
|
+
marks: mark?.marks,
|
|
1435
|
+
};
|
|
1436
|
+
for (let bi = 0; bi < n.childNodes.length; bi++) {
|
|
1437
|
+
const bnodes = n.childNodes[bi];
|
|
1438
|
+
retMark = this.parseSubMarks(bnodes, retMark, false, infoIconData);
|
|
1439
|
+
if (retMark) {
|
|
1440
|
+
if (bi < n.childNodes.length - 1) {
|
|
1441
|
+
this.marks.push(retMark);
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
else {
|
|
1445
|
+
retMark = {
|
|
1446
|
+
type: 'text',
|
|
1447
|
+
marks: mark?.marks,
|
|
1448
|
+
};
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
return retMark;
|
|
1453
|
+
}
|
|
1454
|
+
parseAnchorWithInfoIcon(n, mark_Colour, mark, retMark, infoIconData) {
|
|
1455
|
+
if (n.textContent.trim() !== '') {
|
|
1456
|
+
const lnk = {
|
|
1457
|
+
type: 'link',
|
|
1458
|
+
attrs: {
|
|
1459
|
+
href: n.href,
|
|
1460
|
+
rel: n.rel,
|
|
1461
|
+
target: 'blank',
|
|
1462
|
+
title: null,
|
|
1463
|
+
},
|
|
1464
|
+
};
|
|
1465
|
+
const clr = {
|
|
1466
|
+
type: 'mark-text-color',
|
|
1467
|
+
attrs: {
|
|
1468
|
+
color: mark_Colour,
|
|
1469
|
+
overridden: true,
|
|
1470
|
+
},
|
|
1471
|
+
};
|
|
1472
|
+
if (n.childNodes.length === 1) {
|
|
1473
|
+
mark?.marks.push(lnk);
|
|
1474
|
+
if (mark_Colour) {
|
|
1475
|
+
mark?.marks.push(clr);
|
|
1476
|
+
}
|
|
1477
|
+
retMark = this.parseSubMarks(n.childNodes[0], mark, true, infoIconData);
|
|
1478
|
+
}
|
|
1479
|
+
else {
|
|
1480
|
+
mark?.marks.push(lnk);
|
|
1481
|
+
if (mark_Colour) {
|
|
1482
|
+
mark?.marks.push(clr);
|
|
1483
|
+
}
|
|
1484
|
+
retMark = {
|
|
1485
|
+
type: 'text',
|
|
1486
|
+
marks: mark?.marks,
|
|
1487
|
+
};
|
|
1488
|
+
for (const enodes of Array.from(n.childNodes)) {
|
|
1489
|
+
retMark = this.parseSubMarks(enodes, retMark, false, infoIconData);
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
return retMark;
|
|
1494
|
+
}
|
|
1495
|
+
getBaseElement() {
|
|
1496
|
+
return {
|
|
1497
|
+
type: 'paragraph',
|
|
1498
|
+
attrs: {
|
|
1499
|
+
styleName: this.styleName,
|
|
1500
|
+
align: this.align,
|
|
1501
|
+
indent: this.indent,
|
|
1502
|
+
id: this.id ? this.id : '',
|
|
1503
|
+
capco: this.capco ? this.capco : '',
|
|
1504
|
+
selectionId: this.selectionId ? this.selectionId : undefined,
|
|
1505
|
+
overriddenLineSpacing: this.overriddenLineSpacing,
|
|
1506
|
+
lineSpacing: this.lineSpacing,
|
|
1507
|
+
overriddenLineSpaceingValue: this.overriddenLineSpaceingValue,
|
|
1508
|
+
overriddenAlignValue: this.overriddenAlignValue,
|
|
1509
|
+
overriddenAlign: this.overriddenAlign,
|
|
1510
|
+
hangingindent: this.hangingindent,
|
|
1511
|
+
reset: this.reset,
|
|
1512
|
+
},
|
|
1513
|
+
content: null,
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
getBoldMarks(node) {
|
|
1517
|
+
return {
|
|
1518
|
+
type: 'text',
|
|
1519
|
+
marks: [
|
|
1520
|
+
{
|
|
1521
|
+
type: 'strong',
|
|
1522
|
+
attrs: { overridden: true },
|
|
1523
|
+
},
|
|
1524
|
+
],
|
|
1525
|
+
text: node.innerText,
|
|
1526
|
+
};
|
|
1527
|
+
}
|
|
1528
|
+
getEmMarks(node, data) {
|
|
1529
|
+
if (!node.childNodes) {
|
|
1530
|
+
return {
|
|
1531
|
+
type: 'text',
|
|
1532
|
+
marks: [
|
|
1533
|
+
{
|
|
1534
|
+
type: 'em',
|
|
1535
|
+
attrs: { overridden: true },
|
|
1536
|
+
},
|
|
1537
|
+
],
|
|
1538
|
+
text: node.innerText,
|
|
1539
|
+
};
|
|
1540
|
+
}
|
|
1541
|
+
for (const childNode of Array.from(node.childNodes)) {
|
|
1542
|
+
if (childNode.id === 'infoIcon') {
|
|
1543
|
+
const infoMark = this.getEmInfoIconMark(childNode, data);
|
|
1544
|
+
if (infoMark) {
|
|
1545
|
+
return infoMark;
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
else {
|
|
1549
|
+
return {
|
|
1550
|
+
type: 'text',
|
|
1551
|
+
marks: [
|
|
1552
|
+
{
|
|
1553
|
+
type: 'em',
|
|
1554
|
+
attrs: { overridden: true },
|
|
1555
|
+
},
|
|
1556
|
+
],
|
|
1557
|
+
text: childNode.textContent,
|
|
1558
|
+
};
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
getEmInfoIconMark(childNode, data) {
|
|
1563
|
+
for (const infoNode of Array.from(childNode.childNodes)) {
|
|
1564
|
+
const infoID = infoNode.id;
|
|
1565
|
+
for (const dataNode of data[0].childNodes) {
|
|
1566
|
+
if (infoID === dataNode.id) {
|
|
1567
|
+
const infoDescription = dataNode.innerText;
|
|
1568
|
+
const infoIconClassData = infoDescription.includes('Common access card required')
|
|
1569
|
+
? infoIconLockData
|
|
1570
|
+
: infoIconCircleData;
|
|
1571
|
+
return this.getInfoIconJson(infoDescription, infoIconClassData);
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
return undefined;
|
|
1576
|
+
}
|
|
1577
|
+
getUnderLineMarks(node) {
|
|
1578
|
+
return {
|
|
1579
|
+
type: 'text',
|
|
1580
|
+
marks: [
|
|
1581
|
+
{
|
|
1582
|
+
type: 'underline',
|
|
1583
|
+
attrs: { overridden: true },
|
|
1584
|
+
},
|
|
1585
|
+
],
|
|
1586
|
+
text: node.innerText,
|
|
1587
|
+
};
|
|
1588
|
+
}
|
|
1589
|
+
getSuperScriptMarks(node, data) {
|
|
1590
|
+
if (data && node.id === 'infoIcon') {
|
|
1591
|
+
const infoID = node.childNodes[0]['id'];
|
|
1592
|
+
for (const childNode of data[0].childNodes) {
|
|
1593
|
+
if (infoID === childNode?.id) {
|
|
1594
|
+
const infoDescription = childNode.innerText;
|
|
1595
|
+
const infoIconClassData = infoDescription.includes('Common access card required')
|
|
1596
|
+
? infoIconLockData
|
|
1597
|
+
: infoIconCircleData;
|
|
1598
|
+
const InfoJson = this.getInfoIconJson(infoDescription, infoIconClassData);
|
|
1599
|
+
return InfoJson;
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
else {
|
|
1604
|
+
return {
|
|
1605
|
+
type: 'text',
|
|
1606
|
+
marks: [
|
|
1607
|
+
{
|
|
1608
|
+
type: 'super',
|
|
1609
|
+
attrs: { overridden: true },
|
|
1610
|
+
},
|
|
1611
|
+
],
|
|
1612
|
+
text: node.innerText,
|
|
1613
|
+
};
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
//Method for highlight and/or text color
|
|
1617
|
+
getHighLightAndTextColor(node) {
|
|
1618
|
+
const marks = [];
|
|
1619
|
+
if (node.getAttribute('highlight-color')) {
|
|
1620
|
+
marks.push({
|
|
1621
|
+
type: 'mark-text-highlight',
|
|
1622
|
+
attrs: {
|
|
1623
|
+
highlightColor: node.getAttribute('highlight-color'),
|
|
1624
|
+
overridden: true,
|
|
1625
|
+
},
|
|
1626
|
+
});
|
|
1627
|
+
}
|
|
1628
|
+
if (node.getAttribute('color')) {
|
|
1629
|
+
marks.push({
|
|
1630
|
+
type: 'mark-text-color',
|
|
1631
|
+
attrs: {
|
|
1632
|
+
color: node.getAttribute('color'),
|
|
1633
|
+
overridden: true,
|
|
1634
|
+
},
|
|
1635
|
+
});
|
|
1636
|
+
}
|
|
1637
|
+
if (marks.length > 0) {
|
|
1638
|
+
return {
|
|
1639
|
+
type: 'text',
|
|
1640
|
+
marks,
|
|
1641
|
+
text: node.innerText,
|
|
1642
|
+
};
|
|
1643
|
+
}
|
|
1644
|
+
return undefined;
|
|
1645
|
+
}
|
|
1646
|
+
getSubscriptMarks(node) {
|
|
1647
|
+
return {
|
|
1648
|
+
type: 'text',
|
|
1649
|
+
marks: [
|
|
1650
|
+
{
|
|
1651
|
+
type: 'sub',
|
|
1652
|
+
attrs: { overridden: true },
|
|
1653
|
+
},
|
|
1654
|
+
],
|
|
1655
|
+
text: node.innerText,
|
|
1656
|
+
};
|
|
1657
|
+
}
|
|
1658
|
+
getLinkMarks(node) {
|
|
1659
|
+
return {
|
|
1660
|
+
type: 'text',
|
|
1661
|
+
marks: [
|
|
1662
|
+
{
|
|
1663
|
+
type: 'link',
|
|
1664
|
+
attrs: {
|
|
1665
|
+
href: node.href,
|
|
1666
|
+
rel: node.rel,
|
|
1667
|
+
target: 'blank',
|
|
1668
|
+
title: null,
|
|
1669
|
+
},
|
|
1670
|
+
},
|
|
1671
|
+
],
|
|
1672
|
+
text: node.innerText,
|
|
1673
|
+
};
|
|
1674
|
+
}
|
|
1675
|
+
getText(node) {
|
|
1676
|
+
return {
|
|
1677
|
+
type: 'text',
|
|
1678
|
+
text: node.innerText ? node.innerText : node.textContent,
|
|
1679
|
+
};
|
|
1680
|
+
}
|
|
1681
|
+
getInfoIconJson(infoDescription, Data) {
|
|
1682
|
+
return {
|
|
1683
|
+
type: 'infoicon',
|
|
1684
|
+
attrs: {
|
|
1685
|
+
from: null,
|
|
1686
|
+
to: null,
|
|
1687
|
+
description: infoDescription,
|
|
1688
|
+
infoIcon: {
|
|
1689
|
+
name: Data.infoIconClass,
|
|
1690
|
+
unicode: Data.infoIconUnicode,
|
|
1691
|
+
selected: false,
|
|
1692
|
+
},
|
|
1693
|
+
},
|
|
1694
|
+
};
|
|
1695
|
+
}
|
|
1696
|
+
render() {
|
|
1697
|
+
const element = this.getBaseElement();
|
|
1698
|
+
element.content = this.marks;
|
|
1699
|
+
return element;
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
export class LicitErrorTextElement extends LicitElement {
|
|
1703
|
+
getBaseElement() {
|
|
1704
|
+
return {
|
|
1705
|
+
type: 'paragraph',
|
|
1706
|
+
attrs: {
|
|
1707
|
+
align: 'center',
|
|
1708
|
+
color: null,
|
|
1709
|
+
id: null,
|
|
1710
|
+
indent: null,
|
|
1711
|
+
lineSpacing: null,
|
|
1712
|
+
paddingBottom: null,
|
|
1713
|
+
paddingTop: null,
|
|
1714
|
+
},
|
|
1715
|
+
content: [
|
|
1716
|
+
{
|
|
1717
|
+
type: 'text',
|
|
1718
|
+
marks: [
|
|
1719
|
+
{ type: 'strong', attrs: { overridden: true } },
|
|
1720
|
+
{
|
|
1721
|
+
type: 'mark-text-color',
|
|
1722
|
+
attrs: { color: '#f20d0d', overridden: true },
|
|
1723
|
+
},
|
|
1724
|
+
],
|
|
1725
|
+
text: this.text,
|
|
1726
|
+
},
|
|
1727
|
+
],
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1730
|
+
text;
|
|
1731
|
+
constructor(altText) {
|
|
1732
|
+
super();
|
|
1733
|
+
this.text = altText;
|
|
1734
|
+
}
|
|
1735
|
+
render() {
|
|
1736
|
+
const element = this.getBaseElement();
|
|
1737
|
+
return element;
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
export class LicitBulletListItemElement extends LicitElement {
|
|
1741
|
+
getBaseElement() {
|
|
1742
|
+
return {
|
|
1743
|
+
type: 'list_item',
|
|
1744
|
+
attrs: {},
|
|
1745
|
+
content: [],
|
|
1746
|
+
};
|
|
1747
|
+
}
|
|
1748
|
+
node;
|
|
1749
|
+
constructor(_node) {
|
|
1750
|
+
super();
|
|
1751
|
+
this.node = _node;
|
|
1752
|
+
}
|
|
1753
|
+
render() {
|
|
1754
|
+
const element = this.getBaseElement();
|
|
1755
|
+
const paragraph = new NewLicitParagraphElement(this.node, null);
|
|
1756
|
+
element.content.push(paragraph.render());
|
|
1757
|
+
return element;
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
export class LicitBulletListElement extends LicitElement {
|
|
1761
|
+
getBaseElement() {
|
|
1762
|
+
return {
|
|
1763
|
+
type: 'bullet_list',
|
|
1764
|
+
attrs: {
|
|
1765
|
+
id: null,
|
|
1766
|
+
indent: this.indent,
|
|
1767
|
+
listStyleType: null,
|
|
1768
|
+
},
|
|
1769
|
+
content: [],
|
|
1770
|
+
};
|
|
1771
|
+
}
|
|
1772
|
+
listItems = [];
|
|
1773
|
+
indent = 0;
|
|
1774
|
+
constructor(indent) {
|
|
1775
|
+
super();
|
|
1776
|
+
this.indent = indent;
|
|
1777
|
+
}
|
|
1778
|
+
addItem(item) {
|
|
1779
|
+
this.listItems.push(item);
|
|
1780
|
+
}
|
|
1781
|
+
render() {
|
|
1782
|
+
const element = this.getBaseElement();
|
|
1783
|
+
for (const item of this.listItems) {
|
|
1784
|
+
const obj = item.render();
|
|
1785
|
+
element.content.push(obj);
|
|
1786
|
+
}
|
|
1787
|
+
return element;
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
export class LicitTableCellElement extends LicitElement {
|
|
1791
|
+
getBaseElement() {
|
|
1792
|
+
return {
|
|
1793
|
+
type: 'table_cell',
|
|
1794
|
+
attrs: {
|
|
1795
|
+
colspan: 1,
|
|
1796
|
+
rowspan: 1,
|
|
1797
|
+
colwidth: this.colwidth,
|
|
1798
|
+
background: this.bgColor,
|
|
1799
|
+
vignette: false,
|
|
1800
|
+
fullSize: 0,
|
|
1801
|
+
vAlign: this.vAlign,
|
|
1802
|
+
},
|
|
1803
|
+
content: [
|
|
1804
|
+
{
|
|
1805
|
+
type: 'paragraph',
|
|
1806
|
+
attrs: {
|
|
1807
|
+
align: this.align,
|
|
1808
|
+
},
|
|
1809
|
+
content: [
|
|
1810
|
+
{
|
|
1811
|
+
type: 'text',
|
|
1812
|
+
text: '',
|
|
1813
|
+
marks: [
|
|
1814
|
+
{
|
|
1815
|
+
type: 'mark-font-type',
|
|
1816
|
+
attrs: {
|
|
1817
|
+
name: 'Times New Roman',
|
|
1818
|
+
},
|
|
1819
|
+
},
|
|
1820
|
+
{
|
|
1821
|
+
type: 'mark-font-size',
|
|
1822
|
+
attrs: {
|
|
1823
|
+
pt: 12,
|
|
1824
|
+
},
|
|
1825
|
+
},
|
|
1826
|
+
],
|
|
1827
|
+
},
|
|
1828
|
+
],
|
|
1829
|
+
},
|
|
1830
|
+
],
|
|
1831
|
+
};
|
|
1832
|
+
}
|
|
1833
|
+
text;
|
|
1834
|
+
rowspan = 1;
|
|
1835
|
+
colspan = 1;
|
|
1836
|
+
bgColor;
|
|
1837
|
+
align;
|
|
1838
|
+
colwidth;
|
|
1839
|
+
vAlign;
|
|
1840
|
+
constructor(text, bgColor, alignment, colWidth, verticalAlignment) {
|
|
1841
|
+
super();
|
|
1842
|
+
this.text = text;
|
|
1843
|
+
this.bgColor = bgColor;
|
|
1844
|
+
this.align = alignment;
|
|
1845
|
+
this.colwidth = colWidth;
|
|
1846
|
+
this.vAlign = verticalAlignment;
|
|
1847
|
+
}
|
|
1848
|
+
render() {
|
|
1849
|
+
const element = this.getBaseElement();
|
|
1850
|
+
element.content[0].content[0].text = this.text;
|
|
1851
|
+
element.attrs.colspan = this.colspan;
|
|
1852
|
+
element.attrs.rowspan = this.rowspan;
|
|
1853
|
+
element.attrs.background = this.bgColor;
|
|
1854
|
+
element.attrs.vAlign = this.vAlign;
|
|
1855
|
+
return element;
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
export class LicitTableCellParagraph extends LicitElement {
|
|
1859
|
+
getBaseElement() {
|
|
1860
|
+
return {
|
|
1861
|
+
type: 'table_cell',
|
|
1862
|
+
attrs: {
|
|
1863
|
+
colspan: 1,
|
|
1864
|
+
rowspan: 1,
|
|
1865
|
+
colwidth: this.colWidth,
|
|
1866
|
+
background: this.bgColor,
|
|
1867
|
+
vAlign: this.vAlign,
|
|
1868
|
+
},
|
|
1869
|
+
content: [],
|
|
1870
|
+
};
|
|
1871
|
+
}
|
|
1872
|
+
node;
|
|
1873
|
+
rowspan = 1;
|
|
1874
|
+
colspan = 1;
|
|
1875
|
+
bgColor;
|
|
1876
|
+
colWidth;
|
|
1877
|
+
content = [];
|
|
1878
|
+
vAlign;
|
|
1879
|
+
constructor(node, bgColor, colwidth, vericalAlignment) {
|
|
1880
|
+
super();
|
|
1881
|
+
this.bgColor = bgColor;
|
|
1882
|
+
this.colWidth = colwidth;
|
|
1883
|
+
this.vAlign = vericalAlignment;
|
|
1884
|
+
const paragraph = new NewLicitParagraphElement(node, null);
|
|
1885
|
+
if (paragraph) {
|
|
1886
|
+
this.content.push(paragraph.render());
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
render() {
|
|
1890
|
+
const element = this.getBaseElement();
|
|
1891
|
+
element.content = this.content;
|
|
1892
|
+
element.attrs.colspan = this.colspan;
|
|
1893
|
+
element.attrs.rowspan = this.rowspan;
|
|
1894
|
+
element.attrs.background = this.bgColor;
|
|
1895
|
+
element.attrs.vAlign = this.vAlign;
|
|
1896
|
+
return element;
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
export class NewLicitTableCellParagraph extends LicitElement {
|
|
1900
|
+
getBaseElement() {
|
|
1901
|
+
const defaultColWidth = 100;
|
|
1902
|
+
const defaultBgColor = '#FFFFFF';
|
|
1903
|
+
return {
|
|
1904
|
+
type: 'table_cell',
|
|
1905
|
+
attrs: {
|
|
1906
|
+
colspan: 1,
|
|
1907
|
+
rowspan: 1,
|
|
1908
|
+
colwidth: this.colWidth || defaultColWidth,
|
|
1909
|
+
background: this.bgColor || defaultBgColor,
|
|
1910
|
+
vAlign: this.vAlign || 'top',
|
|
1911
|
+
},
|
|
1912
|
+
content: [],
|
|
1913
|
+
};
|
|
1914
|
+
}
|
|
1915
|
+
node;
|
|
1916
|
+
rowspan = 1;
|
|
1917
|
+
colspan = 1;
|
|
1918
|
+
bgColor;
|
|
1919
|
+
colWidth;
|
|
1920
|
+
content = [];
|
|
1921
|
+
vAlign;
|
|
1922
|
+
constructor(node, bgColor, colwidth, vericalAlignment) {
|
|
1923
|
+
super();
|
|
1924
|
+
this.vAlign = vericalAlignment;
|
|
1925
|
+
this.bgColor = bgColor;
|
|
1926
|
+
this.colWidth = colwidth;
|
|
1927
|
+
const paragraph = new NewLicitParagraphElement(node, null);
|
|
1928
|
+
//paraElement
|
|
1929
|
+
if (paragraph) {
|
|
1930
|
+
this.content.push(paragraph.render());
|
|
1931
|
+
}
|
|
1932
|
+
}
|
|
1933
|
+
render() {
|
|
1934
|
+
const baseElement = this.getBaseElement();
|
|
1935
|
+
baseElement.content = this.content;
|
|
1936
|
+
baseElement.attrs = {
|
|
1937
|
+
...baseElement.attrs,
|
|
1938
|
+
colspan: this.colspan,
|
|
1939
|
+
rowspan: this.rowspan,
|
|
1940
|
+
background: this.bgColor,
|
|
1941
|
+
vAlign: this.vAlign,
|
|
1942
|
+
};
|
|
1943
|
+
return baseElement;
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
export class LicitTableCellImageElement extends LicitElement {
|
|
1947
|
+
getBaseElement() {
|
|
1948
|
+
return {
|
|
1949
|
+
type: 'table_cell',
|
|
1950
|
+
attrs: {
|
|
1951
|
+
colspan: 1,
|
|
1952
|
+
rowspan: 1,
|
|
1953
|
+
colwidth: this.colWidth,
|
|
1954
|
+
borderColor: null,
|
|
1955
|
+
borderLeft: null,
|
|
1956
|
+
borderRight: null,
|
|
1957
|
+
borderBottom: null,
|
|
1958
|
+
borderTop: null,
|
|
1959
|
+
background: this.bgColor,
|
|
1960
|
+
vignette: false,
|
|
1961
|
+
fullSize: this.fillImg,
|
|
1962
|
+
},
|
|
1963
|
+
content: [
|
|
1964
|
+
{
|
|
1965
|
+
type: 'paragraph',
|
|
1966
|
+
attrs: {
|
|
1967
|
+
styleName: 'Normal',
|
|
1968
|
+
},
|
|
1969
|
+
content: [
|
|
1970
|
+
{
|
|
1971
|
+
type: 'image',
|
|
1972
|
+
attrs: {
|
|
1973
|
+
align: 'center',
|
|
1974
|
+
alt: this.alt,
|
|
1975
|
+
crop: null,
|
|
1976
|
+
height: this.height,
|
|
1977
|
+
rotate: null,
|
|
1978
|
+
src: this.src,
|
|
1979
|
+
title: null,
|
|
1980
|
+
width: null,
|
|
1981
|
+
fitToParent: this.fitToParent,
|
|
1982
|
+
},
|
|
1983
|
+
},
|
|
1984
|
+
],
|
|
1985
|
+
},
|
|
1986
|
+
],
|
|
1987
|
+
};
|
|
1988
|
+
}
|
|
1989
|
+
text;
|
|
1990
|
+
src;
|
|
1991
|
+
rowspan = 1;
|
|
1992
|
+
colspan = 1;
|
|
1993
|
+
height;
|
|
1994
|
+
bgColor;
|
|
1995
|
+
colWidth;
|
|
1996
|
+
alt;
|
|
1997
|
+
fillImg;
|
|
1998
|
+
fitToParent;
|
|
1999
|
+
constructor(src, fillImg, fitToParent, bgColor, imgHeight, colWidth, alt) {
|
|
2000
|
+
super();
|
|
2001
|
+
this.src = src;
|
|
2002
|
+
this.bgColor = bgColor;
|
|
2003
|
+
this.height = imgHeight;
|
|
2004
|
+
this.colWidth = colWidth;
|
|
2005
|
+
this.alt = alt;
|
|
2006
|
+
this.fillImg = fillImg;
|
|
2007
|
+
this.fitToParent = fitToParent;
|
|
2008
|
+
}
|
|
2009
|
+
render() {
|
|
2010
|
+
const element = this.getBaseElement();
|
|
2011
|
+
element.attrs.colspan = this.colspan;
|
|
2012
|
+
element.attrs.rowspan = this.rowspan;
|
|
2013
|
+
element.attrs.colwidth = this.colWidth;
|
|
2014
|
+
element.attrs.background = this.bgColor;
|
|
2015
|
+
return element;
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
export class LicitVignetteElement extends LicitElement {
|
|
2019
|
+
getBaseElement() {
|
|
2020
|
+
const width = '0.25px';
|
|
2021
|
+
const style = 'solid';
|
|
2022
|
+
const cssValue = `${width} ${style} ${this.borderColor}`;
|
|
2023
|
+
return {
|
|
2024
|
+
type: 'table_cell',
|
|
2025
|
+
attrs: {
|
|
2026
|
+
colspan: 1,
|
|
2027
|
+
rowspan: 1,
|
|
2028
|
+
colwidth: this.width,
|
|
2029
|
+
borderColor: this.borderColor,
|
|
2030
|
+
borderTop: cssValue,
|
|
2031
|
+
borderBottom: cssValue,
|
|
2032
|
+
borderLeft: cssValue,
|
|
2033
|
+
borderRight: cssValue,
|
|
2034
|
+
background: this.bgColor,
|
|
2035
|
+
vignette: true,
|
|
2036
|
+
},
|
|
2037
|
+
content: [],
|
|
2038
|
+
};
|
|
2039
|
+
}
|
|
2040
|
+
text;
|
|
2041
|
+
src;
|
|
2042
|
+
rowspan = 1;
|
|
2043
|
+
colspan = 1;
|
|
2044
|
+
borderColor;
|
|
2045
|
+
bgColor;
|
|
2046
|
+
isVignet;
|
|
2047
|
+
width = [];
|
|
2048
|
+
content = [];
|
|
2049
|
+
constructor(node, borderColor, bgColor, width) {
|
|
2050
|
+
super();
|
|
2051
|
+
this.borderColor = borderColor === '#undefined' ? '#36598d' : borderColor;
|
|
2052
|
+
this.bgColor = bgColor || '#dce6f2';
|
|
2053
|
+
this.width = [width];
|
|
2054
|
+
this.ConvertElements(node);
|
|
2055
|
+
}
|
|
2056
|
+
ConvertElements(node) {
|
|
2057
|
+
for (const n of Array.from(node.childNodes)) {
|
|
2058
|
+
//SL-1
|
|
2059
|
+
switch (n.nodeName) {
|
|
2060
|
+
case 'P': {
|
|
2061
|
+
const paragraph = new NewLicitParagraphElement(n, null);
|
|
2062
|
+
if (paragraph) {
|
|
2063
|
+
this.content.push(paragraph.render());
|
|
2064
|
+
}
|
|
2065
|
+
break;
|
|
2066
|
+
}
|
|
2067
|
+
case 'DIV': {
|
|
2068
|
+
this.convertDiv(n);
|
|
2069
|
+
break;
|
|
2070
|
+
}
|
|
2071
|
+
case 'SPAN': {
|
|
2072
|
+
for (const pNode of Array.from(n.childNodes)) {
|
|
2073
|
+
this.handleVignetteSpan(pNode);
|
|
2074
|
+
}
|
|
2075
|
+
break;
|
|
2076
|
+
}
|
|
2077
|
+
case 'IMG': {
|
|
2078
|
+
const imgNode = n;
|
|
2079
|
+
const source = imgNode?.src;
|
|
2080
|
+
if (!source)
|
|
2081
|
+
break;
|
|
2082
|
+
const alt = imgNode?.alt;
|
|
2083
|
+
const width = imgNode?.getAttribute('width');
|
|
2084
|
+
const height = imgNode?.getAttribute('height');
|
|
2085
|
+
const imgElement = new LicitParagraphImageElement(source, alt, width, height);
|
|
2086
|
+
this.content.push(imgElement.render());
|
|
2087
|
+
break;
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
convertDiv(n) {
|
|
2093
|
+
for (const childNode of Array.from(n.childNodes)) {
|
|
2094
|
+
if (childNode.nodeName === 'SPAN') {
|
|
2095
|
+
this.processSpanChildren(childNode);
|
|
2096
|
+
}
|
|
2097
|
+
else if (childNode.nodeName === 'DIV') {
|
|
2098
|
+
this.processDivChildren(childNode);
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
processSpanChildren(spanNode) {
|
|
2103
|
+
for (const grandChildNode of Array.from(spanNode.childNodes)) {
|
|
2104
|
+
this.handleVignetteSpan(grandChildNode);
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
processDivChildren(divNode) {
|
|
2108
|
+
for (const grandChildNode of Array.from(divNode.childNodes)) {
|
|
2109
|
+
if (grandChildNode.nodeName !== 'SPAN') {
|
|
2110
|
+
return;
|
|
2111
|
+
}
|
|
2112
|
+
for (const sNode of Array.from(grandChildNode.childNodes)) {
|
|
2113
|
+
this.handleVignetteSpan(sNode);
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
handleVignetteSpan(pNode) {
|
|
2118
|
+
let paragraph;
|
|
2119
|
+
switch (pNode.nodeName) {
|
|
2120
|
+
case 'P':
|
|
2121
|
+
paragraph = new NewLicitParagraphElement(pNode, null);
|
|
2122
|
+
//paraElement
|
|
2123
|
+
if (paragraph) {
|
|
2124
|
+
this.content.push(paragraph.render());
|
|
2125
|
+
}
|
|
2126
|
+
break;
|
|
2127
|
+
case 'IMG': {
|
|
2128
|
+
const imgNode = pNode;
|
|
2129
|
+
const source = imgNode?.src;
|
|
2130
|
+
const altText = imgNode?.alt;
|
|
2131
|
+
const width = imgNode?.getAttribute('width');
|
|
2132
|
+
const height = imgNode?.getAttribute('height');
|
|
2133
|
+
if (source) {
|
|
2134
|
+
const imgElement = new LicitParagraphImageElement(source, altText, width, height);
|
|
2135
|
+
this.content.push(imgElement.render());
|
|
2136
|
+
if (altText === '/ERR:Unsupported Image Format x-emf') {
|
|
2137
|
+
const errText = new LicitErrorTextElement(altText);
|
|
2138
|
+
this.content.push(errText.render());
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
break;
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
render() {
|
|
2146
|
+
const element = this.getBaseElement();
|
|
2147
|
+
element.content = this.content;
|
|
2148
|
+
element.attrs.colspan = this.colspan;
|
|
2149
|
+
element.attrs.rowspan = this.rowspan;
|
|
2150
|
+
element.attrs.borderColor = this.borderColor;
|
|
2151
|
+
element.attrs.background = this.bgColor;
|
|
2152
|
+
element.attrs.colwidth = this.width;
|
|
2153
|
+
return element;
|
|
2154
|
+
}
|
|
2155
|
+
}
|
|
2156
|
+
export class LicitTableCellParaElement extends LicitElement {
|
|
2157
|
+
getBaseElement() {
|
|
2158
|
+
const defaultColWidth = 120;
|
|
2159
|
+
const defaultBgColor = '#FFFFFF';
|
|
2160
|
+
return {
|
|
2161
|
+
type: this.isTableHeader ? 'table_header' : 'table_cell',
|
|
2162
|
+
attrs: {
|
|
2163
|
+
colspan: 1,
|
|
2164
|
+
rowspan: 1,
|
|
2165
|
+
colwidth: this.colWidth || defaultColWidth,
|
|
2166
|
+
background: this.bgColor || defaultBgColor,
|
|
2167
|
+
vAlign: this.vAlign || 'middle',
|
|
2168
|
+
},
|
|
2169
|
+
content: [],
|
|
2170
|
+
};
|
|
2171
|
+
}
|
|
2172
|
+
node;
|
|
2173
|
+
rowspan = 1;
|
|
2174
|
+
colspan = 1;
|
|
2175
|
+
bgColor;
|
|
2176
|
+
colWidth;
|
|
2177
|
+
content = [];
|
|
2178
|
+
vAlign;
|
|
2179
|
+
isTableHeader;
|
|
2180
|
+
isTransparentTable;
|
|
2181
|
+
constructor(node, bgColor, colwidth, vericalAlignment, isTableHeader, isTransparentTable) {
|
|
2182
|
+
super();
|
|
2183
|
+
this.bgColor = bgColor;
|
|
2184
|
+
this.colWidth = colwidth;
|
|
2185
|
+
this.vAlign = vericalAlignment;
|
|
2186
|
+
this.isTableHeader = isTableHeader;
|
|
2187
|
+
this.isTransparentTable = isTransparentTable;
|
|
2188
|
+
this.ConvertElements(node);
|
|
2189
|
+
}
|
|
2190
|
+
ConvertElements(node) {
|
|
2191
|
+
let i = 0;
|
|
2192
|
+
while (i < node.childNodes.length) {
|
|
2193
|
+
const childNode = node.childNodes[i];
|
|
2194
|
+
const nextChild = node.childNodes[i + 1];
|
|
2195
|
+
if (childNode.nodeType === Node.ELEMENT_NODE &&
|
|
2196
|
+
nextChild?.nodeType === Node.ELEMENT_NODE) {
|
|
2197
|
+
if (shouldSkipNext(childNode.className) &&
|
|
2198
|
+
!shouldSkipNext(nextChild.className)) {
|
|
2199
|
+
function updateTextContent(el) {
|
|
2200
|
+
for (const childNode of Array.from(el.childNodes)) {
|
|
2201
|
+
if (childNode.nodeType === Node.TEXT_NODE) {
|
|
2202
|
+
childNode.textContent += '. ';
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
updateTextContent(childNode);
|
|
2207
|
+
childNode.appendChild(nextChild);
|
|
2208
|
+
}
|
|
2209
|
+
}
|
|
2210
|
+
this.processChildNode(childNode);
|
|
2211
|
+
i++;
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
processChildNode(childNode) {
|
|
2215
|
+
if (childNode.nodeName === 'P') {
|
|
2216
|
+
const paragraph = new NewLicitParagraphElement(childNode, null);
|
|
2217
|
+
if (paragraph) {
|
|
2218
|
+
this.content.push(paragraph.render());
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
else if (childNode.nodeName === 'IMG') {
|
|
2222
|
+
const imgElement = childNode;
|
|
2223
|
+
const source = imgElement?.getAttribute('srcRelative') ?? imgElement?.src;
|
|
2224
|
+
if (!source)
|
|
2225
|
+
return;
|
|
2226
|
+
const alt = imgElement?.alt;
|
|
2227
|
+
const width = imgElement?.getAttribute('width');
|
|
2228
|
+
const height = imgElement?.getAttribute('height');
|
|
2229
|
+
const img = new LicitParagraphImageElement(source, alt, width, height);
|
|
2230
|
+
this.content.push(img.render());
|
|
2231
|
+
}
|
|
2232
|
+
else if (childNode.nodeName === 'OL') {
|
|
2233
|
+
this.processChildOL(childNode);
|
|
2234
|
+
}
|
|
2235
|
+
else if (childNode.nodeName === 'UL') {
|
|
2236
|
+
this.processChildUL(childNode);
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
processChildOL(childNode) {
|
|
2240
|
+
const orderedList = new LicitOrderedListElement(0);
|
|
2241
|
+
const olText = childNode.textContent;
|
|
2242
|
+
if (olText && childNode.childNodes && childNode.childNodes.length > 0) {
|
|
2243
|
+
const childNodes = Array.from(childNode.childNodes).filter((node) => node.tagName?.toLowerCase() === 'li');
|
|
2244
|
+
for (const n of childNodes) {
|
|
2245
|
+
n.textContent = this.removeNewLines(n.textContent);
|
|
2246
|
+
const bulletItem = new LicitBulletListItemElement(n);
|
|
2247
|
+
orderedList.addItem(bulletItem);
|
|
2248
|
+
}
|
|
2249
|
+
this.content.push(orderedList.render());
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2252
|
+
processChildUL(childNode) {
|
|
2253
|
+
const bulletList = new LicitBulletListElement(0);
|
|
2254
|
+
const ulText = childNode.textContent;
|
|
2255
|
+
if (ulText && childNode.childNodes && childNode.childNodes.length > 0) {
|
|
2256
|
+
const childNodes = Array.from(childNode.childNodes).filter((node) => node.tagName?.toLowerCase() === 'p');
|
|
2257
|
+
for (const n of childNodes) {
|
|
2258
|
+
this.processTextNodes(n);
|
|
2259
|
+
const bulletItem = new LicitBulletListItemElement(n);
|
|
2260
|
+
bulletList.addItem(bulletItem);
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
this.content.push(bulletList.render());
|
|
2264
|
+
}
|
|
2265
|
+
processTextNodes(node) {
|
|
2266
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
2267
|
+
node.textContent = this.cleanupText(node.textContent);
|
|
2268
|
+
return;
|
|
2269
|
+
}
|
|
2270
|
+
const children = Array.from(node.childNodes);
|
|
2271
|
+
for (const child of children) {
|
|
2272
|
+
this.processTextNodes(child);
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2275
|
+
cleanupText(text) {
|
|
2276
|
+
return this.removeBullets(this.removeNewLines(text));
|
|
2277
|
+
}
|
|
2278
|
+
removeNewLines(text) {
|
|
2279
|
+
return text.split('\n').join('');
|
|
2280
|
+
}
|
|
2281
|
+
removeBullets(text) {
|
|
2282
|
+
return text.split('•').join('');
|
|
2283
|
+
}
|
|
2284
|
+
render() {
|
|
2285
|
+
const element = this.getBaseElement();
|
|
2286
|
+
element.content = this.content;
|
|
2287
|
+
element.attrs.colspan = this.colspan;
|
|
2288
|
+
element.attrs.rowspan = this.rowspan;
|
|
2289
|
+
element.attrs.background = this.bgColor;
|
|
2290
|
+
//Adding border styles for transparent table
|
|
2291
|
+
if (this.isTransparentTable) {
|
|
2292
|
+
element.attrs.borderTop = '0.25px solid #ffffff';
|
|
2293
|
+
element.attrs.borderLeft = '0.25px solid #ffffff';
|
|
2294
|
+
element.attrs.borderRight = '0.25px solid #ffffff';
|
|
2295
|
+
element.attrs.borderBottom = '0.25px solid #000000';
|
|
2296
|
+
}
|
|
2297
|
+
element.attrs.colwidth = this.colWidth;
|
|
2298
|
+
return element;
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2301
|
+
export class LicitTableRowElement extends LicitElement {
|
|
2302
|
+
getBaseElement() {
|
|
2303
|
+
return {
|
|
2304
|
+
type: 'table_row',
|
|
2305
|
+
content: [],
|
|
2306
|
+
};
|
|
2307
|
+
}
|
|
2308
|
+
cells = [];
|
|
2309
|
+
addCell(cell) {
|
|
2310
|
+
this.cells.push(cell);
|
|
2311
|
+
}
|
|
2312
|
+
render() {
|
|
2313
|
+
const element = this.getBaseElement();
|
|
2314
|
+
for (const cell of this.cells) {
|
|
2315
|
+
element.content.push(cell.render());
|
|
2316
|
+
}
|
|
2317
|
+
return element;
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
export class LicitTableElement extends LicitElement {
|
|
2321
|
+
getBaseElement() {
|
|
2322
|
+
return {
|
|
2323
|
+
type: 'table',
|
|
2324
|
+
attrs: {
|
|
2325
|
+
marginLeft: null,
|
|
2326
|
+
vignette: this.isVignette,
|
|
2327
|
+
capco: this.capco,
|
|
2328
|
+
},
|
|
2329
|
+
content: [],
|
|
2330
|
+
};
|
|
2331
|
+
}
|
|
2332
|
+
rows = [];
|
|
2333
|
+
isVignette = false;
|
|
2334
|
+
capco;
|
|
2335
|
+
constructor(isVignette, capco) {
|
|
2336
|
+
super();
|
|
2337
|
+
this.isVignette = isVignette;
|
|
2338
|
+
this.capco = capco;
|
|
2339
|
+
}
|
|
2340
|
+
addRow(row) {
|
|
2341
|
+
this.rows.push(row);
|
|
2342
|
+
}
|
|
2343
|
+
render() {
|
|
2344
|
+
const element = this.getBaseElement();
|
|
2345
|
+
for (const row of this.rows) {
|
|
2346
|
+
element.content.push(row.render());
|
|
2347
|
+
}
|
|
2348
|
+
return element;
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
export class LicitEnhancedTableElement extends LicitElement {
|
|
2352
|
+
getBaseElement() {
|
|
2353
|
+
return {
|
|
2354
|
+
type: 'enhanced_table_figure',
|
|
2355
|
+
attrs: {
|
|
2356
|
+
id: '',
|
|
2357
|
+
figureType: 'table',
|
|
2358
|
+
orientation: this.orientation,
|
|
2359
|
+
maximized: false,
|
|
2360
|
+
isValidate: true,
|
|
2361
|
+
},
|
|
2362
|
+
content: [],
|
|
2363
|
+
};
|
|
2364
|
+
}
|
|
2365
|
+
body;
|
|
2366
|
+
capco;
|
|
2367
|
+
notes;
|
|
2368
|
+
orientation;
|
|
2369
|
+
constructor(orientation = 'portrait') {
|
|
2370
|
+
super();
|
|
2371
|
+
this.orientation = orientation;
|
|
2372
|
+
}
|
|
2373
|
+
render() {
|
|
2374
|
+
const element = this.getBaseElement();
|
|
2375
|
+
if (this.body) {
|
|
2376
|
+
element.content.push(this.body.render());
|
|
2377
|
+
}
|
|
2378
|
+
if (this.notes) {
|
|
2379
|
+
element.content.push(this.notes.render());
|
|
2380
|
+
}
|
|
2381
|
+
if (this.capco) {
|
|
2382
|
+
element.content.push(this.capco.render());
|
|
2383
|
+
}
|
|
2384
|
+
return element;
|
|
2385
|
+
}
|
|
2386
|
+
addBody(bodyObj) {
|
|
2387
|
+
this.body = bodyObj;
|
|
2388
|
+
}
|
|
2389
|
+
addCapco(capcoObj) {
|
|
2390
|
+
this.capco = capcoObj;
|
|
2391
|
+
}
|
|
2392
|
+
addNotes(notesObj) {
|
|
2393
|
+
this.notes = notesObj;
|
|
2394
|
+
}
|
|
2395
|
+
removeLastRow() {
|
|
2396
|
+
if (this.body?.table?.rows?.length > 0) {
|
|
2397
|
+
this.body.table.rows.pop();
|
|
2398
|
+
}
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
export class LicitEnhancedTableFigureBodyElement extends LicitElement {
|
|
2402
|
+
table;
|
|
2403
|
+
getBaseElement() {
|
|
2404
|
+
return {
|
|
2405
|
+
content: [],
|
|
2406
|
+
type: 'enhanced_table_figure_body',
|
|
2407
|
+
};
|
|
2408
|
+
}
|
|
2409
|
+
render() {
|
|
2410
|
+
const element = this.getBaseElement();
|
|
2411
|
+
element.content.push(this.table.render());
|
|
2412
|
+
return element;
|
|
2413
|
+
}
|
|
2414
|
+
addTable(table) {
|
|
2415
|
+
this.table = table;
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
export class LicitEnhancedTableFigureCapcoElement extends LicitElement {
|
|
2419
|
+
text;
|
|
2420
|
+
capco;
|
|
2421
|
+
getBaseElement() {
|
|
2422
|
+
return {
|
|
2423
|
+
type: 'enhanced_table_figure_capco',
|
|
2424
|
+
attrs: {
|
|
2425
|
+
form: 'long',
|
|
2426
|
+
capco: this.capco,
|
|
2427
|
+
style: '',
|
|
2428
|
+
isValidate: true,
|
|
2429
|
+
},
|
|
2430
|
+
content: [],
|
|
2431
|
+
};
|
|
2432
|
+
}
|
|
2433
|
+
constructor(capco) {
|
|
2434
|
+
super();
|
|
2435
|
+
this.text = ' ';
|
|
2436
|
+
this.capco = capco;
|
|
2437
|
+
}
|
|
2438
|
+
render() {
|
|
2439
|
+
const element = this.getBaseElement();
|
|
2440
|
+
element.attrs.capco = this.capco;
|
|
2441
|
+
element.content.push({
|
|
2442
|
+
type: 'text',
|
|
2443
|
+
text: this.text,
|
|
2444
|
+
});
|
|
2445
|
+
return element;
|
|
2446
|
+
}
|
|
2447
|
+
}
|
|
2448
|
+
export class LicitEnhancedTableNotesElement extends LicitElement {
|
|
2449
|
+
paragraphs;
|
|
2450
|
+
constructor(paragraphNodes) {
|
|
2451
|
+
super();
|
|
2452
|
+
this.paragraphs = paragraphNodes.map((p) => new NewLicitParagraphElement(p));
|
|
2453
|
+
}
|
|
2454
|
+
getBaseElement() {
|
|
2455
|
+
return {
|
|
2456
|
+
type: 'enhanced_table_figure_notes',
|
|
2457
|
+
attrs: {
|
|
2458
|
+
styleName: 'Normal',
|
|
2459
|
+
},
|
|
2460
|
+
content: [],
|
|
2461
|
+
};
|
|
2462
|
+
}
|
|
2463
|
+
render() {
|
|
2464
|
+
const element = this.getBaseElement();
|
|
2465
|
+
for (const p of this.paragraphs) {
|
|
2466
|
+
element.content.push(p.render());
|
|
2467
|
+
}
|
|
2468
|
+
return element;
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2471
|
+
export class LicitHRElement extends LicitElement {
|
|
2472
|
+
getBaseElement() {
|
|
2473
|
+
return {
|
|
2474
|
+
type: 'horizontal_rule',
|
|
2475
|
+
attrs: {
|
|
2476
|
+
pageBreak: null,
|
|
2477
|
+
},
|
|
2478
|
+
};
|
|
2479
|
+
}
|
|
2480
|
+
render() {
|
|
2481
|
+
const element = this.getBaseElement();
|
|
2482
|
+
return element;
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2485
|
+
export class LicitOrderedListElement extends LicitElement {
|
|
2486
|
+
getBaseElement() {
|
|
2487
|
+
return {
|
|
2488
|
+
type: 'ordered_list',
|
|
2489
|
+
attrs: {
|
|
2490
|
+
id: null,
|
|
2491
|
+
indent: this.indent,
|
|
2492
|
+
listStyleType: null,
|
|
2493
|
+
},
|
|
2494
|
+
content: [],
|
|
2495
|
+
};
|
|
2496
|
+
}
|
|
2497
|
+
listItems = [];
|
|
2498
|
+
indent = 0;
|
|
2499
|
+
constructor(indent) {
|
|
2500
|
+
super();
|
|
2501
|
+
this.indent = indent;
|
|
2502
|
+
}
|
|
2503
|
+
addItem(item) {
|
|
2504
|
+
this.listItems.push(item);
|
|
2505
|
+
}
|
|
2506
|
+
render() {
|
|
2507
|
+
const baseElement = this.getBaseElement();
|
|
2508
|
+
const renderedElement = { ...baseElement };
|
|
2509
|
+
for (const item of this.listItems) {
|
|
2510
|
+
const renderedItem = item.render();
|
|
2511
|
+
renderedElement.content.push(renderedItem);
|
|
2512
|
+
}
|
|
2513
|
+
return renderedElement;
|
|
2514
|
+
}
|
|
2515
|
+
}
|
|
2516
|
+
export function shouldSkipNext(className) {
|
|
2517
|
+
const classesToSkip = [
|
|
2518
|
+
'chpara0',
|
|
2519
|
+
'chsubpara1',
|
|
2520
|
+
'attpara0',
|
|
2521
|
+
'attsubpara1',
|
|
2522
|
+
'FM_chpara0',
|
|
2523
|
+
'FM_attpara0',
|
|
2524
|
+
'FM_chsubpara1',
|
|
2525
|
+
'FM_attsubpara1',
|
|
2526
|
+
];
|
|
2527
|
+
return classesToSkip.includes(className);
|
|
2528
|
+
}
|
|
2529
|
+
function checkFirstSentenceBold(parentNode) {
|
|
2530
|
+
return shouldSkipNext(parentNode?.className);
|
|
2531
|
+
}
|
|
2532
|
+
/**
|
|
2533
|
+
* Adds ". " to the end of the text if it doesn't already end with it.
|
|
2534
|
+
* @param {string} text - The input text to check.
|
|
2535
|
+
* @returns {string} The text ending with ". "
|
|
2536
|
+
*/
|
|
2537
|
+
function getInlineStylesArray(nodeStyles) {
|
|
2538
|
+
const inlineStyles = [];
|
|
2539
|
+
const stylesToInclude = new Set([
|
|
2540
|
+
'italic',
|
|
2541
|
+
'bold',
|
|
2542
|
+
'underline',
|
|
2543
|
+
'uppercase',
|
|
2544
|
+
'lowercase',
|
|
2545
|
+
]);
|
|
2546
|
+
for (const styleArray of nodeStyles) {
|
|
2547
|
+
if (styleArray?.includes(':')) {
|
|
2548
|
+
const [styleType, styleValue] = styleArray
|
|
2549
|
+
.split(':')
|
|
2550
|
+
.map((s) => s.toLowerCase().trim());
|
|
2551
|
+
if (stylesToInclude.has(styleValue)) {
|
|
2552
|
+
inlineStyles.push(styleValue);
|
|
2553
|
+
}
|
|
2554
|
+
else if (styleType === 'line-height') {
|
|
2555
|
+
inlineStyles.push(`line-height-${styleValue}`);
|
|
2556
|
+
}
|
|
2557
|
+
else if (styleType === 'text-align') {
|
|
2558
|
+
inlineStyles.push(`text-align-${styleValue}`);
|
|
2559
|
+
}
|
|
2560
|
+
else if (styleType === 'color') {
|
|
2561
|
+
inlineStyles.push(`color-${styleValue}`);
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
return inlineStyles;
|
|
2566
|
+
}
|
|
2567
|
+
export function getElementAlignment(imgEl) {
|
|
2568
|
+
const alignAttr = imgEl?.getAttribute('align');
|
|
2569
|
+
if (alignAttr) {
|
|
2570
|
+
return alignAttr;
|
|
2571
|
+
}
|
|
2572
|
+
// If no align attribute, check inline styles
|
|
2573
|
+
// Split by semicolon to get individual style declarations
|
|
2574
|
+
const styles = imgEl?.getAttribute('style')?.split(';') ?? [];
|
|
2575
|
+
for (const style of styles) {
|
|
2576
|
+
const parts = style.split(':');
|
|
2577
|
+
if (parts.length !== 2) {
|
|
2578
|
+
continue;
|
|
2579
|
+
}
|
|
2580
|
+
const property = parts[0].trim().toLowerCase();
|
|
2581
|
+
// Check for align or text-align properties
|
|
2582
|
+
if (property === 'align') {
|
|
2583
|
+
const value = parts[1].trim();
|
|
2584
|
+
return value;
|
|
2585
|
+
}
|
|
2586
|
+
}
|
|
2587
|
+
return null;
|
|
2588
|
+
}
|