document-ir 0.0.15 → 0.2.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.
Files changed (54) hide show
  1. package/{esm → dist}/ArrayCollapseTransformer.d.ts +2 -2
  2. package/{script → dist}/DocumentThinningTransformer.d.ts +2 -2
  3. package/dist/ExampleDocument.d.ts +2 -0
  4. package/{esm → dist}/IdentityTransformer.d.ts +5 -3
  5. package/{esm → dist}/NodeVisitor.d.ts +3 -1
  6. package/{esm → dist}/TextCollapseTransformer.d.ts +2 -2
  7. package/{script → dist}/TextVisitor.d.ts +2 -2
  8. package/{script → dist}/WhitespaceStretchingTransformer.d.ts +2 -2
  9. package/{script → dist}/WhitespaceTransformer.d.ts +2 -2
  10. package/{script → dist}/WordCountTransformer.d.ts +2 -2
  11. package/{script → dist}/WordCounterVisitor.d.ts +2 -2
  12. package/dist/index.d.ts +11 -0
  13. package/dist/index.js +1493 -0
  14. package/{script → dist}/types.d.ts +74 -58
  15. package/package.json +40 -11
  16. package/esm/ArrayCollapseTransformer.js +0 -18
  17. package/esm/DocumentThinningTransformer.d.ts +0 -16
  18. package/esm/DocumentThinningTransformer.js +0 -246
  19. package/esm/IdentityTransformer.js +0 -866
  20. package/esm/NodeVisitor.js +0 -414
  21. package/esm/TextCollapseTransformer.js +0 -36
  22. package/esm/TextVisitor.d.ts +0 -15
  23. package/esm/TextVisitor.js +0 -55
  24. package/esm/WhitespaceStretchingTransformer.d.ts +0 -26
  25. package/esm/WhitespaceStretchingTransformer.js +0 -121
  26. package/esm/WhitespaceTransformer.d.ts +0 -12
  27. package/esm/WhitespaceTransformer.js +0 -75
  28. package/esm/WordCountTransformer.d.ts +0 -6
  29. package/esm/WordCountTransformer.js +0 -83
  30. package/esm/WordCounterVisitor.d.ts +0 -13
  31. package/esm/WordCounterVisitor.js +0 -43
  32. package/esm/index.d.ts +0 -11
  33. package/esm/index.js +0 -11
  34. package/esm/package.json +0 -3
  35. package/esm/types.d.ts +0 -351
  36. package/esm/types.js +0 -1
  37. package/script/ArrayCollapseTransformer.d.ts +0 -5
  38. package/script/ArrayCollapseTransformer.js +0 -22
  39. package/script/DocumentThinningTransformer.js +0 -250
  40. package/script/IdentityTransformer.d.ts +0 -59
  41. package/script/IdentityTransformer.js +0 -870
  42. package/script/NodeVisitor.d.ts +0 -59
  43. package/script/NodeVisitor.js +0 -418
  44. package/script/TextCollapseTransformer.d.ts +0 -5
  45. package/script/TextCollapseTransformer.js +0 -40
  46. package/script/TextVisitor.js +0 -59
  47. package/script/WhitespaceStretchingTransformer.js +0 -125
  48. package/script/WhitespaceTransformer.js +0 -79
  49. package/script/WordCountTransformer.js +0 -87
  50. package/script/WordCounterVisitor.js +0 -47
  51. package/script/index.d.ts +0 -11
  52. package/script/index.js +0 -38
  53. package/script/package.json +0 -3
  54. package/script/types.js +0 -2
package/dist/index.js ADDED
@@ -0,0 +1,1493 @@
1
+ var b = Object.defineProperty;
2
+ var y = (c, t, e) => t in c ? b(c, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : c[t] = e;
3
+ var l = (c, t, e) => y(c, typeof t != "symbol" ? t + "" : t, e);
4
+ class u {
5
+ async beforeBlock() {
6
+ }
7
+ async afterBlock() {
8
+ }
9
+ async beforeInline() {
10
+ }
11
+ async afterInline() {
12
+ }
13
+ async chooseChildren(t) {
14
+ const e = [];
15
+ for (const i of t) {
16
+ const r = await this.choose(i);
17
+ r && e.push(r);
18
+ }
19
+ return e;
20
+ }
21
+ async block(t) {
22
+ await this.beforeBlock();
23
+ const e = await this.chooseChildren(t.content);
24
+ await this.afterBlock();
25
+ const i = {
26
+ type: "block",
27
+ content: e
28
+ };
29
+ return t.id != null && (i.id = t.id), i;
30
+ }
31
+ async blockQuote(t) {
32
+ await this.beforeBlock();
33
+ const e = await this.chooseChildren(t.content);
34
+ await this.afterBlock();
35
+ const i = {
36
+ type: "block-quote",
37
+ content: e
38
+ };
39
+ return t.id != null && (i.id = t.id), i;
40
+ }
41
+ async bold(t) {
42
+ await this.beforeInline();
43
+ const e = await this.chooseChildren(t.content);
44
+ await this.afterInline();
45
+ const i = {
46
+ type: "bold",
47
+ content: e
48
+ };
49
+ return t.id != null && (i.id = t.id), i;
50
+ }
51
+ async break_(t) {
52
+ await this.beforeBlock(), await this.afterBlock();
53
+ const e = {
54
+ type: "break"
55
+ };
56
+ return t.id != null && (e.id = t.id), e;
57
+ }
58
+ async bubble(t) {
59
+ await this.beforeBlock();
60
+ const e = await this.chooseChildren(t.content);
61
+ await this.afterBlock();
62
+ const i = {
63
+ type: "bubble",
64
+ orientation: t.orientation || "left",
65
+ content: e
66
+ };
67
+ return t.id != null && (i.id = t.id), i;
68
+ }
69
+ async center(t) {
70
+ await this.beforeBlock();
71
+ const e = await this.chooseChildren(t.content);
72
+ await this.afterBlock();
73
+ const i = {
74
+ type: "center",
75
+ content: e
76
+ };
77
+ return t.id != null && (i.id = t.id), i;
78
+ }
79
+ async code(t) {
80
+ await this.beforeInline();
81
+ const e = await this.chooseChildren(t.content);
82
+ await this.afterInline();
83
+ const i = {
84
+ type: "code",
85
+ content: e
86
+ };
87
+ return t.id != null && (i.id = t.id), i;
88
+ }
89
+ async columns(t) {
90
+ const e = [];
91
+ for (const r of t.columns)
92
+ await this.beforeBlock(), e.push(await this.chooseChildren(r)), await this.afterBlock();
93
+ const i = {
94
+ type: "columns",
95
+ columns: e,
96
+ "column-count": t["column-count"]
97
+ };
98
+ return t.id != null && (i.id = t.id), i;
99
+ }
100
+ async definition(t) {
101
+ await this.beforeBlock();
102
+ const e = await this.chooseChildren(t.abbreviation);
103
+ await this.afterBlock(), await this.beforeBlock();
104
+ const i = await this.chooseChildren(t.title);
105
+ await this.afterBlock(), await this.beforeBlock();
106
+ const r = await this.chooseChildren(t.content);
107
+ await this.afterBlock();
108
+ const s = {
109
+ type: "definition",
110
+ abbreviation: e,
111
+ title: i,
112
+ content: r,
113
+ key: t.key
114
+ };
115
+ return t.id != null && (s.id = t.id), s;
116
+ }
117
+ async definitionList(t) {
118
+ await this.beforeBlock();
119
+ const e = [];
120
+ for (const r of t.content) {
121
+ const s = await this.definition(r);
122
+ s && e.push(s);
123
+ }
124
+ await this.afterBlock();
125
+ const i = {
126
+ type: "definition-list",
127
+ content: e
128
+ };
129
+ return t.id != null && (i.id = t.id), i;
130
+ }
131
+ async definitionReference(t) {
132
+ await this.beforeInline();
133
+ const e = await this.chooseChildren(
134
+ t.definition.abbreviation
135
+ );
136
+ await this.afterInline();
137
+ const i = {
138
+ type: "definition-reference",
139
+ definition: {
140
+ abbreviation: e,
141
+ key: t.definition.key
142
+ },
143
+ content: await this.chooseChildren(t.content)
144
+ };
145
+ return t.id != null && (i.id = t.id), i;
146
+ }
147
+ async embed(t) {
148
+ const e = {
149
+ type: "embed",
150
+ content: {
151
+ ...t.content
152
+ }
153
+ };
154
+ return t.id != null && (e.id = t.id), e;
155
+ }
156
+ async emoji(t) {
157
+ const e = {
158
+ type: "emoji",
159
+ url: t.url,
160
+ alt: t.alt
161
+ };
162
+ return t.id != null && (e.id = t.id), e;
163
+ }
164
+ async figure(t) {
165
+ await this.beforeBlock();
166
+ const e = await this.chooseChildren(t.content);
167
+ await this.afterBlock();
168
+ const i = {
169
+ type: "figure",
170
+ content: e
171
+ };
172
+ return t.id != null && (i.id = t.id), i;
173
+ }
174
+ async figureCaption(t) {
175
+ await this.beforeBlock();
176
+ const e = await this.chooseChildren(t.content);
177
+ await this.afterBlock();
178
+ const i = {
179
+ type: "figure-caption",
180
+ content: e
181
+ };
182
+ return t.id != null && (i.id = t.id), i;
183
+ }
184
+ async figureImage(t) {
185
+ await this.beforeBlock();
186
+ const e = await this.chooseChildren(t.content);
187
+ await this.afterBlock();
188
+ const i = {
189
+ type: "figure-image",
190
+ alt: t.alt || "",
191
+ url: t.url,
192
+ content: e
193
+ };
194
+ return t.id != null && (i.id = t.id), t.blurhash && (i.blurhash = t.blurhash), t.height && (i.height = t.height), t.width && (i.width = t.width), t.hero && (i.hero = t.hero), t.image && (i.image = t.image), i;
195
+ }
196
+ async formattedText(t) {
197
+ await this.beforeBlock(), await this.afterBlock();
198
+ const e = {
199
+ type: "formatted-text",
200
+ text: t.text || "",
201
+ language: t.language
202
+ };
203
+ return t.id != null && (e.id = t.id), e;
204
+ }
205
+ async header(t) {
206
+ await this.beforeBlock();
207
+ const e = await this.chooseChildren(t.content);
208
+ await this.afterBlock();
209
+ const i = {
210
+ type: "header",
211
+ content: e,
212
+ level: t.level || 2
213
+ };
214
+ return t.id != null && (i.id = t.id), t.htmlId && (i.htmlId = t.htmlId), i;
215
+ }
216
+ async highTechAlert(t) {
217
+ await this.beforeBlock();
218
+ const e = await this.chooseChildren(t.content);
219
+ await this.afterBlock(), await this.beforeBlock();
220
+ const i = await this.chooseChildren(t.warning);
221
+ await this.afterBlock();
222
+ const r = {
223
+ type: "high-tech-alert",
224
+ content: e,
225
+ warning: i
226
+ };
227
+ return t.id != null && (r.id = t.id), r;
228
+ }
229
+ async horizontalRule(t) {
230
+ await this.beforeBlock(), await this.afterBlock();
231
+ const e = {
232
+ type: "horizontal-rule"
233
+ };
234
+ return t.id != null && (e.id = t.id), e;
235
+ }
236
+ async image(t) {
237
+ await this.beforeBlock(), await this.afterBlock();
238
+ const e = {
239
+ type: "image",
240
+ alt: t.alt || "",
241
+ url: t.url
242
+ };
243
+ return t.id != null && (e.id = t.id), t.hero && (e.hero = t.hero), t.blurhash && (e.blurhash = t.blurhash), t.height && (e.height = t.height), t.width && (e.width = t.width), t.image && (e.image = t.image), e;
244
+ }
245
+ async italic(t) {
246
+ await this.beforeInline();
247
+ const e = await this.chooseChildren(t.content);
248
+ await this.afterInline();
249
+ const i = {
250
+ type: "italic",
251
+ content: e
252
+ };
253
+ return t.id != null && (i.id = t.id), i;
254
+ }
255
+ async link(t) {
256
+ await this.beforeInline();
257
+ const e = await this.chooseChildren(t.content);
258
+ await this.afterInline();
259
+ const i = {
260
+ type: "link",
261
+ content: e,
262
+ url: t.url
263
+ };
264
+ return t.id != null && (i.id = t.id), t.title && (i.title = t.title), t.target && (i.target = t.target), t.userGeneratedContent && (i.userGeneratedContent = t.userGeneratedContent), t.noReferrer && (i.noReferrer = t.noReferrer), t.noFollow && (i.noFollow = t.noFollow), t.noOpener && (i.noOpener = t.noOpener), i;
265
+ }
266
+ async array(t) {
267
+ const e = {
268
+ type: "array",
269
+ content: await this.chooseChildren(t.content)
270
+ };
271
+ return t.id != null && (e.id = t.id), e;
272
+ }
273
+ async note(t) {
274
+ await this.beforeBlock();
275
+ const e = await this.chooseChildren(t.content);
276
+ await this.afterBlock();
277
+ const i = {
278
+ type: "note",
279
+ content: e
280
+ };
281
+ return t.id != null && (i.id = t.id), i;
282
+ }
283
+ async list(t) {
284
+ const e = [];
285
+ for (const r of t.content) {
286
+ await this.beforeBlock();
287
+ const s = await this.chooseChildren(r.content);
288
+ if (await this.afterBlock(), s && s.length > 0) {
289
+ const a = {
290
+ type: "list-item",
291
+ content: s
292
+ };
293
+ r.id != null && (a.id = r.id), e.push(a);
294
+ }
295
+ }
296
+ const i = {
297
+ type: "list",
298
+ style: t.style || "unordered",
299
+ content: e
300
+ };
301
+ return t.id != null && (i.id = t.id), i;
302
+ }
303
+ async paragraph(t) {
304
+ await this.beforeBlock();
305
+ const e = await this.chooseChildren(t.content);
306
+ await this.afterBlock();
307
+ const i = {
308
+ type: "paragraph",
309
+ content: e
310
+ };
311
+ return t.id != null && (i.id = t.id), i;
312
+ }
313
+ async quote(t) {
314
+ await this.beforeBlock();
315
+ const e = await this.chooseChildren(t.content);
316
+ await this.afterBlock();
317
+ const i = {
318
+ type: "quote",
319
+ icon: t.icon,
320
+ name: t.name,
321
+ content: e,
322
+ url: t.url
323
+ };
324
+ return t.id != null && (i.id = t.id), t.orientation && (i.orientation = t.orientation), i;
325
+ }
326
+ async redacted(t) {
327
+ t.style == "block" ? await this.beforeBlock() : await this.beforeInline();
328
+ const e = await this.chooseChildren(t.content);
329
+ t.style == "block" ? await this.afterBlock() : await this.afterInline();
330
+ const i = {
331
+ type: "redacted",
332
+ style: t.style,
333
+ content: e
334
+ };
335
+ return t.id != null && (i.id = t.id), i;
336
+ }
337
+ async region(t) {
338
+ await this.beforeBlock();
339
+ const e = await this.chooseChildren(t.content);
340
+ await this.afterBlock();
341
+ const i = {
342
+ type: "region",
343
+ mode: t.mode,
344
+ regions: t.regions,
345
+ content: e
346
+ };
347
+ return t.id != null && (i.id = t.id), i;
348
+ }
349
+ async script(t) {
350
+ const e = {
351
+ type: "script",
352
+ "mime-type": t["mime-type"] || "text/javascript",
353
+ source: t.source
354
+ };
355
+ return t.id != null && (e.id = t.id), e;
356
+ }
357
+ async secret(t) {
358
+ await this.beforeInline();
359
+ const e = await this.chooseChildren(t.content);
360
+ await this.afterInline();
361
+ const i = {
362
+ type: "secret",
363
+ content: e
364
+ };
365
+ return t.id != null && (i.id = t.id), i;
366
+ }
367
+ async smaller(t) {
368
+ await this.beforeInline();
369
+ const e = await this.chooseChildren(t.content);
370
+ await this.afterInline();
371
+ const i = {
372
+ type: "smaller",
373
+ content: e
374
+ };
375
+ return t.id != null && (i.id = t.id), i;
376
+ }
377
+ async sticker(t) {
378
+ await this.beforeBlock();
379
+ const e = await this.chooseChildren(t.content);
380
+ await this.afterBlock();
381
+ const i = {
382
+ type: "sticker",
383
+ orientation: t.orientation,
384
+ character: t.character,
385
+ name: t.name,
386
+ content: e
387
+ };
388
+ return t.id != null && (i.id = t.id), t.size && (i.size = t.size), t.width && (i.width = t.width), t.height && (i.height = t.height), i;
389
+ }
390
+ async strikeThrough(t) {
391
+ await this.beforeInline();
392
+ const e = await this.chooseChildren(t.content);
393
+ await this.afterInline();
394
+ const i = {
395
+ type: "strike-through",
396
+ content: e
397
+ };
398
+ return t.id != null && (i.id = t.id), i;
399
+ }
400
+ async standard(t) {
401
+ await this.beforeInline();
402
+ const e = await this.chooseChildren(t.content);
403
+ await this.afterInline();
404
+ const i = {
405
+ type: "standard",
406
+ standard: t.standard,
407
+ identifier: t.identifier,
408
+ url: t.url,
409
+ content: e
410
+ };
411
+ return t.id != null && (i.id = t.id), i;
412
+ }
413
+ async text(t) {
414
+ const e = {
415
+ type: "text",
416
+ text: t.text
417
+ };
418
+ return t.id != null && (e.id = t.id), e;
419
+ }
420
+ async table(t) {
421
+ const e = [];
422
+ for (const r of t.content) {
423
+ const s = [];
424
+ let a = 0;
425
+ for (const n of r) {
426
+ await this.beforeBlock();
427
+ const o = await this.chooseChildren(n.content);
428
+ await this.afterBlock(), o && o.length == 0 && a++;
429
+ const h = {
430
+ type: "table-cell",
431
+ span: [n.span[0] || 1, n.span[1] || 1],
432
+ content: o
433
+ };
434
+ n.id != null && (h.id = n.id), n.header && (h.header = n.header), s.push(h);
435
+ }
436
+ s.length > 0 && a != s.length && e.push(s);
437
+ }
438
+ const i = {
439
+ type: "table",
440
+ content: e
441
+ };
442
+ return t.id != null && (i.id = t.id), i;
443
+ }
444
+ async social(t) {
445
+ return await this.beforeBlock(), await this.afterBlock(), {
446
+ type: t.type,
447
+ id: t.id
448
+ };
449
+ }
450
+ async underline(t) {
451
+ await this.beforeInline();
452
+ const e = await this.chooseChildren(t.content);
453
+ await this.afterInline();
454
+ const i = {
455
+ type: "underline",
456
+ content: e
457
+ };
458
+ return t.id != null && (i.id = t.id), i;
459
+ }
460
+ async video(t) {
461
+ await this.beforeBlock();
462
+ const e = t.content && await this.chooseChildren(t.content);
463
+ await this.afterBlock();
464
+ const i = {
465
+ type: "video",
466
+ alt: t.alt,
467
+ mp4: t.mp4,
468
+ poster: t.poster
469
+ };
470
+ return t.id != null && (i.id = t.id), t.autoplay && (i.autoplay = t.autoplay), t.blurhash && (i.blurhash = t.blurhash), e && (i.content = e), t.controls && (i.controls = t.controls), t.height && (i.height = t.height), t.width && (i.width = t.width), t.loop && (i.loop = t.loop), t.muted && (i.muted = t.muted), t.webm && (i.webm = t.webm), i;
471
+ }
472
+ async warning(t) {
473
+ await this.beforeBlock();
474
+ const e = await this.chooseChildren(t.content);
475
+ await this.afterBlock();
476
+ const i = {
477
+ type: "warning",
478
+ content: e
479
+ };
480
+ return t.id != null && (i.id = t.id), i;
481
+ }
482
+ async card(t) {
483
+ let e;
484
+ if (t.content) {
485
+ await this.beforeBlock();
486
+ const n = await this.chooseChildren(t.content.content);
487
+ n && n.length > 0 && (e = {
488
+ type: "card-content",
489
+ content: n
490
+ }, t.content.id != null && (e.id = t.content.id)), await this.afterBlock();
491
+ }
492
+ let i;
493
+ if (t.attribution && (i = {
494
+ type: "card-attribution"
495
+ }, t.attribution.id != null && (i.id = t.attribution.id), t.attribution.archiveUrl && (i.archiveUrl = t.attribution.archiveUrl), t.attribution.url && (i.url = t.attribution.url), t.attribution.date && (i.date = t.attribution.date), t.attribution.title)) {
496
+ await this.beforeBlock();
497
+ const n = await this.chooseChildren(t.attribution.title);
498
+ await this.afterBlock(), i.title = n;
499
+ }
500
+ let r;
501
+ if (t.header) {
502
+ await this.beforeBlock();
503
+ const n = await this.chooseChildren(t.header.title);
504
+ await this.afterBlock(), r = {
505
+ type: "card-header",
506
+ title: n,
507
+ backgroundBlurhash: t.header.backgroundBlurhash,
508
+ backgroundColor: t.header.backgroundColor,
509
+ backgroundImage: t.header.backgroundImage,
510
+ imageUrl: t.header.imageUrl,
511
+ imageBlurhash: t.header.imageBlurhash
512
+ }, t.header.id != null && (r.id = t.header.id), t.header.url && (r.url = t.header.url), t.header.username && (r.username = t.header.username), t.header.usernameDomain && (r.usernameDomain = t.header.usernameDomain);
513
+ }
514
+ let s;
515
+ if (t.media) {
516
+ const n = [];
517
+ for (const o of t.media.content) {
518
+ await this.beforeBlock();
519
+ const h = await this.choose(o);
520
+ h && (h.type == "image" || h.type == "video" || h.type == "embed") && n.push(h), await this.afterBlock();
521
+ }
522
+ n.length > 0 && (s = {
523
+ type: "card-media",
524
+ content: n
525
+ }, t.media.id != null && (s.id = t.media.id));
526
+ }
527
+ const a = {
528
+ type: "card",
529
+ content: e,
530
+ attribution: i,
531
+ header: r,
532
+ media: s,
533
+ original: t.original
534
+ };
535
+ return t.id != null && (a.id = t.id), a;
536
+ }
537
+ async date(t) {
538
+ await this.beforeInline();
539
+ const e = t.content && await this.chooseChildren(t.content);
540
+ await this.afterInline();
541
+ const i = {
542
+ type: "date",
543
+ isoDate: t.isoDate,
544
+ content: e
545
+ };
546
+ return t.id != null && (i.id = t.id), i;
547
+ }
548
+ async time(t) {
549
+ await this.beforeInline();
550
+ const e = t.content && await this.chooseChildren(t.content);
551
+ await this.afterInline();
552
+ const i = {
553
+ type: "time",
554
+ isoTime: t.isoTime,
555
+ content: e
556
+ };
557
+ return t.id != null && (i.id = t.id), i;
558
+ }
559
+ async datetime(t) {
560
+ await this.beforeInline();
561
+ const e = t.content && await this.chooseChildren(t.content);
562
+ await this.afterInline();
563
+ const i = {
564
+ type: "datetime",
565
+ iso8601: t.iso8601,
566
+ content: e
567
+ };
568
+ return t.id != null && (i.id = t.id), i;
569
+ }
570
+ async subText(t) {
571
+ await this.beforeInline();
572
+ const e = t.content && await this.chooseChildren(t.content);
573
+ await this.afterInline();
574
+ const i = {
575
+ type: "sub",
576
+ content: e
577
+ };
578
+ return t.id != null && (i.id = t.id), i;
579
+ }
580
+ async superText(t) {
581
+ await this.beforeInline();
582
+ const e = t.content && await this.chooseChildren(t.content);
583
+ await this.afterInline();
584
+ const i = {
585
+ type: "super",
586
+ content: e
587
+ };
588
+ return t.id != null && (i.id = t.id), i;
589
+ }
590
+ async toc(t) {
591
+ await this.beforeBlock();
592
+ const e = await this.chooseChildren(t.content), i = t.date && await this.choose(t.date);
593
+ await this.afterBlock(), await this.beforeBlock();
594
+ const r = await this.chooseChildren(t.children);
595
+ await this.afterBlock();
596
+ const s = r.filter(
597
+ (n) => n.type == "toc"
598
+ ), a = {
599
+ type: "toc",
600
+ content: e,
601
+ children: s
602
+ };
603
+ return t.id != null && (a.id = t.id), i && (i.type == "date" || i.type == "time" || i.type == "datetime") && (a.date = i), t.href && (a.href = t.href), t.hrefHtmlId && (a.hrefHtmlId = t.hrefHtmlId), a;
604
+ }
605
+ async timeRange(t) {
606
+ await this.beforeBlock();
607
+ const e = await this.chooseChildren(t.content);
608
+ await this.afterBlock();
609
+ const i = {
610
+ type: "time-range",
611
+ content: e
612
+ };
613
+ return t.id != null && (i.id = t.id), t.notBefore && (i.notBefore = t.notBefore), t.notAfter && (i.notAfter = t.notAfter), i;
614
+ }
615
+ async choose(t) {
616
+ if (!t || !t.type)
617
+ throw new Error(`Unexpected node, no type: ${JSON.stringify(t)}`);
618
+ try {
619
+ switch (t.type) {
620
+ case "block":
621
+ return await this.block(t);
622
+ case "block-quote":
623
+ return await this.blockQuote(t);
624
+ case "bold":
625
+ return await this.bold(t);
626
+ case "break":
627
+ return await this.break_(t);
628
+ case "bubble":
629
+ return await this.bubble(t);
630
+ case "card":
631
+ return await this.card(t);
632
+ case "center":
633
+ return await this.center(t);
634
+ case "code":
635
+ return await this.code(t);
636
+ case "columns":
637
+ return await this.columns(t);
638
+ case "definition":
639
+ return await this.definition(t);
640
+ case "definition-list":
641
+ return await this.definitionList(t);
642
+ case "definition-reference":
643
+ return await this.definitionReference(t);
644
+ case "embed":
645
+ return await this.embed(t);
646
+ case "emoji":
647
+ return await this.emoji(t);
648
+ case "figure":
649
+ return await this.figure(t);
650
+ case "figure-caption":
651
+ return await this.figureCaption(t);
652
+ case "figure-image":
653
+ return await this.figureImage(t);
654
+ case "formatted-text":
655
+ return await this.formattedText(t);
656
+ case "header":
657
+ return await this.header(t);
658
+ case "high-tech-alert":
659
+ return await this.highTechAlert(t);
660
+ case "horizontal-rule":
661
+ return await this.horizontalRule(t);
662
+ case "image":
663
+ return await this.image(t);
664
+ case "italic":
665
+ return await this.italic(t);
666
+ case "link":
667
+ return await this.link(t);
668
+ case "array":
669
+ return await this.array(t);
670
+ case "note":
671
+ return await this.note(t);
672
+ case "list":
673
+ return await this.list(t);
674
+ case "paragraph":
675
+ return await this.paragraph(t);
676
+ case "quote":
677
+ return await this.quote(t);
678
+ case "redacted":
679
+ return await this.redacted(t);
680
+ case "region":
681
+ return await this.region(t);
682
+ case "script":
683
+ return await this.script(t);
684
+ case "secret":
685
+ return await this.secret(t);
686
+ case "smaller":
687
+ return await this.smaller(t);
688
+ case "sticker":
689
+ return await this.sticker(t);
690
+ case "standard":
691
+ return await this.standard(t);
692
+ case "strike-through":
693
+ return await this.strikeThrough(t);
694
+ case "table":
695
+ return await this.table(t);
696
+ case "text":
697
+ return await this.text(t);
698
+ case "toot":
699
+ case "tweet":
700
+ case "vimeo":
701
+ case "youtube":
702
+ return await this.social(t);
703
+ case "underline":
704
+ return await this.underline(t);
705
+ case "video":
706
+ return await this.video(t);
707
+ case "warning":
708
+ return await this.warning(t);
709
+ case "date":
710
+ return await this.date(t);
711
+ case "time":
712
+ return await this.time(t);
713
+ case "datetime":
714
+ return await this.datetime(t);
715
+ case "super":
716
+ return await this.superText(t);
717
+ case "sub":
718
+ return await this.subText(t);
719
+ case "toc":
720
+ return await this.toc(t);
721
+ case "time-range":
722
+ return await this.timeRange(t);
723
+ }
724
+ } catch (e) {
725
+ throw console.log(
726
+ `Got exception while processing node: ${JSON.stringify(t)}`
727
+ ), e;
728
+ }
729
+ return console.error(`Unsupported type ${t.type}`), null;
730
+ }
731
+ async document(t) {
732
+ await this.beforeBlock();
733
+ const e = await this.chooseChildren(t.content);
734
+ await this.afterBlock(), await this.beforeBlock();
735
+ const i = t.definitions && (await this.chooseChildren(t.definitions)).filter(
736
+ (a) => a.type == "definition"
737
+ ), r = t.hierarchy;
738
+ await this.afterBlock();
739
+ const s = {
740
+ type: "document",
741
+ title: t.title,
742
+ content: e,
743
+ url: t.url
744
+ };
745
+ return t.image && (s.image = t.image), t.guid && (s.guid = t.guid), t["pub-date"] && (s["pub-date"] = t["pub-date"]), t.description && (s.description = t.description), t.date && (s.date = t.date), r && (s.hierarchy = r), i && (s.definitions = i), t.noindex && (s.noindex = t.noindex), t.author && (s.author = t.author), t.hidden && (s.hidden = t.hidden), t.readingDifficultyMultiplier && (s.readingDifficultyMultiplier = t.readingDifficultyMultiplier), t.contentDigest && (s.contentDigest = t.contentDigest), s;
746
+ }
747
+ async transform(t) {
748
+ return await this.document(t);
749
+ }
750
+ }
751
+ class k extends u {
752
+ async chooseChildren(t) {
753
+ const e = await super.chooseChildren(t), i = [];
754
+ for (const r of e)
755
+ if (r.type == "array")
756
+ for (const s of r.content)
757
+ i.push(s);
758
+ else
759
+ i.push(r);
760
+ return i;
761
+ }
762
+ }
763
+ class I extends u {
764
+ async chooseChildren(t) {
765
+ const e = await super.chooseChildren(t), i = [];
766
+ let r = null, s;
767
+ for (const a of e)
768
+ if (a.type == "text")
769
+ r != null ? r = `${r}${a.text}` : (r = a.text, s = a.id);
770
+ else {
771
+ if (r != null) {
772
+ const n = { type: "text", text: r };
773
+ s != null && (n.id = s), i.push(n), r = null, s = void 0;
774
+ }
775
+ i.push(a);
776
+ }
777
+ if (r != null) {
778
+ const a = { type: "text", text: r };
779
+ s != null && (a.id = s), i.push(a);
780
+ }
781
+ return i;
782
+ }
783
+ }
784
+ class m extends u {
785
+ async text(t) {
786
+ return t.text == "" ? null : t;
787
+ }
788
+ }
789
+ class T extends u {
790
+ constructor() {
791
+ super();
792
+ l(this, "stripWhitespace");
793
+ l(this, "lastText");
794
+ this.stripWhitespace = !0, this.lastText = null;
795
+ }
796
+ async text(e) {
797
+ let i = "";
798
+ for (const s of e.text)
799
+ s == " " || s == `
800
+ ` || s == " " || s == "\r" ? this.stripWhitespace || (i += " ", this.stripWhitespace = !0) : (i += s, this.stripWhitespace = !1);
801
+ if (i.length == 0)
802
+ return null;
803
+ const r = {
804
+ type: "text",
805
+ text: i
806
+ };
807
+ return e.id != null && (r.id = e.id), this.lastText = r, r;
808
+ }
809
+ stripLastText() {
810
+ this.lastText && (this.lastText.text.endsWith(" ") && (this.lastText.text = this.lastText.text.slice(0, -1)), this.lastText = null), this.stripWhitespace = !0;
811
+ }
812
+ async beforeBlock() {
813
+ this.stripLastText();
814
+ }
815
+ async afterBlock() {
816
+ this.stripLastText();
817
+ }
818
+ async transform(e) {
819
+ const i = await super.transform(e);
820
+ return await new m().transform(i);
821
+ }
822
+ }
823
+ class v extends u {
824
+ constructor() {
825
+ super();
826
+ l(this, "root");
827
+ l(this, "cursor");
828
+ this.root = {
829
+ type: "_block",
830
+ content: [],
831
+ parent: null
832
+ }, this.cursor = this.root;
833
+ }
834
+ async beforeBlock() {
835
+ const e = this.cursor, i = {
836
+ type: "_block",
837
+ content: [],
838
+ parent: e
839
+ };
840
+ e.content.push(i), this.cursor = i;
841
+ }
842
+ async afterBlock() {
843
+ this.cursor.parent && (this.cursor = this.cursor.parent);
844
+ }
845
+ async beforeInline() {
846
+ const e = this.cursor, i = {
847
+ type: "_inline",
848
+ content: [],
849
+ parent: e
850
+ };
851
+ e.content.push(i), this.cursor = i;
852
+ }
853
+ async afterInline() {
854
+ this.cursor.parent && (this.cursor = this.cursor.parent);
855
+ }
856
+ reviewBlock(e) {
857
+ const i = [], r = (s, a) => {
858
+ if (s.type == "text")
859
+ i.push({
860
+ node: s,
861
+ level: a
862
+ });
863
+ else if (s.type == "_block")
864
+ this.reviewBlock(s), i.push({ node: null, level: a });
865
+ else
866
+ for (const n of s.content)
867
+ r(n, a + 1);
868
+ };
869
+ for (const s of e.content)
870
+ r(s, 0);
871
+ for (let s = 0; s < i.length; s++) {
872
+ const a = i[s], n = s + 1 < i.length ? i[s + 1] : { node: null, level: 0 };
873
+ !a.node || !n.node || a.level != n.level && (a.level < n.level ? n.node.text.startsWith(" ") && (n.node.text = n.node.text.slice(1), a.node.text += " ") : a.level > n.level && a.node.text.endsWith(" ") && (a.node.text = a.node.text.slice(0, -1), n.node.text = ` ${n.node.text}`));
874
+ }
875
+ }
876
+ async text(e) {
877
+ const i = {
878
+ type: "text",
879
+ text: `${e.text}`
880
+ };
881
+ return e.id != null && (i.id = e.id), this.cursor.content.push(i), i;
882
+ }
883
+ async transform(e) {
884
+ const i = await super.transform(e);
885
+ return this.reviewBlock(this.root), i;
886
+ }
887
+ }
888
+ class w {
889
+ beforeBlock() {
890
+ }
891
+ afterBlock() {
892
+ }
893
+ beforeInline() {
894
+ }
895
+ afterInline() {
896
+ }
897
+ chooseChildren(t) {
898
+ for (const e of t)
899
+ this.choose(e);
900
+ }
901
+ block(t) {
902
+ this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock();
903
+ }
904
+ blockQuote(t) {
905
+ this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock();
906
+ }
907
+ bold(t) {
908
+ this.beforeInline(), this.chooseChildren(t.content), this.afterInline();
909
+ }
910
+ break_(t) {
911
+ this.beforeBlock(), this.afterBlock();
912
+ }
913
+ bubble(t) {
914
+ this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock();
915
+ }
916
+ center(t) {
917
+ this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock();
918
+ }
919
+ code(t) {
920
+ this.beforeInline(), this.chooseChildren(t.content), this.afterInline();
921
+ }
922
+ columns(t) {
923
+ for (const e of t.columns)
924
+ this.beforeBlock(), this.chooseChildren(e), this.afterBlock();
925
+ }
926
+ definition(t) {
927
+ this.beforeBlock(), this.chooseChildren(t.abbreviation), this.afterBlock(), this.beforeBlock(), this.chooseChildren(t.title), this.afterBlock(), this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock();
928
+ }
929
+ definitionList(t) {
930
+ this.beforeBlock();
931
+ for (const e of t.content)
932
+ this.definition(e);
933
+ this.afterBlock();
934
+ }
935
+ definitionReference(t) {
936
+ this.beforeInline(), this.chooseChildren(t.definition.abbreviation), this.afterInline(), this.chooseChildren(t.content);
937
+ }
938
+ embed(t) {
939
+ }
940
+ emoji(t) {
941
+ }
942
+ figure(t) {
943
+ this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock();
944
+ }
945
+ figureCaption(t) {
946
+ this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock();
947
+ }
948
+ figureImage(t) {
949
+ this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock();
950
+ }
951
+ formattedText(t) {
952
+ }
953
+ header(t) {
954
+ this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock();
955
+ }
956
+ highTechAlert(t) {
957
+ this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock(), this.beforeBlock(), this.chooseChildren(t.warning), this.afterBlock();
958
+ }
959
+ horizontalRule(t) {
960
+ }
961
+ image(t) {
962
+ }
963
+ italic(t) {
964
+ this.beforeInline(), this.chooseChildren(t.content), this.afterInline();
965
+ }
966
+ link(t) {
967
+ this.beforeInline(), this.chooseChildren(t.content), this.afterInline();
968
+ }
969
+ array(t) {
970
+ this.chooseChildren(t.content);
971
+ }
972
+ note(t) {
973
+ this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock();
974
+ }
975
+ list(t) {
976
+ for (const e of t.content)
977
+ this.beforeBlock(), this.chooseChildren(e.content), this.afterBlock();
978
+ }
979
+ paragraph(t) {
980
+ this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock();
981
+ }
982
+ quote(t) {
983
+ this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock();
984
+ }
985
+ redacted(t) {
986
+ t.style == "block" ? this.beforeBlock() : this.beforeInline(), this.chooseChildren(t.content), t.style == "block" ? this.afterBlock() : this.afterInline();
987
+ }
988
+ region(t) {
989
+ this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock();
990
+ }
991
+ script(t) {
992
+ }
993
+ secret(t) {
994
+ this.beforeInline(), this.chooseChildren(t.content), this.afterInline();
995
+ }
996
+ smaller(t) {
997
+ this.beforeInline(), this.chooseChildren(t.content), this.afterInline();
998
+ }
999
+ sticker(t) {
1000
+ this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock();
1001
+ }
1002
+ strikeThrough(t) {
1003
+ this.beforeInline(), this.chooseChildren(t.content), this.afterInline();
1004
+ }
1005
+ standard(t) {
1006
+ this.beforeInline(), this.chooseChildren(t.content), this.afterInline();
1007
+ }
1008
+ text(t) {
1009
+ }
1010
+ table(t) {
1011
+ for (const e of t.content)
1012
+ for (const i of e)
1013
+ this.beforeBlock(), this.chooseChildren(i.content), this.afterBlock();
1014
+ }
1015
+ social(t) {
1016
+ }
1017
+ underline(t) {
1018
+ this.beforeInline(), this.chooseChildren(t.content), this.afterInline();
1019
+ }
1020
+ video(t) {
1021
+ this.beforeBlock(), t.content && this.chooseChildren(t.content), this.afterBlock();
1022
+ }
1023
+ warning(t) {
1024
+ this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock();
1025
+ }
1026
+ card(t) {
1027
+ if (t.content && (this.beforeBlock(), this.chooseChildren(t.content.content), this.afterBlock()), t.attribution && t.attribution.title && (this.beforeBlock(), this.chooseChildren(t.attribution.title), this.afterBlock()), t.header && (this.beforeBlock(), this.chooseChildren(t.header.title), this.afterBlock()), t.media)
1028
+ for (const e of t.media.content)
1029
+ this.beforeBlock(), this.choose(e), this.afterBlock();
1030
+ }
1031
+ date(t) {
1032
+ this.beforeInline(), this.chooseChildren(t.content), this.afterInline();
1033
+ }
1034
+ time(t) {
1035
+ this.beforeInline(), this.chooseChildren(t.content), this.afterInline();
1036
+ }
1037
+ datetime(t) {
1038
+ this.beforeInline(), this.chooseChildren(t.content), this.afterInline();
1039
+ }
1040
+ subText(t) {
1041
+ this.beforeInline(), this.chooseChildren(t.content), this.afterInline();
1042
+ }
1043
+ superText(t) {
1044
+ this.beforeInline(), this.chooseChildren(t.content), this.afterInline();
1045
+ }
1046
+ toc(t) {
1047
+ this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock(), this.beforeBlock(), this.chooseChildren(t.children), this.afterBlock();
1048
+ }
1049
+ timeRange(t) {
1050
+ this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock();
1051
+ }
1052
+ choose(t) {
1053
+ if (!t || !t.type)
1054
+ throw new Error(`Unexpected node, no type: ${JSON.stringify(t)}`);
1055
+ try {
1056
+ switch (t.type) {
1057
+ case "block":
1058
+ return this.block(t);
1059
+ case "block-quote":
1060
+ return this.blockQuote(t);
1061
+ case "bold":
1062
+ return this.bold(t);
1063
+ case "break":
1064
+ return this.break_(t);
1065
+ case "bubble":
1066
+ return this.bubble(t);
1067
+ case "card":
1068
+ return this.card(t);
1069
+ case "center":
1070
+ return this.center(t);
1071
+ case "code":
1072
+ return this.code(t);
1073
+ case "columns":
1074
+ return this.columns(t);
1075
+ case "definition":
1076
+ return this.definition(t);
1077
+ case "definition-list":
1078
+ return this.definitionList(t);
1079
+ case "definition-reference":
1080
+ return this.definitionReference(t);
1081
+ case "embed":
1082
+ return this.embed(t);
1083
+ case "emoji":
1084
+ return this.emoji(t);
1085
+ case "figure":
1086
+ return this.figure(t);
1087
+ case "figure-caption":
1088
+ return this.figureCaption(t);
1089
+ case "figure-image":
1090
+ return this.figureImage(t);
1091
+ case "formatted-text":
1092
+ return this.formattedText(t);
1093
+ case "header":
1094
+ return this.header(t);
1095
+ case "high-tech-alert":
1096
+ return this.highTechAlert(t);
1097
+ case "horizontal-rule":
1098
+ return this.horizontalRule(t);
1099
+ case "image":
1100
+ return this.image(t);
1101
+ case "italic":
1102
+ return this.italic(t);
1103
+ case "link":
1104
+ return this.link(t);
1105
+ case "array":
1106
+ return this.array(t);
1107
+ case "note":
1108
+ return this.note(t);
1109
+ case "list":
1110
+ return this.list(t);
1111
+ case "paragraph":
1112
+ return this.paragraph(t);
1113
+ case "quote":
1114
+ return this.quote(t);
1115
+ case "redacted":
1116
+ return this.redacted(t);
1117
+ case "region":
1118
+ return this.region(t);
1119
+ case "script":
1120
+ return this.script(t);
1121
+ case "secret":
1122
+ return this.secret(t);
1123
+ case "smaller":
1124
+ return this.smaller(t);
1125
+ case "sticker":
1126
+ return this.sticker(t);
1127
+ case "standard":
1128
+ return this.standard(t);
1129
+ case "strike-through":
1130
+ return this.strikeThrough(t);
1131
+ case "table":
1132
+ return this.table(t);
1133
+ case "text":
1134
+ return this.text(t);
1135
+ case "toot":
1136
+ case "tweet":
1137
+ case "vimeo":
1138
+ case "youtube":
1139
+ return this.social(t);
1140
+ case "underline":
1141
+ return this.underline(t);
1142
+ case "video":
1143
+ return this.video(t);
1144
+ case "warning":
1145
+ return this.warning(t);
1146
+ case "date":
1147
+ return this.date(t);
1148
+ case "time":
1149
+ return this.time(t);
1150
+ case "datetime":
1151
+ return this.datetime(t);
1152
+ case "sub":
1153
+ return this.subText(t);
1154
+ case "super":
1155
+ return this.superText(t);
1156
+ case "toc":
1157
+ return this.toc(t);
1158
+ case "time-range":
1159
+ return this.timeRange(t);
1160
+ }
1161
+ } catch (e) {
1162
+ throw console.log(
1163
+ `Got exception while processing node: ${JSON.stringify(t)}`
1164
+ ), e;
1165
+ }
1166
+ console.error(`Unsupported type ${t.type}`);
1167
+ }
1168
+ document(t) {
1169
+ this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock(), this.beforeBlock(), t.definitions && this.chooseChildren(t.definitions), this.afterBlock();
1170
+ }
1171
+ visit(t) {
1172
+ t.type == "document" ? this.document(t) : this.choose(t);
1173
+ }
1174
+ }
1175
+ class g extends w {
1176
+ constructor() {
1177
+ super();
1178
+ l(this, "textList");
1179
+ this.textList = [];
1180
+ }
1181
+ text(e) {
1182
+ this.textList.push(e.text), super.text(e);
1183
+ }
1184
+ video(e) {
1185
+ this.textList.push(e.alt), super.video(e);
1186
+ }
1187
+ image(e) {
1188
+ this.textList.push(e.alt), super.image(e);
1189
+ }
1190
+ emoji(e) {
1191
+ this.textList.push(e.alt), super.emoji(e);
1192
+ }
1193
+ figureImage(e) {
1194
+ this.textList.push(e.alt), super.figureImage(e);
1195
+ }
1196
+ definitionReference(e) {
1197
+ this.chooseChildren(e.content);
1198
+ }
1199
+ definition(e) {
1200
+ this.chooseChildren(e.title), this.textList.push(" ("), this.chooseChildren(e.abbreviation), this.textList.push("): "), this.chooseChildren(e.content);
1201
+ }
1202
+ toc(e) {
1203
+ e.date && (this.choose(e.date), this.textList.push(" ")), this.chooseChildren(e.content), this.textList.push(`
1204
+ `), this.chooseChildren(e.children);
1205
+ }
1206
+ getText() {
1207
+ return this.textList.join("");
1208
+ }
1209
+ }
1210
+ class B extends k {
1211
+ async sticker(t) {
1212
+ if (t.content.length == 0)
1213
+ return null;
1214
+ const e = await this.chooseChildren(t.content);
1215
+ return e ? {
1216
+ type: "paragraph",
1217
+ content: e
1218
+ } : null;
1219
+ }
1220
+ async bubble(t) {
1221
+ if (t.content.length == 0)
1222
+ return null;
1223
+ const e = await this.chooseChildren(t.content);
1224
+ return e ? {
1225
+ type: "paragraph",
1226
+ content: e
1227
+ } : null;
1228
+ }
1229
+ async highTechAlert(t) {
1230
+ if (t.content.length == 0)
1231
+ return null;
1232
+ const e = await this.chooseChildren(t.content);
1233
+ return e ? {
1234
+ type: "array",
1235
+ content: e
1236
+ } : null;
1237
+ }
1238
+ async columns(t) {
1239
+ const e = t.columns.flat();
1240
+ if (e.length == 0)
1241
+ return null;
1242
+ const i = await this.chooseChildren(e);
1243
+ return i ? {
1244
+ type: "array",
1245
+ content: i
1246
+ } : null;
1247
+ }
1248
+ async quote(t) {
1249
+ if (t.content.length == 0)
1250
+ return null;
1251
+ const e = await this.chooseChildren(t.content);
1252
+ return e ? {
1253
+ type: "array",
1254
+ content: e
1255
+ } : null;
1256
+ }
1257
+ image(t) {
1258
+ return Promise.resolve({
1259
+ type: "paragraph",
1260
+ content: [{
1261
+ type: "text",
1262
+ text: "inline image: "
1263
+ }, {
1264
+ type: "text",
1265
+ text: t.alt
1266
+ }]
1267
+ });
1268
+ }
1269
+ async figureImage(t) {
1270
+ const e = {
1271
+ type: "paragraph",
1272
+ content: [{
1273
+ type: "text",
1274
+ text: "inline image: "
1275
+ }, {
1276
+ type: "text",
1277
+ text: t.alt
1278
+ }]
1279
+ };
1280
+ if (t.content) {
1281
+ const i = await this.chooseChildren(t.content);
1282
+ return {
1283
+ type: "array",
1284
+ content: [
1285
+ e,
1286
+ ...i
1287
+ ]
1288
+ };
1289
+ } else
1290
+ return e;
1291
+ }
1292
+ async video(t) {
1293
+ const e = {
1294
+ type: "paragraph",
1295
+ content: [{
1296
+ type: "text",
1297
+ text: "inline video: "
1298
+ }, {
1299
+ type: "text",
1300
+ text: t.alt
1301
+ }]
1302
+ };
1303
+ if (t.content) {
1304
+ const i = await this.chooseChildren(t.content);
1305
+ return {
1306
+ type: "array",
1307
+ content: [
1308
+ e,
1309
+ ...i
1310
+ ]
1311
+ };
1312
+ } else
1313
+ return e;
1314
+ }
1315
+ async definitionList(t) {
1316
+ const e = [];
1317
+ for (const i of t.content) {
1318
+ const r = [], s = await this.chooseChildren(i.title);
1319
+ if (s)
1320
+ for (const n of s)
1321
+ r.push(n);
1322
+ r.push({ type: "text", text: " " });
1323
+ const a = await this.chooseChildren(i.abbreviation);
1324
+ if (a)
1325
+ for (const n of a)
1326
+ r.push(n);
1327
+ if (i.content.length > 0 && i.content[0].type != "paragraph") {
1328
+ r.push({ type: "text", text: " " });
1329
+ const n = await this.chooseChildren(i.content);
1330
+ if (n)
1331
+ for (const o of n)
1332
+ r.push(o);
1333
+ }
1334
+ if (e.push({
1335
+ type: "paragraph",
1336
+ content: r
1337
+ }), i.content.length > 0 && i.content[0].type == "paragraph") {
1338
+ const n = await this.chooseChildren(i.content);
1339
+ if (n)
1340
+ for (const o of n)
1341
+ e.push(o);
1342
+ }
1343
+ }
1344
+ return {
1345
+ type: "array",
1346
+ content: e
1347
+ };
1348
+ }
1349
+ async redacted(t) {
1350
+ return null;
1351
+ }
1352
+ async note(t) {
1353
+ if (t.content.length == 0)
1354
+ return null;
1355
+ const e = await this.chooseChildren(t.content);
1356
+ return e ? {
1357
+ type: "paragraph",
1358
+ content: [
1359
+ { type: "text", text: "Note: " },
1360
+ ...e
1361
+ ]
1362
+ } : null;
1363
+ }
1364
+ async card(t) {
1365
+ const e = [];
1366
+ if (t.header) {
1367
+ const i = await this.chooseChildren(t.header.title);
1368
+ i.length > 0 && e.push({
1369
+ type: "paragraph",
1370
+ content: i
1371
+ });
1372
+ }
1373
+ if (t.content) {
1374
+ const i = await this.chooseChildren(t.content.content);
1375
+ for (const r of i)
1376
+ e.push(r);
1377
+ }
1378
+ if (t.media)
1379
+ for (const i of t.media.content) {
1380
+ const r = await this.choose(i);
1381
+ r && e.push(r);
1382
+ }
1383
+ if (t.attribution) {
1384
+ const i = [];
1385
+ if (t.attribution.title) {
1386
+ const r = await this.chooseChildren(t.attribution.title);
1387
+ for (const s of r)
1388
+ e.push(s);
1389
+ }
1390
+ t.attribution.date && (e.length > 0 && e.push({ type: "text", text: " " }), e.push({ type: "text", text: `${t.attribution.date}` })), i.length > 0 && e.push({
1391
+ type: "paragraph",
1392
+ content: i
1393
+ });
1394
+ }
1395
+ return {
1396
+ type: "array",
1397
+ content: e
1398
+ };
1399
+ }
1400
+ }
1401
+ class x extends w {
1402
+ constructor() {
1403
+ super();
1404
+ l(this, "count");
1405
+ l(this, "texts");
1406
+ this.count = 0, this.texts = [];
1407
+ }
1408
+ countText() {
1409
+ this.texts.length > 0 && (this.count += this.texts.join("").split(" ").length, this.texts = []);
1410
+ }
1411
+ beforeBlock() {
1412
+ this.countText();
1413
+ }
1414
+ afterBlock() {
1415
+ this.countText();
1416
+ }
1417
+ text(e) {
1418
+ this.texts.push(e.text);
1419
+ }
1420
+ document(e) {
1421
+ super.document(e), this.countText();
1422
+ }
1423
+ getCount() {
1424
+ return this.countText(), this.count;
1425
+ }
1426
+ }
1427
+ function d(c) {
1428
+ const t = {
1429
+ headerText: c.header,
1430
+ headerId: c.headerId,
1431
+ words: 0,
1432
+ totalWords: 0,
1433
+ children: []
1434
+ }, e = new x();
1435
+ for (const i of c.nodes)
1436
+ e.visit(i);
1437
+ t.words = e.getCount(), t.totalWords = t.words;
1438
+ for (const i of c.children) {
1439
+ const r = d(i);
1440
+ t.children.push(r), t.totalWords += r.totalWords;
1441
+ }
1442
+ return t;
1443
+ }
1444
+ class L extends u {
1445
+ constructor() {
1446
+ super();
1447
+ }
1448
+ async transform(t) {
1449
+ const e = JSON.parse(JSON.stringify(t)), i = await new B().transform(e), r = [], s = {
1450
+ header: t.title,
1451
+ headerId: "title",
1452
+ nodes: [],
1453
+ children: [],
1454
+ depth: 1
1455
+ };
1456
+ r.push(s);
1457
+ let a = 1;
1458
+ for (const o of i.content)
1459
+ if (o.type == "header") {
1460
+ if (o.level == 1)
1461
+ continue;
1462
+ if (o.level <= a)
1463
+ for (let p = r.length - 1; p > 0; p--)
1464
+ r[p].depth >= o.level && r.pop();
1465
+ const h = new g();
1466
+ h.visit(o);
1467
+ const f = {
1468
+ header: h.getText(),
1469
+ depth: o.level,
1470
+ children: [],
1471
+ nodes: []
1472
+ };
1473
+ o.htmlId && (f.headerId = o.htmlId), r[r.length - 1].children.push(f), r.push(f), a = o.level;
1474
+ } else
1475
+ r[r.length - 1].nodes.push(o);
1476
+ const n = {
1477
+ ...t
1478
+ };
1479
+ return n.hierarchy = d(s), n;
1480
+ }
1481
+ }
1482
+ export {
1483
+ k as ArrayCollapseTransformer,
1484
+ B as DocumentThinningTransformer,
1485
+ u as IdentityTransformer,
1486
+ w as NodeVisitor,
1487
+ I as TextCollapseTransformer,
1488
+ g as TextVisitor,
1489
+ v as WhitespaceStretchingTransformer,
1490
+ T as WhitespaceTransformer,
1491
+ L as WordCounterTransformer,
1492
+ x as WordCounterVisitor
1493
+ };