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