remark-docx 0.3.27 → 0.3.29

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 (43) hide show
  1. package/lib/chunk-CMqjfN_6.cjs +1 -0
  2. package/lib/index.cjs +2 -600
  3. package/lib/index.cjs.map +1 -1
  4. package/lib/index.d.ts +3 -3
  5. package/lib/index.js +468 -596
  6. package/lib/index.js.map +1 -1
  7. package/lib/mdast-util-to-docx.d.ts +2 -2
  8. package/lib/plugin.d.ts +3 -3
  9. package/lib/plugins/html/index.cjs +2 -28
  10. package/lib/plugins/html/index.cjs.map +1 -1
  11. package/lib/plugins/html/index.d.ts +1 -1
  12. package/lib/plugins/html/index.js +10 -25
  13. package/lib/plugins/html/index.js.map +1 -1
  14. package/lib/plugins/image/index.cjs +2 -129
  15. package/lib/plugins/image/index.cjs.map +1 -1
  16. package/lib/plugins/image/index.d.ts +1 -1
  17. package/lib/plugins/image/index.js +87 -124
  18. package/lib/plugins/image/index.js.map +1 -1
  19. package/lib/plugins/latex/index.cjs +2 -123
  20. package/lib/plugins/latex/index.cjs.map +1 -1
  21. package/lib/plugins/latex/index.d.ts +1 -7
  22. package/lib/plugins/latex/index.js +73 -119
  23. package/lib/plugins/latex/index.js.map +1 -1
  24. package/lib/plugins/mermaid/index.cjs +2 -77
  25. package/lib/plugins/mermaid/index.cjs.map +1 -1
  26. package/lib/plugins/mermaid/index.d.ts +1 -1
  27. package/lib/plugins/mermaid/index.js +46 -73
  28. package/lib/plugins/mermaid/index.js.map +1 -1
  29. package/lib/plugins/shiki/index.cjs +2 -113
  30. package/lib/plugins/shiki/index.cjs.map +1 -1
  31. package/lib/plugins/shiki/index.d.ts +2 -2
  32. package/lib/plugins/shiki/index.js +60 -109
  33. package/lib/plugins/shiki/index.js.map +1 -1
  34. package/lib/types.d.ts +3 -3
  35. package/lib/utils-BBifD5si.js +16 -0
  36. package/lib/utils-BBifD5si.js.map +1 -0
  37. package/lib/utils-D_YAYv4R.cjs +2 -0
  38. package/lib/utils-D_YAYv4R.cjs.map +1 -0
  39. package/package.json +6 -7
  40. package/lib/utils-BVB8aSvE.js +0 -25
  41. package/lib/utils-BVB8aSvE.js.map +0 -1
  42. package/lib/utils-KFMY7wxz.js +0 -22
  43. package/lib/utils-KFMY7wxz.js.map +0 -1
package/lib/index.js CHANGED
@@ -1,598 +1,470 @@
1
- import { sectionPageSizeDefaults, sectionMarginDefaults, Document, Packer, AlignmentType, LevelFormat, FootnoteReferenceRun, ImageRun, ExternalHyperlink, TextRun, Paragraph, TableRow, TableCell, Table, PageBreak, HeadingLevel } from 'docx';
2
- import { w as warnOnce } from './utils-KFMY7wxz.js';
3
- import { definitions } from 'mdast-util-definitions';
4
- import deepmerge from 'deepmerge';
5
-
6
- const BULLET_LIST_REF = "bullet";
7
- const ORDERED_LIST_REF = "ordered";
8
- const COMPLETE_TASK_LIST_REF = "task-complete";
9
- const INCOMPLETE_TASK_LIST_REF = "task-incomplete";
10
- const HYPERLINK_STYLE_ID = "Hyperlink";
11
- const calcIndent = (i) => {
12
- const INDENT_UNIT = 10 * 40;
13
- return { hanging: INDENT_UNIT, left: INDENT_UNIT * (i + 1) };
14
- };
15
- const createFootnoteRegistry = () => {
16
- const idToInternalId = new Map();
17
- const defs = new Map();
18
- return {
19
- id: (id) => {
20
- let internalId = idToInternalId.get(id);
21
- if (internalId == null) {
22
- idToInternalId.set(id, (internalId = idToInternalId.size + 1));
23
- }
24
- return internalId;
25
- },
26
- set: (id, def) => {
27
- defs.set(id, def);
28
- },
29
- toConfig: () => {
30
- return defs.entries().reduce((acc, [key, def]) => {
31
- acc[key] = { children: def };
32
- return acc;
33
- }, {});
34
- },
35
- };
36
- };
37
- const createOrderedListRegistry = () => {
38
- let counter = 1;
39
- const ids = [];
40
- return {
41
- createId: () => {
42
- const id = `${ORDERED_LIST_REF}-${counter++}`;
43
- ids.push(id);
44
- return id;
45
- },
46
- getIds: () => {
47
- return ids;
48
- },
49
- };
50
- };
51
- const composeBuilders = (pluginsBuilders, defaultBuilders) => {
52
- return pluginsBuilders.reduceRight((acc, p) => {
53
- for (const [k, cur] of Object.entries(p)) {
54
- const prev = acc[k];
55
- acc[k] = (prev
56
- ? (n, c) => {
57
- const r = cur(n, c);
58
- if (r) {
59
- return r;
60
- }
61
- return prev(n, c);
62
- }
63
- : cur);
64
- }
65
- return acc;
66
- }, defaultBuilders);
67
- };
68
- const buildLevels = (formats) => {
69
- return formats.map(({ format, text }, i) => {
70
- return {
71
- level: i,
72
- format: LevelFormat[format],
73
- text: text,
74
- alignment: AlignmentType.LEFT,
75
- style: {
76
- paragraph: {
77
- indent: calcIndent(i),
78
- },
79
- },
80
- };
81
- });
82
- };
83
- const docxParagraph = (options, ctx) => {
84
- if (ctx.quote != null) {
85
- options.indent = calcIndent(ctx.quote + 1);
86
- }
87
- if (ctx.list) {
88
- const { level, meta } = ctx.list;
89
- if (meta.type === "task") {
90
- options.numbering = {
91
- reference: meta.checked
92
- ? COMPLETE_TASK_LIST_REF
93
- : INCOMPLETE_TASK_LIST_REF,
94
- level,
95
- };
96
- }
97
- else if (meta.type === "ordered") {
98
- options.numbering = {
99
- reference: meta.reference,
100
- level,
101
- };
102
- }
103
- else {
104
- options.numbering = {
105
- reference: BULLET_LIST_REF,
106
- level,
107
- };
108
- }
109
- }
110
- if (ctx.rtl) {
111
- options.bidirectional = true;
112
- }
113
- return new Paragraph(options);
114
- };
115
- const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywords, description, styles, size, margin, orientation, columns, spacing, direction, background, thematicBreak = "page", orderedListFormat, } = {}) => {
116
- const definition = definitions(node);
117
- const ordered = createOrderedListRegistry();
118
- const footnote = createFootnoteRegistry();
119
- const images = new Map();
120
- const pluginCtx = { root: node, images, definition };
121
- const builders = composeBuilders(await Promise.all(plugins.map((p) => p(pluginCtx))), {
122
- paragraph: buildParagraph,
123
- heading: buildHeading,
124
- thematicBreak: buildThematicBreak,
125
- blockquote: buildBlockquote,
126
- list: buildList,
127
- listItem: buildListItem,
128
- table: buildTable,
129
- tableRow: noop,
130
- tableCell: noop,
131
- html: fallbackText,
132
- code: fallbackText,
133
- definition: noop,
134
- footnoteDefinition: buildFootnoteDefinition,
135
- text: buildText,
136
- emphasis: buildEmphasis,
137
- strong: buildStrong,
138
- delete: buildDelete,
139
- inlineCode: buildInlineCode,
140
- break: buildBreak,
141
- link: buildLink,
142
- linkReference: buildLinkReference,
143
- image: buildImage,
144
- imageReference: buildImageReference,
145
- footnoteReference: buildFootnoteReference,
146
- math: fallbackText,
147
- inlineMath: fallbackText,
148
- });
149
- const renderNode = (node, c) => {
150
- const builder = builders[node.type];
151
- if (!builder) {
152
- warnOnce(`${node.type} node is not supported without plugins.`);
153
- return null;
154
- }
155
- const r = builder(node, c);
156
- if (r) {
157
- if (Array.isArray(r)) {
158
- return r;
159
- }
160
- else {
161
- return [r];
162
- }
163
- }
164
- return null;
165
- };
166
- let { WIDTH: pageWidth, HEIGHT: pageHeight } = sectionPageSizeDefaults;
167
- if (size) {
168
- if (size.width != null) {
169
- pageWidth = size.width;
170
- }
171
- if (size.height != null) {
172
- pageHeight = size.height;
173
- }
174
- }
175
- let { TOP: marginTop, LEFT: marginLeft, BOTTOM: marginBottom, RIGHT: marginRight, } = sectionMarginDefaults;
176
- if (margin) {
177
- if (margin.top != null) {
178
- marginTop = margin.top;
179
- }
180
- if (margin.left != null) {
181
- marginLeft = margin.left;
182
- }
183
- if (margin.bottom != null) {
184
- marginBottom = margin.bottom;
185
- }
186
- if (margin.right != null) {
187
- marginRight = margin.right;
188
- }
189
- }
190
- const ctx = {
191
- render(nodes, c) {
192
- const results = [];
193
- for (const node of nodes) {
194
- const r = renderNode(node, c !== null && c !== void 0 ? c : this);
195
- if (r) {
196
- results.push(...r);
197
- }
198
- }
199
- return results;
200
- },
201
- width: pageWidth - marginLeft - marginRight,
202
- style: {},
203
- thematicBreak,
204
- rtl: direction === "rtl",
205
- definition: definition,
206
- images,
207
- footnote,
208
- orderedId: ordered.createId,
209
- };
210
- const sections = [[]];
211
- for (const n of node.children) {
212
- const r = renderNode(n, ctx);
213
- if (r) {
214
- if (!r.length) {
215
- // thematicBreak
216
- sections.push([]);
217
- }
218
- else {
219
- const lastSection = sections[sections.length - 1];
220
- lastSection.push(...r);
221
- }
222
- }
223
- }
224
- const orderedLevels = buildLevels(orderedListFormat !== null && orderedListFormat !== void 0 ? orderedListFormat : [
225
- { text: "%1.", format: "DECIMAL" },
226
- { text: "%2.", format: "DECIMAL" },
227
- { text: "%3.", format: "DECIMAL" },
228
- { text: "%4.", format: "DECIMAL" },
229
- { text: "%5.", format: "DECIMAL" },
230
- { text: "%6.", format: "DECIMAL" },
231
- ]);
232
- const sectionProperties = {
233
- column: columns ? { count: columns } : undefined,
234
- page: {
235
- textDirection: direction === "vertical" ? "tbRl" : undefined,
236
- size: { width: pageWidth, height: pageHeight, orientation },
237
- margin: {
238
- top: marginTop,
239
- left: marginLeft,
240
- bottom: marginBottom,
241
- right: marginRight,
242
- },
243
- },
244
- };
245
- const doc = new Document({
246
- title,
247
- subject,
248
- creator,
249
- keywords,
250
- description,
251
- styles: deepmerge({
252
- default: {
253
- document: {
254
- paragraph: {
255
- spacing: spacing ? { after: spacing } : undefined,
256
- },
257
- },
258
- },
259
- }, styles || {}),
260
- background,
261
- sections: sections
262
- .filter((s) => s.length)
263
- .map((s) => ({
264
- properties: sectionProperties,
265
- children: s,
266
- })),
267
- footnotes: footnote.toConfig(),
268
- numbering: {
269
- config: [
270
- {
271
- reference: BULLET_LIST_REF,
272
- levels: buildLevels([
273
- { text: "\u25CF", format: "BULLET" },
274
- { text: "\u25CB", format: "BULLET" },
275
- { text: "\u25A0", format: "BULLET" },
276
- { text: "\u25CF", format: "BULLET" },
277
- { text: "\u25CB", format: "BULLET" },
278
- { text: "\u25A0", format: "BULLET" },
279
- ]),
280
- },
281
- ...ordered.getIds().map((ref) => ({
282
- reference: ref,
283
- levels: orderedLevels,
284
- })),
285
- {
286
- reference: COMPLETE_TASK_LIST_REF,
287
- levels: buildLevels([
288
- { text: "\u2611", format: "BULLET" },
289
- { text: "\u2611", format: "BULLET" },
290
- { text: "\u2611", format: "BULLET" },
291
- { text: "\u2611", format: "BULLET" },
292
- { text: "\u2611", format: "BULLET" },
293
- { text: "\u2611", format: "BULLET" },
294
- ]),
295
- },
296
- {
297
- reference: INCOMPLETE_TASK_LIST_REF,
298
- levels: buildLevels([
299
- { text: "\u2610", format: "BULLET" },
300
- { text: "\u2610", format: "BULLET" },
301
- { text: "\u2610", format: "BULLET" },
302
- { text: "\u2610", format: "BULLET" },
303
- { text: "\u2610", format: "BULLET" },
304
- { text: "\u2610", format: "BULLET" },
305
- ]),
306
- },
307
- ],
308
- },
309
- });
310
- // HACK: docx.js has no option to remove default numbering definitions from .docx. So do it here for now.
311
- // https://github.com/dolanmiu/docx/blob/master/src/file/numbering/numbering.ts
312
- const defaultBulletKey = "default-bullet-numbering";
313
- const _numbering = doc.numbering;
314
- _numbering.abstractNumberingMap.delete(defaultBulletKey);
315
- _numbering.concreteNumberingMap.delete(defaultBulletKey);
316
- return Packer.toArrayBuffer(doc);
317
- };
318
- const buildParagraph = ({ children }, ctx) => {
319
- return docxParagraph({
320
- children: ctx.render(children),
321
- }, ctx);
322
- };
323
- const buildHeading = ({ children, depth }, ctx) => {
324
- let level;
325
- switch (depth) {
326
- case 1:
327
- level = "TITLE";
328
- break;
329
- case 2:
330
- level = "HEADING_1";
331
- break;
332
- case 3:
333
- level = "HEADING_2";
334
- break;
335
- case 4:
336
- level = "HEADING_3";
337
- break;
338
- case 5:
339
- level = "HEADING_4";
340
- break;
341
- case 6:
342
- level = "HEADING_5";
343
- break;
344
- }
345
- return docxParagraph({
346
- heading: HeadingLevel[level],
347
- outlineLevel: depth - 1,
348
- children: ctx.render(children),
349
- }, ctx);
350
- };
351
- const buildThematicBreak = (_, ctx) => {
352
- switch (ctx.thematicBreak) {
353
- case "page": {
354
- return new Paragraph({ children: [new PageBreak()] });
355
- }
356
- case "section": {
357
- // Returning empty array at toplevel means section insertion.
358
- return [];
359
- }
360
- case "line": {
361
- return new Paragraph({ thematicBreak: true });
362
- }
363
- }
364
- };
365
- const buildBlockquote = ({ children }, ctx) => {
366
- return ctx.render(children, {
367
- ...ctx,
368
- quote: ctx.quote == null ? 0 : ctx.quote + 1,
369
- });
370
- };
371
- const buildList = ({ children, ordered }, ctx) => {
372
- const parentList = ctx.list;
373
- let meta;
374
- if (ordered) {
375
- meta = {
376
- type: "ordered",
377
- reference: parentList && parentList.meta.type === "ordered"
378
- ? parentList.meta.reference
379
- : ctx.orderedId(),
380
- };
381
- }
382
- else {
383
- meta = { type: "bullet" };
384
- }
385
- return ctx.render(children, {
386
- ...ctx,
387
- list: {
388
- level: !parentList ? 0 : parentList.level + 1,
389
- meta,
390
- },
391
- });
392
- };
393
- const buildListItem = ({ children, checked }, ctx) => {
394
- let list = ctx.list;
395
- if (list) {
396
- // listItem must be the child of list
397
- if (checked != null) {
398
- list = {
399
- level: list.level,
400
- meta: {
401
- type: "task",
402
- checked,
403
- },
404
- };
405
- }
406
- }
407
- return ctx.render(children, {
408
- ...ctx,
409
- list,
410
- });
411
- };
412
- const buildTable = ({ children, align }, ctx) => {
413
- const textAlign = align === null || align === void 0 ? void 0 : align.map((a) => {
414
- switch (a) {
415
- case "left":
416
- return "LEFT";
417
- case "right":
418
- return "RIGHT";
419
- case "center":
420
- return "CENTER";
421
- default:
422
- return "LEFT";
423
- }
424
- });
425
- const columnLength = children[0].children.length;
426
- const columnWidth = ctx.width / columnLength;
427
- const options = {
428
- columnWidths: Array.from({ length: columnLength }).map(() => columnWidth),
429
- rows: children.map((r) => {
430
- return new TableRow({
431
- children: r.children.map((c, i) => {
432
- var _a;
433
- return new TableCell({
434
- width: { size: columnWidth, type: "dxa" },
435
- children: [
436
- new Paragraph({
437
- alignment: AlignmentType[(_a = textAlign === null || textAlign === void 0 ? void 0 : textAlign[i]) !== null && _a !== void 0 ? _a : "LEFT"],
438
- children: ctx.render(c.children, {
439
- ...ctx,
440
- // https://github.com/dolanmiu/docx/blob/master/demo/22-right-to-left-text.ts
441
- rtl: undefined,
442
- }),
443
- }),
444
- ],
445
- });
446
- }),
447
- });
448
- }),
449
- };
450
- if (ctx.rtl) {
451
- options.visuallyRightToLeft = true;
452
- }
453
- return new Table(options);
454
- };
455
- const buildText = ({ value }, { style, rtl }) => {
456
- const options = {
457
- text: value,
458
- bold: style.bold,
459
- italics: style.italic,
460
- strike: style.strike,
461
- };
462
- if (style.inlineCode) {
463
- options.highlight = "lightGray";
464
- }
465
- if (style.link) {
466
- // https://docx.js.org/#/usage/hyperlinks?id=styling-hyperlinks
467
- options.style = HYPERLINK_STYLE_ID;
468
- }
469
- if (rtl) {
470
- options.rightToLeft = true;
471
- }
472
- return new TextRun(options);
473
- };
474
- const buildEmphasis = ({ children }, ctx) => {
475
- return ctx.render(children, {
476
- ...ctx,
477
- style: { ...ctx.style, italic: true },
478
- });
479
- };
480
- const buildStrong = ({ children }, ctx) => {
481
- return ctx.render(children, {
482
- ...ctx,
483
- style: { ...ctx.style, bold: true },
484
- });
485
- };
486
- const buildDelete = ({ children }, ctx) => {
487
- return ctx.render(children, {
488
- ...ctx,
489
- style: { ...ctx.style, strike: true },
490
- });
491
- };
492
- const buildInlineCode = ({ value }, ctx) => {
493
- return buildText({ value }, {
494
- ...ctx,
495
- style: { ...ctx.style, inlineCode: true },
496
- });
497
- };
498
- const buildBreak = () => {
499
- return new TextRun({ text: "", break: 1 });
500
- };
501
- const buildLink = ({ children, url }, ctx) => {
502
- if (url.startsWith("#")) {
503
- // TODO support anchor link
504
- return ctx.render(children);
505
- }
506
- return new ExternalHyperlink({
507
- link: url,
508
- children: ctx.render(children, {
509
- ...ctx,
510
- style: { ...ctx.style, link: true },
511
- }),
512
- });
513
- };
514
- const buildLinkReference = ({ children, identifier }, ctx) => {
515
- const def = ctx.definition(identifier);
516
- if (def == null) {
517
- return ctx.render(children);
518
- }
519
- return buildLink({ children, url: def.url }, ctx);
520
- };
521
- const buildImage = (node, ctx) => {
522
- var _a, _b;
523
- const image = ctx.images.get(node.url);
524
- if (!image) {
525
- return null;
526
- }
527
- let { width, height } = image;
528
- const pageWidthInch = ctx.width / 1440;
529
- const DPI = 96;
530
- const pageWidthPx = pageWidthInch * DPI;
531
- if (width > pageWidthPx) {
532
- const scale = pageWidthPx / width;
533
- width *= scale;
534
- height *= scale;
535
- }
536
- const altText = node.alt || node.title
537
- ? {
538
- name: "",
539
- description: (_a = node.alt) !== null && _a !== void 0 ? _a : undefined,
540
- title: (_b = node.title) !== null && _b !== void 0 ? _b : undefined,
541
- }
542
- : undefined;
543
- if (image.type === "svg") {
544
- const { type, data, fallback } = image;
545
- return new ImageRun({
546
- type: type,
547
- data: data,
548
- transformation: {
549
- width,
550
- height,
551
- },
552
- // https://github.com/dolanmiu/docx/issues/1162#issuecomment-3228368003
553
- fallback: { type: "png", data: fallback },
554
- altText,
555
- });
556
- }
557
- const { type, data } = image;
558
- return new ImageRun({
559
- type: type,
560
- data: data,
561
- transformation: {
562
- width,
563
- height,
564
- },
565
- altText,
566
- });
567
- };
568
- const buildImageReference = (node, ctx) => {
569
- const def = ctx.definition(node.identifier);
570
- if (def == null) {
571
- return null;
572
- }
573
- return buildImage({ url: def.url, alt: node.alt, title: def.title }, ctx);
574
- };
575
- const buildFootnoteDefinition = ({ children, identifier }, ctx) => {
576
- const contents = ctx.render(children).filter((c) => c instanceof Paragraph);
577
- ctx.footnote.set(ctx.footnote.id(identifier), contents);
578
- return null;
579
- };
580
- const buildFootnoteReference = ({ identifier }, ctx) => {
581
- return new FootnoteReferenceRun(ctx.footnote.id(identifier));
582
- };
583
- const noop = () => {
584
- return null;
585
- };
586
- const fallbackText = (node, ctx) => {
587
- warnOnce(`${node.type} node is not supported without plugins, falling back to text.`);
588
- return buildText({ value: node.value }, ctx);
589
- };
590
-
591
- const plugin = function (opts) {
592
- this.compiler = (node) => {
593
- return mdastToDocx(node, opts);
594
- };
1
+ import { n as e } from "./utils-BBifD5si.js";
2
+ import { AlignmentType as t, Document as n, ExternalHyperlink as r, FootnoteReferenceRun as i, HeadingLevel as a, ImageRun as o, LevelFormat as s, Packer as c, PageBreak as l, Paragraph as u, Table as d, TableCell as f, TableRow as p, TextRun as m, sectionMarginDefaults as ee, sectionPageSizeDefaults as te } from "docx";
3
+ import { definitions as h } from "mdast-util-definitions";
4
+ import g from "deepmerge";
5
+ //#region src/mdast-util-to-docx.ts
6
+ var _ = "bullet", v = "ordered", y = "task-complete", b = "task-incomplete", x = "Hyperlink", S = (e) => ({
7
+ hanging: 400,
8
+ left: 400 * (e + 1)
9
+ }), ne = () => {
10
+ let e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map();
11
+ return {
12
+ id: (t) => {
13
+ let n = e.get(t);
14
+ return n ?? e.set(t, n = e.size + 1), n;
15
+ },
16
+ set: (e, n) => {
17
+ t.set(e, n);
18
+ },
19
+ toConfig: () => t.entries().reduce((e, [t, n]) => (e[t] = { children: n }, e), {})
20
+ };
21
+ }, re = () => {
22
+ let e = 1, t = [];
23
+ return {
24
+ createId: () => {
25
+ let n = `${v}-${e++}`;
26
+ return t.push(n), n;
27
+ },
28
+ getIds: () => t
29
+ };
30
+ }, ie = (e, t) => e.reduceRight((e, t) => {
31
+ for (let [n, r] of Object.entries(t)) {
32
+ let t = e[n];
33
+ e[n] = t ? (e, n) => r(e, n) || t(e, n) : r;
34
+ }
35
+ return e;
36
+ }, t), C = (e) => e.map(({ format: e, text: n }, r) => ({
37
+ level: r,
38
+ format: s[e],
39
+ text: n,
40
+ alignment: t.LEFT,
41
+ style: { paragraph: { indent: S(r) } }
42
+ })), w = (e, t) => {
43
+ if (t.quote != null && (e.indent = S(t.quote + 1)), t.list) {
44
+ let { level: n, meta: r } = t.list;
45
+ r.type === "task" ? e.numbering = {
46
+ reference: r.checked ? y : b,
47
+ level: n
48
+ } : r.type === "ordered" ? e.numbering = {
49
+ reference: r.reference,
50
+ level: n
51
+ } : e.numbering = {
52
+ reference: _,
53
+ level: n
54
+ };
55
+ }
56
+ return t.rtl && (e.bidirectional = !0), new u(e);
57
+ }, T = async (t, { plugins: r = [], title: i, subject: a, creator: o, keywords: s, description: l, styles: u, size: d, margin: f, orientation: p, columns: m, spacing: v, direction: x, background: S, thematicBreak: w = "page", orderedListFormat: T } = {}) => {
58
+ let z = h(t), B = re(), V = ne(), H = /* @__PURE__ */ new Map(), me = {
59
+ root: t,
60
+ images: H,
61
+ definition: z
62
+ }, he = ie(await Promise.all(r.map((e) => e(me))), {
63
+ paragraph: ae,
64
+ heading: E,
65
+ thematicBreak: D,
66
+ blockquote: O,
67
+ list: oe,
68
+ listItem: se,
69
+ table: ce,
70
+ tableRow: I,
71
+ tableCell: I,
72
+ html: L,
73
+ code: R,
74
+ definition: I,
75
+ footnoteDefinition: P,
76
+ text: k,
77
+ emphasis: le,
78
+ strong: ue,
79
+ delete: de,
80
+ inlineCode: fe,
81
+ break: pe,
82
+ link: A,
83
+ linkReference: j,
84
+ image: M,
85
+ imageReference: N,
86
+ footnoteReference: F,
87
+ math: L,
88
+ inlineMath: L
89
+ }), U = (t, n) => {
90
+ let r = he[t.type];
91
+ if (!r) return e(`${t.type} node is not supported without plugins.`), null;
92
+ let i = r(t, n);
93
+ return i ? Array.isArray(i) ? i : [i] : null;
94
+ }, { WIDTH: W, HEIGHT: G } = te;
95
+ d && (d.width != null && (W = d.width), d.height != null && (G = d.height));
96
+ let { TOP: K, LEFT: q, BOTTOM: J, RIGHT: Y } = ee;
97
+ f && (f.top != null && (K = f.top), f.left != null && (q = f.left), f.bottom != null && (J = f.bottom), f.right != null && (Y = f.right));
98
+ let ge = {
99
+ render(e, t) {
100
+ let n = [];
101
+ for (let r of e) {
102
+ let e = U(r, t ?? this);
103
+ e && n.push(...e);
104
+ }
105
+ return n;
106
+ },
107
+ width: W - q - Y,
108
+ style: {},
109
+ thematicBreak: w,
110
+ rtl: x === "rtl",
111
+ definition: z,
112
+ images: H,
113
+ footnote: V,
114
+ orderedId: B.createId
115
+ }, X = [[]];
116
+ for (let e of t.children) {
117
+ let t = U(e, ge);
118
+ t && (t.length ? X[X.length - 1].push(...t) : X.push([]));
119
+ }
120
+ let _e = C(T ?? [
121
+ {
122
+ text: "%1.",
123
+ format: "DECIMAL"
124
+ },
125
+ {
126
+ text: "%2.",
127
+ format: "DECIMAL"
128
+ },
129
+ {
130
+ text: "%3.",
131
+ format: "DECIMAL"
132
+ },
133
+ {
134
+ text: "%4.",
135
+ format: "DECIMAL"
136
+ },
137
+ {
138
+ text: "%5.",
139
+ format: "DECIMAL"
140
+ },
141
+ {
142
+ text: "%6.",
143
+ format: "DECIMAL"
144
+ }
145
+ ]), ve = {
146
+ column: m ? { count: m } : void 0,
147
+ page: {
148
+ textDirection: x === "vertical" ? "tbRl" : void 0,
149
+ size: {
150
+ width: W,
151
+ height: G,
152
+ orientation: p
153
+ },
154
+ margin: {
155
+ top: K,
156
+ left: q,
157
+ bottom: J,
158
+ right: Y
159
+ }
160
+ }
161
+ }, Z = new n({
162
+ title: i,
163
+ subject: a,
164
+ creator: o,
165
+ keywords: s,
166
+ description: l,
167
+ styles: g({ default: { document: { paragraph: { spacing: v ? { after: v } : void 0 } } } }, u || {}),
168
+ background: S,
169
+ sections: X.filter((e) => e.length).map((e) => ({
170
+ properties: ve,
171
+ children: e
172
+ })),
173
+ footnotes: V.toConfig(),
174
+ numbering: { config: [
175
+ {
176
+ reference: _,
177
+ levels: C([
178
+ {
179
+ text: "●",
180
+ format: "BULLET"
181
+ },
182
+ {
183
+ text: "○",
184
+ format: "BULLET"
185
+ },
186
+ {
187
+ text: "■",
188
+ format: "BULLET"
189
+ },
190
+ {
191
+ text: "●",
192
+ format: "BULLET"
193
+ },
194
+ {
195
+ text: "○",
196
+ format: "BULLET"
197
+ },
198
+ {
199
+ text: "■",
200
+ format: "BULLET"
201
+ }
202
+ ])
203
+ },
204
+ ...B.getIds().map((e) => ({
205
+ reference: e,
206
+ levels: _e
207
+ })),
208
+ {
209
+ reference: y,
210
+ levels: C([
211
+ {
212
+ text: "☑",
213
+ format: "BULLET"
214
+ },
215
+ {
216
+ text: "☑",
217
+ format: "BULLET"
218
+ },
219
+ {
220
+ text: "☑",
221
+ format: "BULLET"
222
+ },
223
+ {
224
+ text: "☑",
225
+ format: "BULLET"
226
+ },
227
+ {
228
+ text: "",
229
+ format: "BULLET"
230
+ },
231
+ {
232
+ text: "☑",
233
+ format: "BULLET"
234
+ }
235
+ ])
236
+ },
237
+ {
238
+ reference: b,
239
+ levels: C([
240
+ {
241
+ text: "☐",
242
+ format: "BULLET"
243
+ },
244
+ {
245
+ text: "☐",
246
+ format: "BULLET"
247
+ },
248
+ {
249
+ text: "☐",
250
+ format: "BULLET"
251
+ },
252
+ {
253
+ text: "☐",
254
+ format: "BULLET"
255
+ },
256
+ {
257
+ text: "☐",
258
+ format: "BULLET"
259
+ },
260
+ {
261
+ text: "☐",
262
+ format: "BULLET"
263
+ }
264
+ ])
265
+ }
266
+ ] }
267
+ }), Q = "default-bullet-numbering", $ = Z.numbering;
268
+ return $.abstractNumberingMap.delete(Q), $.concreteNumberingMap.delete(Q), c.toArrayBuffer(Z);
269
+ }, ae = ({ children: e }, t) => w({ children: t.render(e) }, t), E = ({ children: e, depth: t }, n) => {
270
+ let r;
271
+ switch (t) {
272
+ case 1:
273
+ r = "TITLE";
274
+ break;
275
+ case 2:
276
+ r = "HEADING_1";
277
+ break;
278
+ case 3:
279
+ r = "HEADING_2";
280
+ break;
281
+ case 4:
282
+ r = "HEADING_3";
283
+ break;
284
+ case 5:
285
+ r = "HEADING_4";
286
+ break;
287
+ case 6:
288
+ r = "HEADING_5";
289
+ break;
290
+ }
291
+ return w({
292
+ heading: a[r],
293
+ outlineLevel: t - 1,
294
+ children: n.render(e)
295
+ }, n);
296
+ }, D = (e, t) => {
297
+ switch (t.thematicBreak) {
298
+ case "page": return new u({ children: [new l()] });
299
+ case "section": return [];
300
+ case "line": return new u({ thematicBreak: !0 });
301
+ }
302
+ }, O = ({ children: e }, t) => t.render(e, {
303
+ ...t,
304
+ quote: t.quote == null ? 0 : t.quote + 1
305
+ }), oe = ({ children: e, ordered: t }, n) => {
306
+ let r = n.list, i;
307
+ return i = t ? {
308
+ type: "ordered",
309
+ reference: r && r.meta.type === "ordered" ? r.meta.reference : n.orderedId()
310
+ } : { type: "bullet" }, n.render(e, {
311
+ ...n,
312
+ list: {
313
+ level: r ? r.level + 1 : 0,
314
+ meta: i
315
+ }
316
+ });
317
+ }, se = ({ children: e, checked: t }, n) => {
318
+ let r = n.list;
319
+ return r && t != null && (r = {
320
+ level: r.level,
321
+ meta: {
322
+ type: "task",
323
+ checked: t
324
+ }
325
+ }), n.render(e, {
326
+ ...n,
327
+ list: r
328
+ });
329
+ }, ce = ({ children: e, align: n }, r) => {
330
+ let i = n?.map((e) => {
331
+ switch (e) {
332
+ case "left": return "LEFT";
333
+ case "right": return "RIGHT";
334
+ case "center": return "CENTER";
335
+ default: return "LEFT";
336
+ }
337
+ }), a = e[0].children.length, o = r.width / a, s = {
338
+ columnWidths: Array.from({ length: a }).map(() => o),
339
+ rows: e.map((e) => new p({ children: e.children.map((e, n) => new f({
340
+ width: {
341
+ size: o,
342
+ type: "dxa"
343
+ },
344
+ children: [new u({
345
+ alignment: t[i?.[n] ?? "LEFT"],
346
+ children: r.render(e.children, {
347
+ ...r,
348
+ rtl: void 0
349
+ })
350
+ })]
351
+ })) }))
352
+ };
353
+ return r.rtl && (s.visuallyRightToLeft = !0), new d(s);
354
+ }, k = ({ value: e }, { style: t, rtl: n }) => {
355
+ let r = {
356
+ text: e,
357
+ bold: t.bold,
358
+ italics: t.italic,
359
+ strike: t.strike
360
+ };
361
+ return t.inlineCode && (r.highlight = "lightGray"), t.link && (r.style = x), n && (r.rightToLeft = !0), new m(r);
362
+ }, le = ({ children: e }, t) => t.render(e, {
363
+ ...t,
364
+ style: {
365
+ ...t.style,
366
+ italic: !0
367
+ }
368
+ }), ue = ({ children: e }, t) => t.render(e, {
369
+ ...t,
370
+ style: {
371
+ ...t.style,
372
+ bold: !0
373
+ }
374
+ }), de = ({ children: e }, t) => t.render(e, {
375
+ ...t,
376
+ style: {
377
+ ...t.style,
378
+ strike: !0
379
+ }
380
+ }), fe = ({ value: e }, t) => k({
381
+ type: "text",
382
+ value: e
383
+ }, {
384
+ ...t,
385
+ style: {
386
+ ...t.style,
387
+ inlineCode: !0
388
+ }
389
+ }), pe = () => new m({
390
+ text: "",
391
+ break: 1
392
+ }), A = ({ children: e, url: t }, n) => t.startsWith("#") ? n.render(e) : new r({
393
+ link: t,
394
+ children: n.render(e, {
395
+ ...n,
396
+ style: {
397
+ ...n.style,
398
+ link: !0
399
+ }
400
+ })
401
+ }), j = ({ children: e, identifier: t }, n) => {
402
+ let r = n.definition(t);
403
+ return r == null ? n.render(e) : A({
404
+ type: "link",
405
+ children: e,
406
+ url: r.url
407
+ }, n);
408
+ }, M = (e, t) => {
409
+ let n = t.images.get(e.url);
410
+ if (!n) return null;
411
+ let { width: r, height: i } = n, a = t.width / 1440 * 96;
412
+ if (r > a) {
413
+ let e = a / r;
414
+ r *= e, i *= e;
415
+ }
416
+ let s = e.alt || e.title ? {
417
+ name: "",
418
+ description: e.alt ?? void 0,
419
+ title: e.title ?? void 0
420
+ } : void 0;
421
+ if (n.type === "svg") {
422
+ let { type: e, data: t, fallback: a } = n;
423
+ return new o({
424
+ type: e,
425
+ data: t,
426
+ transformation: {
427
+ width: r,
428
+ height: i
429
+ },
430
+ fallback: {
431
+ type: "png",
432
+ data: a
433
+ },
434
+ altText: s
435
+ });
436
+ }
437
+ let { type: c, data: l } = n;
438
+ return new o({
439
+ type: c,
440
+ data: l,
441
+ transformation: {
442
+ width: r,
443
+ height: i
444
+ },
445
+ altText: s
446
+ });
447
+ }, N = (e, t) => {
448
+ let n = t.definition(e.identifier);
449
+ return n == null ? null : M({
450
+ type: "image",
451
+ url: n.url,
452
+ alt: e.alt,
453
+ title: n.title
454
+ }, t);
455
+ }, P = ({ children: e, identifier: t }, n) => {
456
+ let r = n.render(e).filter((e) => e instanceof u);
457
+ return n.footnote.set(n.footnote.id(t), r), null;
458
+ }, F = ({ identifier: e }, t) => new i(t.footnote.id(e)), I = () => null, L = (t, n) => (e(`${t.type} node is not supported without plugins, falling back to text.`), k({
459
+ type: "text",
460
+ value: t.value
461
+ }, n)), R = (t, n) => (e(`${t.type} node is not supported without plugins, falling back to text.`), w({ children: t.value.split(/\r?\n/).map((e, t) => new m({
462
+ text: e,
463
+ break: t === 0 ? void 0 : 1
464
+ })) }, n)), z = function(e) {
465
+ this.compiler = (t) => T(t, e);
595
466
  };
467
+ //#endregion
468
+ export { z as default };
596
469
 
597
- export { plugin as default };
598
- //# sourceMappingURL=index.js.map
470
+ //# sourceMappingURL=index.js.map