remark-docx 0.3.17 → 0.3.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -12
- package/lib/index.cjs +49 -23
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +49 -23
- package/lib/index.js.map +1 -1
- package/lib/mdast-util-to-docx.d.ts +19 -1
- package/lib/plugins/image/index.cjs.map +1 -1
- package/lib/plugins/image/index.d.ts +1 -1
- package/lib/plugins/image/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ Currently, some of the default styles may not be nice. If you have feature reque
|
|
|
14
14
|
|
|
15
15
|
- [x] paragraph
|
|
16
16
|
- [x] heading
|
|
17
|
-
- [x] thematicBreak
|
|
17
|
+
- [x] thematicBreak (rendered as Page Break/Section Break)
|
|
18
18
|
- [x] blockquote
|
|
19
19
|
- [x] list / listItem
|
|
20
20
|
- [x] table / tableRow / tableCell
|
|
@@ -86,7 +86,7 @@ const text = "# hello world";
|
|
|
86
86
|
|
|
87
87
|
### Image
|
|
88
88
|
|
|
89
|
-
Fetch image data and embed into docx.
|
|
89
|
+
Fetch image data and embed into docx. `png`, `jpg`, `gif`, `bmp`, `svg` urls are supported.
|
|
90
90
|
|
|
91
91
|
```javascript
|
|
92
92
|
import { unified } from "unified";
|
|
@@ -99,6 +99,19 @@ const processor = unified()
|
|
|
99
99
|
.use(docx, { plugins: [imagePlugin()] });
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
+
When we embed `svg` to docx, it also requires `png` image for compatibility reason. On browser, this plugin generate it automatically. On other enviroment like Node.js, please implement `fallbackSvg` prop.
|
|
103
|
+
|
|
104
|
+
```javascript
|
|
105
|
+
import sharp from "sharp";
|
|
106
|
+
|
|
107
|
+
imagePlugin({
|
|
108
|
+
fallbackSvg: async ({ buffer }) => {
|
|
109
|
+
const png = await sharp(buffer).png().toBuffer();
|
|
110
|
+
return png.buffer;
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
102
115
|
### Code
|
|
103
116
|
|
|
104
117
|
Syntax highlighting with [shiki](https://github.com/shikijs/shiki).
|
|
@@ -114,36 +127,36 @@ const processor = unified()
|
|
|
114
127
|
.use(docx, { plugins: [shikiPlugin({ theme: "dark-plus" })] });
|
|
115
128
|
```
|
|
116
129
|
|
|
117
|
-
###
|
|
130
|
+
### Math
|
|
118
131
|
|
|
119
|
-
|
|
132
|
+
Render LaTeX with [MathJax](https://github.com/mathjax/MathJax).
|
|
120
133
|
|
|
121
134
|
```javascript
|
|
122
135
|
import { unified } from "unified";
|
|
123
136
|
import markdown from "remark-parse";
|
|
137
|
+
import math from "remark-math";
|
|
124
138
|
import docx from "remark-docx";
|
|
125
|
-
import {
|
|
139
|
+
import { latexPlugin } from "remark-docx/plugins/latex";
|
|
126
140
|
|
|
127
141
|
const processor = unified()
|
|
128
142
|
.use(markdown)
|
|
129
|
-
.use(
|
|
143
|
+
.use(math)
|
|
144
|
+
.use(docx, { plugins: [latexPlugin()] });
|
|
130
145
|
```
|
|
131
146
|
|
|
132
|
-
###
|
|
147
|
+
### HTML
|
|
133
148
|
|
|
134
|
-
|
|
149
|
+
Transform HTML to markdown.
|
|
135
150
|
|
|
136
151
|
```javascript
|
|
137
152
|
import { unified } from "unified";
|
|
138
153
|
import markdown from "remark-parse";
|
|
139
|
-
import math from "remark-math";
|
|
140
154
|
import docx from "remark-docx";
|
|
141
|
-
import {
|
|
155
|
+
import { htmlPlugin } from "remark-docx/plugins/html";
|
|
142
156
|
|
|
143
157
|
const processor = unified()
|
|
144
158
|
.use(markdown)
|
|
145
|
-
.use(
|
|
146
|
-
.use(docx, { plugins: [latexPlugin()] });
|
|
159
|
+
.use(docx, { plugins: [htmlPlugin()] });
|
|
147
160
|
```
|
|
148
161
|
|
|
149
162
|
## Documentation
|
package/lib/index.cjs
CHANGED
|
@@ -17,7 +17,6 @@ function warnOnce(message, cond = false) {
|
|
|
17
17
|
const ORDERED_LIST_REF = "ordered";
|
|
18
18
|
const TASK_LIST_REF = "task";
|
|
19
19
|
const HYPERLINK_STYLE_ID = "Hyperlink";
|
|
20
|
-
const INLINE_CODE_STYLE_ID = "InlineCode";
|
|
21
20
|
const INDENT = 0.5;
|
|
22
21
|
const createFootnoteRegistry = () => {
|
|
23
22
|
const idToInternalId = new Map();
|
|
@@ -104,8 +103,7 @@ const buildLevels = (formats) => formats.map(({ format, text }, i) => {
|
|
|
104
103
|
},
|
|
105
104
|
};
|
|
106
105
|
});
|
|
107
|
-
const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywords, description, styles, background, thematicBreak = "page", orderedListFormat = defaultOrderedList, } = {}) => {
|
|
108
|
-
var _a;
|
|
106
|
+
const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywords, description, styles, size, margin, background, thematicBreak = "page", orderedListFormat = defaultOrderedList, } = {}) => {
|
|
109
107
|
const definition = mdastUtilDefinitions.definitions(node);
|
|
110
108
|
const numbering = createNumberingRegistry();
|
|
111
109
|
const footnote = createFootnoteRegistry();
|
|
@@ -155,6 +153,30 @@ const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywor
|
|
|
155
153
|
}
|
|
156
154
|
return null;
|
|
157
155
|
};
|
|
156
|
+
let { WIDTH: pageWidth, HEIGHT: pageHeight } = docx.sectionPageSizeDefaults;
|
|
157
|
+
if (size) {
|
|
158
|
+
if (size.width != null) {
|
|
159
|
+
pageWidth = size.width;
|
|
160
|
+
}
|
|
161
|
+
if (size.height != null) {
|
|
162
|
+
pageHeight = size.height;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
let { TOP: marginTop, LEFT: marginLeft, BOTTOM: marginBottom, RIGHT: marginRight, } = docx.sectionMarginDefaults;
|
|
166
|
+
if (margin) {
|
|
167
|
+
if (margin.top != null) {
|
|
168
|
+
marginTop = margin.top;
|
|
169
|
+
}
|
|
170
|
+
if (margin.left != null) {
|
|
171
|
+
marginLeft = margin.left;
|
|
172
|
+
}
|
|
173
|
+
if (margin.bottom != null) {
|
|
174
|
+
marginBottom = margin.bottom;
|
|
175
|
+
}
|
|
176
|
+
if (margin.right != null) {
|
|
177
|
+
marginRight = margin.right;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
158
180
|
const ctx = {
|
|
159
181
|
render(nodes, c) {
|
|
160
182
|
const results = [];
|
|
@@ -166,9 +188,7 @@ const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywor
|
|
|
166
188
|
}
|
|
167
189
|
return results;
|
|
168
190
|
},
|
|
169
|
-
width:
|
|
170
|
-
docx.sectionMarginDefaults.LEFT -
|
|
171
|
-
docx.sectionMarginDefaults.RIGHT,
|
|
191
|
+
width: pageWidth - marginLeft - marginRight,
|
|
172
192
|
deco: {},
|
|
173
193
|
indent: 0,
|
|
174
194
|
thematicBreak,
|
|
@@ -191,28 +211,31 @@ const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywor
|
|
|
191
211
|
}
|
|
192
212
|
}
|
|
193
213
|
const orderedLevels = buildLevels(orderedListFormat);
|
|
214
|
+
const sectionProperties = {
|
|
215
|
+
page: {
|
|
216
|
+
size: { width: pageWidth, height: pageHeight },
|
|
217
|
+
margin: {
|
|
218
|
+
top: marginTop,
|
|
219
|
+
left: marginLeft,
|
|
220
|
+
bottom: marginBottom,
|
|
221
|
+
right: marginRight,
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
};
|
|
194
225
|
const doc = new docx.Document({
|
|
195
226
|
title,
|
|
196
227
|
subject,
|
|
197
228
|
creator,
|
|
198
229
|
keywords,
|
|
199
230
|
description,
|
|
200
|
-
styles:
|
|
201
|
-
...styles,
|
|
202
|
-
characterStyles: [
|
|
203
|
-
...((_a = styles === null || styles === void 0 ? void 0 : styles.characterStyles) !== null && _a !== void 0 ? _a : []),
|
|
204
|
-
{
|
|
205
|
-
id: INLINE_CODE_STYLE_ID,
|
|
206
|
-
run: {
|
|
207
|
-
highlight: "lightGray",
|
|
208
|
-
},
|
|
209
|
-
},
|
|
210
|
-
],
|
|
211
|
-
},
|
|
231
|
+
styles: styles,
|
|
212
232
|
background,
|
|
213
233
|
sections: sections
|
|
214
234
|
.filter((s) => s.length)
|
|
215
|
-
.map((s) => ({
|
|
235
|
+
.map((s) => ({
|
|
236
|
+
properties: sectionProperties,
|
|
237
|
+
children: s,
|
|
238
|
+
})),
|
|
216
239
|
footnotes: footnote.toConfig(),
|
|
217
240
|
numbering: {
|
|
218
241
|
config: [
|
|
@@ -390,6 +413,9 @@ const buildText = ({ value }, { deco }) => {
|
|
|
390
413
|
italics: deco.italic,
|
|
391
414
|
strike: deco.strike,
|
|
392
415
|
};
|
|
416
|
+
if (deco.inlineCode) {
|
|
417
|
+
options.highlight = "lightGray";
|
|
418
|
+
}
|
|
393
419
|
if (deco.link) {
|
|
394
420
|
// https://docx.js.org/#/usage/hyperlinks?id=styling-hyperlinks
|
|
395
421
|
options.style = HYPERLINK_STYLE_ID;
|
|
@@ -414,10 +440,10 @@ const buildDelete = ({ children }, ctx) => {
|
|
|
414
440
|
deco: { ...ctx.deco, strike: true },
|
|
415
441
|
});
|
|
416
442
|
};
|
|
417
|
-
const buildInlineCode = ({ value }) => {
|
|
418
|
-
return
|
|
419
|
-
|
|
420
|
-
|
|
443
|
+
const buildInlineCode = ({ value }, ctx) => {
|
|
444
|
+
return buildText({ value }, {
|
|
445
|
+
...ctx,
|
|
446
|
+
deco: { ...ctx.deco, inlineCode: true },
|
|
421
447
|
});
|
|
422
448
|
};
|
|
423
449
|
const buildBreak = () => {
|
package/lib/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/src/utils.ts","../src/src/mdast-util-to-docx.ts","../src/src/plugin.ts"],"sourcesContent":["const alreadyWarned: { [message: string]: boolean } = {};\n\n/**\n * @internal\n */\nexport function warnOnce(message: string, cond: boolean = false): void {\n if (!cond && !alreadyWarned[message]) {\n alreadyWarned[message] = true;\n console.warn(message);\n }\n}\n","import {\n convertInchesToTwip,\n Packer,\n Document,\n Paragraph,\n Table,\n TableRow,\n TableCell,\n TextRun,\n ExternalHyperlink,\n HeadingLevel,\n LevelFormat,\n AlignmentType,\n type ILevelsOptions,\n FootnoteReferenceRun,\n CheckBox,\n type IPropertiesOptions,\n sectionPageSizeDefaults,\n sectionMarginDefaults,\n type IRunOptions,\n type IParagraphOptions,\n PageBreak,\n} from \"docx\";\nimport type * as mdast from \"mdast\";\nimport { warnOnce } from \"./utils\";\nimport { definitions } from \"mdast-util-definitions\";\nimport type {\n Context,\n DocxChild,\n DocxContent,\n FootnoteRegistry,\n ListContext,\n NodeBuilder,\n NodeBuilders,\n RemarkDocxPlugin,\n ThematicBreakType,\n Writeable,\n} from \"./types\";\n\nconst ORDERED_LIST_REF = \"ordered\";\nconst TASK_LIST_REF = \"task\";\nconst HYPERLINK_STYLE_ID = \"Hyperlink\";\nconst INLINE_CODE_STYLE_ID = \"InlineCode\";\nconst INDENT = 0.5;\n\nconst createFootnoteRegistry = (): FootnoteRegistry => {\n const idToInternalId = new Map<string, number>();\n const defs = new Map<number, Paragraph[]>();\n\n const getId = (id: string): number => {\n let internalId = idToInternalId.get(id);\n if (internalId == null) {\n idToInternalId.set(id, (internalId = idToInternalId.size + 1));\n }\n return internalId;\n };\n\n return {\n ref: (id) => {\n return getId(id);\n },\n def: (id, def) => {\n const internalId = getId(id);\n defs.set(internalId, def);\n },\n toConfig: () => {\n return defs.entries().reduce(\n (acc, [key, def]) => {\n acc[key] = { children: def };\n return acc;\n },\n {} as {\n [key: string]: { children: Paragraph[] };\n },\n );\n },\n };\n};\n\ntype ListFormat = {\n format: keyof typeof LevelFormat;\n text: string;\n};\n\ntype NumberingRegistry = {\n createId: () => string;\n getIds: () => string[];\n};\nconst createNumberingRegistry = (): NumberingRegistry => {\n let counter = 1;\n\n return {\n createId: () => {\n return `${ORDERED_LIST_REF}-${counter++}`;\n },\n getIds: () => {\n return Array.from(\n { length: counter },\n (_, i) => `${ORDERED_LIST_REF}-${i}`,\n );\n },\n };\n};\n\nconst composeBuilders = (\n pluginsBuilders: readonly NodeBuilders[],\n defaultBuilders: NodeBuilders,\n): NodeBuilders => {\n return pluginsBuilders.reduceRight<NodeBuilders>((acc, p) => {\n type Key = keyof typeof p;\n for (const [k, cur] of Object.entries(p)) {\n const prev = acc[k as Key];\n acc[k as Key] = (\n prev\n ? (n, c) => {\n const r = cur(n as any, c);\n if (r) {\n return r;\n }\n return prev(n as any, c);\n }\n : cur\n ) as NodeBuilder<any>;\n }\n return acc;\n }, defaultBuilders);\n};\nconst defaultTaskList: ListFormat[] = [\n { text: \"\", format: \"NONE\" },\n { text: \"\", format: \"NONE\" },\n { text: \"\", format: \"NONE\" },\n { text: \"\", format: \"NONE\" },\n { text: \"\", format: \"NONE\" },\n { text: \"\", format: \"NONE\" },\n];\n\nconst defaultOrderedList: ListFormat[] = [\n { text: \"%1.\", format: \"DECIMAL\" },\n { text: \"%2.\", format: \"DECIMAL\" },\n { text: \"%3.\", format: \"DECIMAL\" },\n { text: \"%4.\", format: \"DECIMAL\" },\n { text: \"%5.\", format: \"DECIMAL\" },\n { text: \"%6.\", format: \"DECIMAL\" },\n];\n\nconst buildLevels = (formats: readonly ListFormat[]): ILevelsOptions[] =>\n formats.map(({ format, text }, i) => {\n return {\n level: i,\n format: LevelFormat[format],\n text: text,\n alignment: AlignmentType.START,\n style:\n i === 0\n ? undefined\n : {\n paragraph: {\n indent: { start: convertInchesToTwip(INDENT * i) },\n },\n },\n };\n });\n\nexport interface DocxOptions extends Pick<\n IPropertiesOptions,\n | \"title\"\n | \"subject\"\n | \"creator\"\n | \"keywords\"\n | \"description\"\n | \"styles\"\n | \"background\"\n> {\n /**\n * An option to override the text format of ordered list.\n * See https://docx.js.org/#/usage/numbering?id=level-options for more details.\n * @default {@link defaultOrderedList}\n */\n orderedListFormat?: ListFormat[];\n /**\n * An option to select how thematicBreak works. \"page\" is Page Break. \"section\" is Section Break.\n * @default \"page\"\n */\n thematicBreak?: ThematicBreakType;\n /**\n * Plugins to customize how mdast nodes are compiled.\n */\n plugins?: RemarkDocxPlugin[];\n}\n\nexport const mdastToDocx = async (\n node: mdast.Root,\n {\n plugins = [],\n title,\n subject,\n creator,\n keywords,\n description,\n styles,\n background,\n thematicBreak = \"page\",\n orderedListFormat = defaultOrderedList,\n }: DocxOptions = {},\n): Promise<ArrayBuffer> => {\n const definition = definitions(node);\n\n const numbering = createNumberingRegistry();\n const footnote = createFootnoteRegistry();\n\n const pluginCtx = { root: node, definition };\n\n const builders = composeBuilders(\n await Promise.all(plugins.map((p) => p(pluginCtx))),\n {\n paragraph: buildParagraph,\n heading: buildHeading,\n thematicBreak: buildThematicBreak,\n blockquote: buildBlockquote,\n list: buildList,\n listItem: buildListItem,\n table: buildTable,\n tableRow: noop,\n tableCell: noop,\n html: fallbackText,\n code: fallbackText,\n definition: noop,\n footnoteDefinition: buildFootnoteDefinition,\n text: buildText,\n emphasis: buildEmphasis,\n strong: buildStrong,\n delete: buildDelete,\n inlineCode: buildInlineCode,\n break: buildBreak,\n link: buildLink,\n linkReference: buildLinkReference,\n // image: warnImage,\n // imageReference: warnImage,\n footnoteReference: buildFootnoteReference,\n math: fallbackText,\n inlineMath: fallbackText,\n },\n );\n\n const renderNode = (\n node: mdast.RootContent,\n c: Context,\n ): DocxContent[] | null => {\n const builder = builders[node.type];\n if (!builder) {\n warnOnce(`${node.type} node is not supported without plugins.`);\n return null;\n }\n const r = builder(node as any, c);\n if (r) {\n if (Array.isArray(r)) {\n return r;\n } else {\n return [r];\n }\n }\n return null;\n };\n\n const ctx: Context = {\n render(nodes, c) {\n const results: DocxContent[] = [];\n for (const node of nodes) {\n const r = renderNode(node, c ?? this);\n if (r) {\n results.push(...r);\n }\n }\n return results;\n },\n width:\n sectionPageSizeDefaults.WIDTH -\n sectionMarginDefaults.LEFT -\n sectionMarginDefaults.RIGHT,\n deco: {},\n indent: 0,\n thematicBreak,\n definition: definition,\n footnote,\n orderedId: numbering.createId,\n };\n\n const sections: DocxContent[][] = [[]];\n for (const n of node.children) {\n const r = renderNode(n, ctx);\n if (r) {\n if (!r.length) {\n // thematicBreak\n sections.push([]);\n } else {\n const lastSection = sections[sections.length - 1]!;\n lastSection.push(...r);\n }\n }\n }\n\n const orderedLevels = buildLevels(orderedListFormat);\n\n const doc = new Document({\n title,\n subject,\n creator,\n keywords,\n description,\n styles: {\n ...styles,\n characterStyles: [\n ...(styles?.characterStyles ?? []),\n {\n id: INLINE_CODE_STYLE_ID,\n run: {\n highlight: \"lightGray\",\n },\n },\n ],\n },\n background,\n sections: sections\n .filter((s) => s.length)\n .map((s) => ({ children: s as DocxChild[] })),\n footnotes: footnote.toConfig(),\n numbering: {\n config: [\n ...numbering.getIds().map((ref) => ({\n reference: ref,\n levels: orderedLevels,\n })),\n {\n reference: TASK_LIST_REF,\n levels: buildLevels(defaultTaskList),\n },\n ],\n },\n });\n\n return Packer.toArrayBuffer(doc);\n};\n\nconst buildParagraph: NodeBuilder<\"paragraph\"> = ({ children }, ctx) => {\n const list = ctx.list;\n const nodes = ctx.render(children);\n\n const options: Writeable<IParagraphOptions> = {\n children: nodes,\n };\n\n if (ctx.indent > 0) {\n options.indent = {\n start: convertInchesToTwip(INDENT * ctx.indent),\n };\n }\n\n if (list) {\n const { level, meta } = list;\n if (meta.type === \"task\") {\n nodes.unshift(\n new CheckBox({\n checked: meta.checked,\n checkedState: { value: \"2611\" },\n uncheckedState: { value: \"2610\" },\n }),\n );\n options.numbering = {\n reference: TASK_LIST_REF,\n level,\n };\n } else if (meta.type === \"ordered\") {\n options.numbering = {\n reference: meta.reference,\n level,\n };\n } else {\n options.bullet = {\n level,\n };\n }\n }\n\n return new Paragraph(options);\n};\n\nconst buildHeading: NodeBuilder<\"heading\"> = ({ children, depth }, ctx) => {\n let headingLevel: (typeof HeadingLevel)[keyof typeof HeadingLevel];\n switch (depth) {\n case 1:\n headingLevel = HeadingLevel.TITLE;\n break;\n case 2:\n headingLevel = HeadingLevel.HEADING_1;\n break;\n case 3:\n headingLevel = HeadingLevel.HEADING_2;\n break;\n case 4:\n headingLevel = HeadingLevel.HEADING_3;\n break;\n case 5:\n headingLevel = HeadingLevel.HEADING_4;\n break;\n case 6:\n headingLevel = HeadingLevel.HEADING_5;\n break;\n }\n const nodes = ctx.render(children);\n return new Paragraph({\n heading: headingLevel,\n children: nodes,\n });\n};\n\nconst buildThematicBreak: NodeBuilder<\"thematicBreak\"> = (_, ctx) => {\n if (ctx.thematicBreak === \"section\") {\n // Returning empty array at toplevel means section insertion.\n return [];\n }\n return new Paragraph({ children: [new PageBreak()] });\n};\n\nconst buildBlockquote: NodeBuilder<\"blockquote\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n indent: ctx.indent + 1,\n });\n};\n\nconst buildList: NodeBuilder<\"list\"> = ({ children, ordered }, ctx) => {\n const parentList = ctx.list;\n\n let meta: ListContext[\"meta\"];\n if (ordered) {\n meta = {\n type: \"ordered\",\n reference:\n parentList && parentList.meta.type === \"ordered\"\n ? parentList.meta.reference\n : ctx.orderedId(),\n };\n } else {\n meta = { type: \"bullet\" };\n }\n\n return ctx.render(children, {\n ...ctx,\n list: {\n level: !parentList ? 0 : parentList.level + 1,\n meta,\n },\n });\n};\n\nconst buildListItem: NodeBuilder<\"listItem\"> = ({ children, checked }, ctx) => {\n let list = ctx.list;\n if (list) {\n // listItem must be the child of list\n if (checked != null) {\n list = {\n level: list.level,\n meta: {\n type: \"task\",\n checked,\n },\n };\n }\n }\n return ctx.render(children, {\n ...ctx,\n list,\n });\n};\n\nconst buildTable: NodeBuilder<\"table\"> = ({ children, align }, ctx) => {\n const cellAligns:\n | (typeof AlignmentType)[keyof typeof AlignmentType][]\n | undefined = align?.map((a) => {\n switch (a) {\n case \"left\":\n return AlignmentType.LEFT;\n case \"right\":\n return AlignmentType.RIGHT;\n case \"center\":\n return AlignmentType.CENTER;\n default:\n return AlignmentType.LEFT;\n }\n });\n\n const columnLength = children[0]!.children.length;\n const columnWidth = ctx.width / columnLength;\n\n return new Table({\n columnWidths: Array.from({ length: columnLength }).map(() => columnWidth),\n rows: children.map((r) => {\n return new TableRow({\n children: r.children.map((c, i) => {\n return new TableCell({\n width: { size: columnWidth, type: \"dxa\" },\n children: [\n new Paragraph({\n alignment: cellAligns?.[i],\n children: ctx.render(c.children),\n }),\n ],\n });\n }),\n });\n }),\n });\n};\n\nconst buildText: NodeBuilder<\"text\"> = ({ value }, { deco }) => {\n const options: Writeable<IRunOptions> = {\n text: value,\n bold: deco.bold,\n italics: deco.italic,\n strike: deco.strike,\n };\n if (deco.link) {\n // https://docx.js.org/#/usage/hyperlinks?id=styling-hyperlinks\n options.style = HYPERLINK_STYLE_ID;\n }\n return new TextRun(options);\n};\n\nconst buildEmphasis: NodeBuilder<\"emphasis\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, italic: true },\n });\n};\n\nconst buildStrong: NodeBuilder<\"strong\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, bold: true },\n });\n};\n\nconst buildDelete: NodeBuilder<\"delete\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, strike: true },\n });\n};\n\nconst buildInlineCode: NodeBuilder<\"inlineCode\"> = ({ value }) => {\n return new TextRun({\n text: value,\n style: INLINE_CODE_STYLE_ID,\n });\n};\n\nconst buildBreak: NodeBuilder<\"break\"> = () => {\n return new TextRun({ text: \"\", break: 1 });\n};\n\nconst buildLink: NodeBuilder<\"link\"> = ({ children, url }, ctx) => {\n const nodes = ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, link: true },\n });\n return new ExternalHyperlink({\n link: url,\n children: nodes,\n });\n};\n\nconst buildLinkReference: NodeBuilder<\"linkReference\"> = (\n { children, identifier },\n ctx,\n) => {\n const def = ctx.definition(identifier);\n if (def == null) {\n return ctx.render(children);\n }\n return buildLink({ type: \"link\", children, url: def.url }, ctx);\n};\n\nconst buildFootnoteDefinition: NodeBuilder<\"footnoteDefinition\"> = (\n { children, identifier },\n ctx,\n) => {\n ctx.footnote.def(\n identifier,\n ctx.render(children).filter((c) => c instanceof Paragraph),\n );\n return null;\n};\n\nconst buildFootnoteReference: NodeBuilder<\"footnoteReference\"> = (\n { identifier },\n ctx,\n) => {\n return new FootnoteReferenceRun(ctx.footnote.ref(identifier));\n};\n\nconst noop = () => {\n return null;\n};\n\nconst fallbackText = (node: { type: string; value: string }, ctx: Context) => {\n warnOnce(\n `${node.type} node is not supported without plugins, falling back to text.`,\n );\n return buildText({ type: \"text\", value: node.value }, ctx);\n};\n","import type { Plugin } from \"unified\";\nimport type { Root } from \"mdast\";\nimport { mdastToDocx, type DocxOptions } from \"./mdast-util-to-docx\";\n\nexport type { DocxOptions };\n\ndeclare module \"unified\" {\n interface CompileResultMap {\n docx: Promise<ArrayBuffer>;\n }\n}\n\nconst plugin: Plugin<[DocxOptions?], Root, Promise<ArrayBuffer>> = function (\n opts,\n) {\n this.compiler = (node) => {\n return mdastToDocx(node as Root, opts);\n };\n};\nexport default plugin;\n"],"names":["LevelFormat","AlignmentType","convertInchesToTwip","definitions","sectionPageSizeDefaults","sectionMarginDefaults","Document","Packer","CheckBox","Paragraph","HeadingLevel","PageBreak","Table","TableRow","TableCell","TextRun","ExternalHyperlink","FootnoteReferenceRun"],"mappings":";;;;;AAAA,MAAM,aAAa,GAAmC,EAAE;AAExD;;AAEG;SACa,QAAQ,CAAC,OAAe,EAAE,OAAgB,KAAK,EAAA;IAC7D,IAAI,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE;AACpC,QAAA,aAAa,CAAC,OAAO,CAAC,GAAG,IAAI;AAC7B,QAAA,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;IACvB;AACF;;AC6BA,MAAM,gBAAgB,GAAG,SAAS;AAClC,MAAM,aAAa,GAAG,MAAM;AAC5B,MAAM,kBAAkB,GAAG,WAAW;AACtC,M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,CAAC;AAED,MAAM,uBAAuB,GAAsC,CACjE,EAAE,QAAQ,EAAE,UAAU,EAAE,EACxB,GAAG,KACD;IACF,GAAG,CAAC,QAAQ,CAAC,GAAG,CACd,UAAU,EACV,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,YAAYP,cAAS,CAAC,CAC3D;AACD,IAAA,OAAO,IAAI;AACb,CAAC;AAED,MAAM,sBAAsB,GAAqC,CAC/D,EAAE,UAAU,EAAE,EACd,GAAG,KACD;AACF,IAAA,OAAO,IAAIQ,yBAAoB,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAC/D,CAAC;AAED,MAAM,IAAI,GAAG,MAAK;AAChB,IAAA,OAAO,IAAI;AACb,CAAC;AAED,MAAM,YAAY,GAAG,CAAC,IAAqC,EAAE,GAAY,KAAI;AAC3E,IAAA,QAAQ,CACN,CAAA,EAAG,IAAI,CAAC,IAAI,CAAA,6DAAA,CAA+D,CAC5E;AACD,IAAA,OAAO,SAAS,CAAC,EAAgB,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,GAAG,CAAC;AAC5D,CAAC;;ACrlBD,MAAM,MAAM,GAAuD,UACjE,IAAI,EAAA;AAEJ,IAAA,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,KAAI;AACvB,QAAA,OAAO,WAAW,CAAC,IAAY,EAAE,IAAI,CAAC;AACxC,IAAA,CAAC;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/src/utils.ts","../src/src/mdast-util-to-docx.ts","../src/src/plugin.ts"],"sourcesContent":["const alreadyWarned: { [message: string]: boolean } = {};\n\n/**\n * @internal\n */\nexport function warnOnce(message: string, cond: boolean = false): void {\n if (!cond && !alreadyWarned[message]) {\n alreadyWarned[message] = true;\n console.warn(message);\n }\n}\n","import {\n convertInchesToTwip,\n Packer,\n Document,\n Paragraph,\n Table,\n TableRow,\n TableCell,\n TextRun,\n ExternalHyperlink,\n HeadingLevel,\n LevelFormat,\n AlignmentType,\n type ILevelsOptions,\n FootnoteReferenceRun,\n CheckBox,\n type IPropertiesOptions,\n sectionPageSizeDefaults,\n sectionMarginDefaults,\n type IRunOptions,\n type IParagraphOptions,\n PageBreak,\n type ISectionPropertiesOptions,\n} from \"docx\";\nimport type * as mdast from \"mdast\";\nimport { warnOnce } from \"./utils\";\nimport { definitions } from \"mdast-util-definitions\";\nimport type {\n Context,\n DocxChild,\n DocxContent,\n FootnoteRegistry,\n ListContext,\n NodeBuilder,\n NodeBuilders,\n RemarkDocxPlugin,\n ThematicBreakType,\n Writeable,\n} from \"./types\";\n\nconst ORDERED_LIST_REF = \"ordered\";\nconst TASK_LIST_REF = \"task\";\nconst HYPERLINK_STYLE_ID = \"Hyperlink\";\nconst INDENT = 0.5;\n\nconst createFootnoteRegistry = (): FootnoteRegistry => {\n const idToInternalId = new Map<string, number>();\n const defs = new Map<number, Paragraph[]>();\n\n const getId = (id: string): number => {\n let internalId = idToInternalId.get(id);\n if (internalId == null) {\n idToInternalId.set(id, (internalId = idToInternalId.size + 1));\n }\n return internalId;\n };\n\n return {\n ref: (id) => {\n return getId(id);\n },\n def: (id, def) => {\n const internalId = getId(id);\n defs.set(internalId, def);\n },\n toConfig: () => {\n return defs.entries().reduce(\n (acc, [key, def]) => {\n acc[key] = { children: def };\n return acc;\n },\n {} as {\n [key: string]: { children: Paragraph[] };\n },\n );\n },\n };\n};\n\ntype ListFormat = {\n format: keyof typeof LevelFormat;\n text: string;\n};\n\ntype NumberingRegistry = {\n createId: () => string;\n getIds: () => string[];\n};\nconst createNumberingRegistry = (): NumberingRegistry => {\n let counter = 1;\n\n return {\n createId: () => {\n return `${ORDERED_LIST_REF}-${counter++}`;\n },\n getIds: () => {\n return Array.from(\n { length: counter },\n (_, i) => `${ORDERED_LIST_REF}-${i}`,\n );\n },\n };\n};\n\nconst composeBuilders = (\n pluginsBuilders: readonly NodeBuilders[],\n defaultBuilders: NodeBuilders,\n): NodeBuilders => {\n return pluginsBuilders.reduceRight<NodeBuilders>((acc, p) => {\n type Key = keyof typeof p;\n for (const [k, cur] of Object.entries(p)) {\n const prev = acc[k as Key];\n acc[k as Key] = (\n prev\n ? (n, c) => {\n const r = cur(n as any, c);\n if (r) {\n return r;\n }\n return prev(n as any, c);\n }\n : cur\n ) as NodeBuilder<any>;\n }\n return acc;\n }, defaultBuilders);\n};\nconst defaultTaskList: ListFormat[] = [\n { text: \"\", format: \"NONE\" },\n { text: \"\", format: \"NONE\" },\n { text: \"\", format: \"NONE\" },\n { text: \"\", format: \"NONE\" },\n { text: \"\", format: \"NONE\" },\n { text: \"\", format: \"NONE\" },\n];\n\nconst defaultOrderedList: ListFormat[] = [\n { text: \"%1.\", format: \"DECIMAL\" },\n { text: \"%2.\", format: \"DECIMAL\" },\n { text: \"%3.\", format: \"DECIMAL\" },\n { text: \"%4.\", format: \"DECIMAL\" },\n { text: \"%5.\", format: \"DECIMAL\" },\n { text: \"%6.\", format: \"DECIMAL\" },\n];\n\nconst buildLevels = (formats: readonly ListFormat[]): ILevelsOptions[] =>\n formats.map(({ format, text }, i) => {\n return {\n level: i,\n format: LevelFormat[format],\n text: text,\n alignment: AlignmentType.START,\n style:\n i === 0\n ? undefined\n : {\n paragraph: {\n indent: { start: convertInchesToTwip(INDENT * i) },\n },\n },\n };\n });\n\nexport interface DocxOptions extends Pick<\n IPropertiesOptions,\n | \"title\"\n | \"subject\"\n | \"creator\"\n | \"keywords\"\n | \"description\"\n | \"styles\"\n | \"background\"\n> {\n /**\n * Page size defined in twip (1 twip == 1/1440 inch).\n * @default A4 ({@link sectionPageSizeDefaults})\n */\n size?: { width?: number; height?: number };\n /**\n * Page margin defined in twip (1 twip == 1/1440 inch).\n * @default 1 inch ({@link sectionMarginDefaults})\n */\n margin?: { top?: number; left?: number; bottom?: number; right?: number };\n /**\n * An option to override the text format of ordered list.\n * See https://docx.js.org/#/usage/numbering?id=level-options for more details.\n * @default {@link defaultOrderedList}\n */\n orderedListFormat?: ListFormat[];\n /**\n * An option to select how thematicBreak works. \"page\" is Page Break. \"section\" is Section Break.\n * @default \"page\"\n */\n thematicBreak?: ThematicBreakType;\n /**\n * Plugins to customize how mdast nodes are compiled.\n */\n plugins?: RemarkDocxPlugin[];\n}\n\nexport const mdastToDocx = async (\n node: mdast.Root,\n {\n plugins = [],\n title,\n subject,\n creator,\n keywords,\n description,\n styles,\n size,\n margin,\n background,\n thematicBreak = \"page\",\n orderedListFormat = defaultOrderedList,\n }: DocxOptions = {},\n): Promise<ArrayBuffer> => {\n const definition = definitions(node);\n\n const numbering = createNumberingRegistry();\n const footnote = createFootnoteRegistry();\n\n const pluginCtx = { root: node, definition };\n\n const builders = composeBuilders(\n await Promise.all(plugins.map((p) => p(pluginCtx))),\n {\n paragraph: buildParagraph,\n heading: buildHeading,\n thematicBreak: buildThematicBreak,\n blockquote: buildBlockquote,\n list: buildList,\n listItem: buildListItem,\n table: buildTable,\n tableRow: noop,\n tableCell: noop,\n html: fallbackText,\n code: fallbackText,\n definition: noop,\n footnoteDefinition: buildFootnoteDefinition,\n text: buildText,\n emphasis: buildEmphasis,\n strong: buildStrong,\n delete: buildDelete,\n inlineCode: buildInlineCode,\n break: buildBreak,\n link: buildLink,\n linkReference: buildLinkReference,\n // image: warnImage,\n // imageReference: warnImage,\n footnoteReference: buildFootnoteReference,\n math: fallbackText,\n inlineMath: fallbackText,\n },\n );\n\n const renderNode = (\n node: mdast.RootContent,\n c: Context,\n ): DocxContent[] | null => {\n const builder = builders[node.type];\n if (!builder) {\n warnOnce(`${node.type} node is not supported without plugins.`);\n return null;\n }\n const r = builder(node as any, c);\n if (r) {\n if (Array.isArray(r)) {\n return r;\n } else {\n return [r];\n }\n }\n return null;\n };\n\n let { WIDTH: pageWidth, HEIGHT: pageHeight } = sectionPageSizeDefaults;\n if (size) {\n if (size.width != null) {\n pageWidth = size.width;\n }\n if (size.height != null) {\n pageHeight = size.height;\n }\n }\n let {\n TOP: marginTop,\n LEFT: marginLeft,\n BOTTOM: marginBottom,\n RIGHT: marginRight,\n } = sectionMarginDefaults;\n if (margin) {\n if (margin.top != null) {\n marginTop = margin.top;\n }\n if (margin.left != null) {\n marginLeft = margin.left;\n }\n if (margin.bottom != null) {\n marginBottom = margin.bottom;\n }\n if (margin.right != null) {\n marginRight = margin.right;\n }\n }\n\n const ctx: Context = {\n render(nodes, c) {\n const results: DocxContent[] = [];\n for (const node of nodes) {\n const r = renderNode(node, c ?? this);\n if (r) {\n results.push(...r);\n }\n }\n return results;\n },\n width: pageWidth - marginLeft - marginRight,\n deco: {},\n indent: 0,\n thematicBreak,\n definition: definition,\n footnote,\n orderedId: numbering.createId,\n };\n\n const sections: DocxContent[][] = [[]];\n for (const n of node.children) {\n const r = renderNode(n, ctx);\n if (r) {\n if (!r.length) {\n // thematicBreak\n sections.push([]);\n } else {\n const lastSection = sections[sections.length - 1]!;\n lastSection.push(...r);\n }\n }\n }\n\n const orderedLevels = buildLevels(orderedListFormat);\n\n const sectionProperties: ISectionPropertiesOptions = {\n page: {\n size: { width: pageWidth, height: pageHeight },\n margin: {\n top: marginTop,\n left: marginLeft,\n bottom: marginBottom,\n right: marginRight,\n },\n },\n };\n\n const doc = new Document({\n title,\n subject,\n creator,\n keywords,\n description,\n styles: styles,\n background,\n sections: sections\n .filter((s) => s.length)\n .map((s) => ({\n properties: sectionProperties,\n children: s as DocxChild[],\n })),\n footnotes: footnote.toConfig(),\n numbering: {\n config: [\n ...numbering.getIds().map((ref) => ({\n reference: ref,\n levels: orderedLevels,\n })),\n {\n reference: TASK_LIST_REF,\n levels: buildLevels(defaultTaskList),\n },\n ],\n },\n });\n\n return Packer.toArrayBuffer(doc);\n};\n\nconst buildParagraph: NodeBuilder<\"paragraph\"> = ({ children }, ctx) => {\n const list = ctx.list;\n const nodes = ctx.render(children);\n\n const options: Writeable<IParagraphOptions> = {\n children: nodes,\n };\n\n if (ctx.indent > 0) {\n options.indent = {\n start: convertInchesToTwip(INDENT * ctx.indent),\n };\n }\n\n if (list) {\n const { level, meta } = list;\n if (meta.type === \"task\") {\n nodes.unshift(\n new CheckBox({\n checked: meta.checked,\n checkedState: { value: \"2611\" },\n uncheckedState: { value: \"2610\" },\n }),\n );\n options.numbering = {\n reference: TASK_LIST_REF,\n level,\n };\n } else if (meta.type === \"ordered\") {\n options.numbering = {\n reference: meta.reference,\n level,\n };\n } else {\n options.bullet = {\n level,\n };\n }\n }\n\n return new Paragraph(options);\n};\n\nconst buildHeading: NodeBuilder<\"heading\"> = ({ children, depth }, ctx) => {\n let headingLevel: (typeof HeadingLevel)[keyof typeof HeadingLevel];\n switch (depth) {\n case 1:\n headingLevel = HeadingLevel.TITLE;\n break;\n case 2:\n headingLevel = HeadingLevel.HEADING_1;\n break;\n case 3:\n headingLevel = HeadingLevel.HEADING_2;\n break;\n case 4:\n headingLevel = HeadingLevel.HEADING_3;\n break;\n case 5:\n headingLevel = HeadingLevel.HEADING_4;\n break;\n case 6:\n headingLevel = HeadingLevel.HEADING_5;\n break;\n }\n const nodes = ctx.render(children);\n return new Paragraph({\n heading: headingLevel,\n children: nodes,\n });\n};\n\nconst buildThematicBreak: NodeBuilder<\"thematicBreak\"> = (_, ctx) => {\n if (ctx.thematicBreak === \"section\") {\n // Returning empty array at toplevel means section insertion.\n return [];\n }\n return new Paragraph({ children: [new PageBreak()] });\n};\n\nconst buildBlockquote: NodeBuilder<\"blockquote\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n indent: ctx.indent + 1,\n });\n};\n\nconst buildList: NodeBuilder<\"list\"> = ({ children, ordered }, ctx) => {\n const parentList = ctx.list;\n\n let meta: ListContext[\"meta\"];\n if (ordered) {\n meta = {\n type: \"ordered\",\n reference:\n parentList && parentList.meta.type === \"ordered\"\n ? parentList.meta.reference\n : ctx.orderedId(),\n };\n } else {\n meta = { type: \"bullet\" };\n }\n\n return ctx.render(children, {\n ...ctx,\n list: {\n level: !parentList ? 0 : parentList.level + 1,\n meta,\n },\n });\n};\n\nconst buildListItem: NodeBuilder<\"listItem\"> = ({ children, checked }, ctx) => {\n let list = ctx.list;\n if (list) {\n // listItem must be the child of list\n if (checked != null) {\n list = {\n level: list.level,\n meta: {\n type: \"task\",\n checked,\n },\n };\n }\n }\n return ctx.render(children, {\n ...ctx,\n list,\n });\n};\n\nconst buildTable: NodeBuilder<\"table\"> = ({ children, align }, ctx) => {\n const cellAligns:\n | (typeof AlignmentType)[keyof typeof AlignmentType][]\n | undefined = align?.map((a) => {\n switch (a) {\n case \"left\":\n return AlignmentType.LEFT;\n case \"right\":\n return AlignmentType.RIGHT;\n case \"center\":\n return AlignmentType.CENTER;\n default:\n return AlignmentType.LEFT;\n }\n });\n\n const columnLength = children[0]!.children.length;\n const columnWidth = ctx.width / columnLength;\n\n return new Table({\n columnWidths: Array.from({ length: columnLength }).map(() => columnWidth),\n rows: children.map((r) => {\n return new TableRow({\n children: r.children.map((c, i) => {\n return new TableCell({\n width: { size: columnWidth, type: \"dxa\" },\n children: [\n new Paragraph({\n alignment: cellAligns?.[i],\n children: ctx.render(c.children),\n }),\n ],\n });\n }),\n });\n }),\n });\n};\n\nconst buildText: NodeBuilder<\"text\"> = ({ value }, { deco }) => {\n const options: Writeable<IRunOptions> = {\n text: value,\n bold: deco.bold,\n italics: deco.italic,\n strike: deco.strike,\n };\n if (deco.inlineCode) {\n options.highlight = \"lightGray\";\n }\n if (deco.link) {\n // https://docx.js.org/#/usage/hyperlinks?id=styling-hyperlinks\n options.style = HYPERLINK_STYLE_ID;\n }\n return new TextRun(options);\n};\n\nconst buildEmphasis: NodeBuilder<\"emphasis\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, italic: true },\n });\n};\n\nconst buildStrong: NodeBuilder<\"strong\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, bold: true },\n });\n};\n\nconst buildDelete: NodeBuilder<\"delete\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, strike: true },\n });\n};\n\nconst buildInlineCode: NodeBuilder<\"inlineCode\"> = ({ value }, ctx) => {\n return buildText(\n { type: \"text\", value },\n {\n ...ctx,\n deco: { ...ctx.deco, inlineCode: true },\n },\n );\n};\n\nconst buildBreak: NodeBuilder<\"break\"> = () => {\n return new TextRun({ text: \"\", break: 1 });\n};\n\nconst buildLink: NodeBuilder<\"link\"> = ({ children, url }, ctx) => {\n const nodes = ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, link: true },\n });\n return new ExternalHyperlink({\n link: url,\n children: nodes,\n });\n};\n\nconst buildLinkReference: NodeBuilder<\"linkReference\"> = (\n { children, identifier },\n ctx,\n) => {\n const def = ctx.definition(identifier);\n if (def == null) {\n return ctx.render(children);\n }\n return buildLink({ type: \"link\", children, url: def.url }, ctx);\n};\n\nconst buildFootnoteDefinition: NodeBuilder<\"footnoteDefinition\"> = (\n { children, identifier },\n ctx,\n) => {\n ctx.footnote.def(\n identifier,\n ctx.render(children).filter((c) => c instanceof Paragraph),\n );\n return null;\n};\n\nconst buildFootnoteReference: NodeBuilder<\"footnoteReference\"> = (\n { identifier },\n ctx,\n) => {\n return new FootnoteReferenceRun(ctx.footnote.ref(identifier));\n};\n\nconst noop = () => {\n return null;\n};\n\nconst fallbackText = (node: { type: string; value: string }, ctx: Context) => {\n warnOnce(\n `${node.type} node is not supported without plugins, falling back to text.`,\n );\n return buildText({ type: \"text\", value: node.value }, ctx);\n};\n","import type { Plugin } from \"unified\";\nimport type { Root } from \"mdast\";\nimport { mdastToDocx, type DocxOptions } from \"./mdast-util-to-docx\";\n\nexport type { DocxOptions };\n\ndeclare module \"unified\" {\n interface CompileResultMap {\n docx: Promise<ArrayBuffer>;\n }\n}\n\nconst plugin: Plugin<[DocxOptions?], Root, Promise<ArrayBuffer>> = function (\n opts,\n) {\n this.compiler = (node) => {\n return mdastToDocx(node as Root, opts);\n };\n};\nexport default plugin;\n"],"names":["LevelFormat","AlignmentType","convertInchesToTwip","definitions","sectionPageSizeDefaults","sectionMarginDefaults","Document","Packer","CheckBox","Paragraph","HeadingLevel","PageBreak","Table","TableRow","TableCell","TextRun","ExternalHyperlink","FootnoteReferenceRun"],"mappings":";;;;;AAAA,MAAM,aAAa,GAAmC,EAAE;AAExD;;AAEG;SACa,QAAQ,CAAC,OAAe,EAAE,OAAgB,KAAK,EAAA;IAC7D,IAAI,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE;AACpC,QAAA,aAAa,CAAC,OAAO,CAAC,GAAG,IAAI;AAC7B,QAAA,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;IACvB;AACF;;AC8BA,MAAM,gBAAgB,GAAG,SAAS;AAClC,MAAM,aAAa,GAAG,MAAM;AAC5B,MAAM,kBAAkB,GAAG,WAAW;AACtC,MAAM,MAAM,GAAG,GAAG;AAElB,MAAM,sBAAsB,GAAG,MAAuB;AACpD,IAAA,MAAM,cAAc,GAAG,IAAI,GAAG,EAAkB;AAChD,IAAA,MAAM,IAAI,GAAG,IAAI,GAAG,EAAuB;AAE3C,IAAA,MAAM,KAAK,GAAG,CAAC,EAAU,KAAY;QACnC,IAAI,UAAU,GAAG,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;AACvC,QAAA,IAAI,UAAU,IAAI,IAAI,EAAE;AACtB,YAAA,cAAc,CAAC,GAAG,CAAC,EAAE,GAAG,UAAU,GAAG,cAAc,CAAC,IAAI,GAAG,CAAC,EAAE;QAChE;AACA,QAAA,OAAO,UAAU;AACnB,IAAA,CAAC;IAED,OAAO;AACL,QAAA,GAAG,EAAE,CAAC,EAAE,KAAI;AACV,YAAA,OAAO,KAAK,CAAC,EAAE,CAAC;QAClB,CAAC;AACD,QAAA,GAAG,EAAE,CAAC,EAAE,EAAE,GAAG,KAAI;AACf,YAAA,MAAM,UAAU,GAAG,KAAK,CAAC,EAAE,CAAC;AAC5B,YAAA,I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lib/index.js
CHANGED
|
@@ -15,7 +15,6 @@ function warnOnce(message, cond = false) {
|
|
|
15
15
|
const ORDERED_LIST_REF = "ordered";
|
|
16
16
|
const TASK_LIST_REF = "task";
|
|
17
17
|
const HYPERLINK_STYLE_ID = "Hyperlink";
|
|
18
|
-
const INLINE_CODE_STYLE_ID = "InlineCode";
|
|
19
18
|
const INDENT = 0.5;
|
|
20
19
|
const createFootnoteRegistry = () => {
|
|
21
20
|
const idToInternalId = new Map();
|
|
@@ -102,8 +101,7 @@ const buildLevels = (formats) => formats.map(({ format, text }, i) => {
|
|
|
102
101
|
},
|
|
103
102
|
};
|
|
104
103
|
});
|
|
105
|
-
const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywords, description, styles, background, thematicBreak = "page", orderedListFormat = defaultOrderedList, } = {}) => {
|
|
106
|
-
var _a;
|
|
104
|
+
const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywords, description, styles, size, margin, background, thematicBreak = "page", orderedListFormat = defaultOrderedList, } = {}) => {
|
|
107
105
|
const definition = definitions(node);
|
|
108
106
|
const numbering = createNumberingRegistry();
|
|
109
107
|
const footnote = createFootnoteRegistry();
|
|
@@ -153,6 +151,30 @@ const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywor
|
|
|
153
151
|
}
|
|
154
152
|
return null;
|
|
155
153
|
};
|
|
154
|
+
let { WIDTH: pageWidth, HEIGHT: pageHeight } = sectionPageSizeDefaults;
|
|
155
|
+
if (size) {
|
|
156
|
+
if (size.width != null) {
|
|
157
|
+
pageWidth = size.width;
|
|
158
|
+
}
|
|
159
|
+
if (size.height != null) {
|
|
160
|
+
pageHeight = size.height;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
let { TOP: marginTop, LEFT: marginLeft, BOTTOM: marginBottom, RIGHT: marginRight, } = sectionMarginDefaults;
|
|
164
|
+
if (margin) {
|
|
165
|
+
if (margin.top != null) {
|
|
166
|
+
marginTop = margin.top;
|
|
167
|
+
}
|
|
168
|
+
if (margin.left != null) {
|
|
169
|
+
marginLeft = margin.left;
|
|
170
|
+
}
|
|
171
|
+
if (margin.bottom != null) {
|
|
172
|
+
marginBottom = margin.bottom;
|
|
173
|
+
}
|
|
174
|
+
if (margin.right != null) {
|
|
175
|
+
marginRight = margin.right;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
156
178
|
const ctx = {
|
|
157
179
|
render(nodes, c) {
|
|
158
180
|
const results = [];
|
|
@@ -164,9 +186,7 @@ const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywor
|
|
|
164
186
|
}
|
|
165
187
|
return results;
|
|
166
188
|
},
|
|
167
|
-
width:
|
|
168
|
-
sectionMarginDefaults.LEFT -
|
|
169
|
-
sectionMarginDefaults.RIGHT,
|
|
189
|
+
width: pageWidth - marginLeft - marginRight,
|
|
170
190
|
deco: {},
|
|
171
191
|
indent: 0,
|
|
172
192
|
thematicBreak,
|
|
@@ -189,28 +209,31 @@ const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywor
|
|
|
189
209
|
}
|
|
190
210
|
}
|
|
191
211
|
const orderedLevels = buildLevels(orderedListFormat);
|
|
212
|
+
const sectionProperties = {
|
|
213
|
+
page: {
|
|
214
|
+
size: { width: pageWidth, height: pageHeight },
|
|
215
|
+
margin: {
|
|
216
|
+
top: marginTop,
|
|
217
|
+
left: marginLeft,
|
|
218
|
+
bottom: marginBottom,
|
|
219
|
+
right: marginRight,
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
};
|
|
192
223
|
const doc = new Document({
|
|
193
224
|
title,
|
|
194
225
|
subject,
|
|
195
226
|
creator,
|
|
196
227
|
keywords,
|
|
197
228
|
description,
|
|
198
|
-
styles:
|
|
199
|
-
...styles,
|
|
200
|
-
characterStyles: [
|
|
201
|
-
...((_a = styles === null || styles === void 0 ? void 0 : styles.characterStyles) !== null && _a !== void 0 ? _a : []),
|
|
202
|
-
{
|
|
203
|
-
id: INLINE_CODE_STYLE_ID,
|
|
204
|
-
run: {
|
|
205
|
-
highlight: "lightGray",
|
|
206
|
-
},
|
|
207
|
-
},
|
|
208
|
-
],
|
|
209
|
-
},
|
|
229
|
+
styles: styles,
|
|
210
230
|
background,
|
|
211
231
|
sections: sections
|
|
212
232
|
.filter((s) => s.length)
|
|
213
|
-
.map((s) => ({
|
|
233
|
+
.map((s) => ({
|
|
234
|
+
properties: sectionProperties,
|
|
235
|
+
children: s,
|
|
236
|
+
})),
|
|
214
237
|
footnotes: footnote.toConfig(),
|
|
215
238
|
numbering: {
|
|
216
239
|
config: [
|
|
@@ -388,6 +411,9 @@ const buildText = ({ value }, { deco }) => {
|
|
|
388
411
|
italics: deco.italic,
|
|
389
412
|
strike: deco.strike,
|
|
390
413
|
};
|
|
414
|
+
if (deco.inlineCode) {
|
|
415
|
+
options.highlight = "lightGray";
|
|
416
|
+
}
|
|
391
417
|
if (deco.link) {
|
|
392
418
|
// https://docx.js.org/#/usage/hyperlinks?id=styling-hyperlinks
|
|
393
419
|
options.style = HYPERLINK_STYLE_ID;
|
|
@@ -412,10 +438,10 @@ const buildDelete = ({ children }, ctx) => {
|
|
|
412
438
|
deco: { ...ctx.deco, strike: true },
|
|
413
439
|
});
|
|
414
440
|
};
|
|
415
|
-
const buildInlineCode = ({ value }) => {
|
|
416
|
-
return
|
|
417
|
-
|
|
418
|
-
|
|
441
|
+
const buildInlineCode = ({ value }, ctx) => {
|
|
442
|
+
return buildText({ value }, {
|
|
443
|
+
...ctx,
|
|
444
|
+
deco: { ...ctx.deco, inlineCode: true },
|
|
419
445
|
});
|
|
420
446
|
};
|
|
421
447
|
const buildBreak = () => {
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/src/utils.ts","../src/src/mdast-util-to-docx.ts","../src/src/plugin.ts"],"sourcesContent":["const alreadyWarned: { [message: string]: boolean } = {};\n\n/**\n * @internal\n */\nexport function warnOnce(message: string, cond: boolean = false): void {\n if (!cond && !alreadyWarned[message]) {\n alreadyWarned[message] = true;\n console.warn(message);\n }\n}\n","import {\n convertInchesToTwip,\n Packer,\n Document,\n Paragraph,\n Table,\n TableRow,\n TableCell,\n TextRun,\n ExternalHyperlink,\n HeadingLevel,\n LevelFormat,\n AlignmentType,\n type ILevelsOptions,\n FootnoteReferenceRun,\n CheckBox,\n type IPropertiesOptions,\n sectionPageSizeDefaults,\n sectionMarginDefaults,\n type IRunOptions,\n type IParagraphOptions,\n PageBreak,\n} from \"docx\";\nimport type * as mdast from \"mdast\";\nimport { warnOnce } from \"./utils\";\nimport { definitions } from \"mdast-util-definitions\";\nimport type {\n Context,\n DocxChild,\n DocxContent,\n FootnoteRegistry,\n ListContext,\n NodeBuilder,\n NodeBuilders,\n RemarkDocxPlugin,\n ThematicBreakType,\n Writeable,\n} from \"./types\";\n\nconst ORDERED_LIST_REF = \"ordered\";\nconst TASK_LIST_REF = \"task\";\nconst HYPERLINK_STYLE_ID = \"Hyperlink\";\nconst INLINE_CODE_STYLE_ID = \"InlineCode\";\nconst INDENT = 0.5;\n\nconst createFootnoteRegistry = (): FootnoteRegistry => {\n const idToInternalId = new Map<string, number>();\n const defs = new Map<number, Paragraph[]>();\n\n const getId = (id: string): number => {\n let internalId = idToInternalId.get(id);\n if (internalId == null) {\n idToInternalId.set(id, (internalId = idToInternalId.size + 1));\n }\n return internalId;\n };\n\n return {\n ref: (id) => {\n return getId(id);\n },\n def: (id, def) => {\n const internalId = getId(id);\n defs.set(internalId, def);\n },\n toConfig: () => {\n return defs.entries().reduce(\n (acc, [key, def]) => {\n acc[key] = { children: def };\n return acc;\n },\n {} as {\n [key: string]: { children: Paragraph[] };\n },\n );\n },\n };\n};\n\ntype ListFormat = {\n format: keyof typeof LevelFormat;\n text: string;\n};\n\ntype NumberingRegistry = {\n createId: () => string;\n getIds: () => string[];\n};\nconst createNumberingRegistry = (): NumberingRegistry => {\n let counter = 1;\n\n return {\n createId: () => {\n return `${ORDERED_LIST_REF}-${counter++}`;\n },\n getIds: () => {\n return Array.from(\n { length: counter },\n (_, i) => `${ORDERED_LIST_REF}-${i}`,\n );\n },\n };\n};\n\nconst composeBuilders = (\n pluginsBuilders: readonly NodeBuilders[],\n defaultBuilders: NodeBuilders,\n): NodeBuilders => {\n return pluginsBuilders.reduceRight<NodeBuilders>((acc, p) => {\n type Key = keyof typeof p;\n for (const [k, cur] of Object.entries(p)) {\n const prev = acc[k as Key];\n acc[k as Key] = (\n prev\n ? (n, c) => {\n const r = cur(n as any, c);\n if (r) {\n return r;\n }\n return prev(n as any, c);\n }\n : cur\n ) as NodeBuilder<any>;\n }\n return acc;\n }, defaultBuilders);\n};\nconst defaultTaskList: ListFormat[] = [\n { text: \"\", format: \"NONE\" },\n { text: \"\", format: \"NONE\" },\n { text: \"\", format: \"NONE\" },\n { text: \"\", format: \"NONE\" },\n { text: \"\", format: \"NONE\" },\n { text: \"\", format: \"NONE\" },\n];\n\nconst defaultOrderedList: ListFormat[] = [\n { text: \"%1.\", format: \"DECIMAL\" },\n { text: \"%2.\", format: \"DECIMAL\" },\n { text: \"%3.\", format: \"DECIMAL\" },\n { text: \"%4.\", format: \"DECIMAL\" },\n { text: \"%5.\", format: \"DECIMAL\" },\n { text: \"%6.\", format: \"DECIMAL\" },\n];\n\nconst buildLevels = (formats: readonly ListFormat[]): ILevelsOptions[] =>\n formats.map(({ format, text }, i) => {\n return {\n level: i,\n format: LevelFormat[format],\n text: text,\n alignment: AlignmentType.START,\n style:\n i === 0\n ? undefined\n : {\n paragraph: {\n indent: { start: convertInchesToTwip(INDENT * i) },\n },\n },\n };\n });\n\nexport interface DocxOptions extends Pick<\n IPropertiesOptions,\n | \"title\"\n | \"subject\"\n | \"creator\"\n | \"keywords\"\n | \"description\"\n | \"styles\"\n | \"background\"\n> {\n /**\n * An option to override the text format of ordered list.\n * See https://docx.js.org/#/usage/numbering?id=level-options for more details.\n * @default {@link defaultOrderedList}\n */\n orderedListFormat?: ListFormat[];\n /**\n * An option to select how thematicBreak works. \"page\" is Page Break. \"section\" is Section Break.\n * @default \"page\"\n */\n thematicBreak?: ThematicBreakType;\n /**\n * Plugins to customize how mdast nodes are compiled.\n */\n plugins?: RemarkDocxPlugin[];\n}\n\nexport const mdastToDocx = async (\n node: mdast.Root,\n {\n plugins = [],\n title,\n subject,\n creator,\n keywords,\n description,\n styles,\n background,\n thematicBreak = \"page\",\n orderedListFormat = defaultOrderedList,\n }: DocxOptions = {},\n): Promise<ArrayBuffer> => {\n const definition = definitions(node);\n\n const numbering = createNumberingRegistry();\n const footnote = createFootnoteRegistry();\n\n const pluginCtx = { root: node, definition };\n\n const builders = composeBuilders(\n await Promise.all(plugins.map((p) => p(pluginCtx))),\n {\n paragraph: buildParagraph,\n heading: buildHeading,\n thematicBreak: buildThematicBreak,\n blockquote: buildBlockquote,\n list: buildList,\n listItem: buildListItem,\n table: buildTable,\n tableRow: noop,\n tableCell: noop,\n html: fallbackText,\n code: fallbackText,\n definition: noop,\n footnoteDefinition: buildFootnoteDefinition,\n text: buildText,\n emphasis: buildEmphasis,\n strong: buildStrong,\n delete: buildDelete,\n inlineCode: buildInlineCode,\n break: buildBreak,\n link: buildLink,\n linkReference: buildLinkReference,\n // image: warnImage,\n // imageReference: warnImage,\n footnoteReference: buildFootnoteReference,\n math: fallbackText,\n inlineMath: fallbackText,\n },\n );\n\n const renderNode = (\n node: mdast.RootContent,\n c: Context,\n ): DocxContent[] | null => {\n const builder = builders[node.type];\n if (!builder) {\n warnOnce(`${node.type} node is not supported without plugins.`);\n return null;\n }\n const r = builder(node as any, c);\n if (r) {\n if (Array.isArray(r)) {\n return r;\n } else {\n return [r];\n }\n }\n return null;\n };\n\n const ctx: Context = {\n render(nodes, c) {\n const results: DocxContent[] = [];\n for (const node of nodes) {\n const r = renderNode(node, c ?? this);\n if (r) {\n results.push(...r);\n }\n }\n return results;\n },\n width:\n sectionPageSizeDefaults.WIDTH -\n sectionMarginDefaults.LEFT -\n sectionMarginDefaults.RIGHT,\n deco: {},\n indent: 0,\n thematicBreak,\n definition: definition,\n footnote,\n orderedId: numbering.createId,\n };\n\n const sections: DocxContent[][] = [[]];\n for (const n of node.children) {\n const r = renderNode(n, ctx);\n if (r) {\n if (!r.length) {\n // thematicBreak\n sections.push([]);\n } else {\n const lastSection = sections[sections.length - 1]!;\n lastSection.push(...r);\n }\n }\n }\n\n const orderedLevels = buildLevels(orderedListFormat);\n\n const doc = new Document({\n title,\n subject,\n creator,\n keywords,\n description,\n styles: {\n ...styles,\n characterStyles: [\n ...(styles?.characterStyles ?? []),\n {\n id: INLINE_CODE_STYLE_ID,\n run: {\n highlight: \"lightGray\",\n },\n },\n ],\n },\n background,\n sections: sections\n .filter((s) => s.length)\n .map((s) => ({ children: s as DocxChild[] })),\n footnotes: footnote.toConfig(),\n numbering: {\n config: [\n ...numbering.getIds().map((ref) => ({\n reference: ref,\n levels: orderedLevels,\n })),\n {\n reference: TASK_LIST_REF,\n levels: buildLevels(defaultTaskList),\n },\n ],\n },\n });\n\n return Packer.toArrayBuffer(doc);\n};\n\nconst buildParagraph: NodeBuilder<\"paragraph\"> = ({ children }, ctx) => {\n const list = ctx.list;\n const nodes = ctx.render(children);\n\n const options: Writeable<IParagraphOptions> = {\n children: nodes,\n };\n\n if (ctx.indent > 0) {\n options.indent = {\n start: convertInchesToTwip(INDENT * ctx.indent),\n };\n }\n\n if (list) {\n const { level, meta } = list;\n if (meta.type === \"task\") {\n nodes.unshift(\n new CheckBox({\n checked: meta.checked,\n checkedState: { value: \"2611\" },\n uncheckedState: { value: \"2610\" },\n }),\n );\n options.numbering = {\n reference: TASK_LIST_REF,\n level,\n };\n } else if (meta.type === \"ordered\") {\n options.numbering = {\n reference: meta.reference,\n level,\n };\n } else {\n options.bullet = {\n level,\n };\n }\n }\n\n return new Paragraph(options);\n};\n\nconst buildHeading: NodeBuilder<\"heading\"> = ({ children, depth }, ctx) => {\n let headingLevel: (typeof HeadingLevel)[keyof typeof HeadingLevel];\n switch (depth) {\n case 1:\n headingLevel = HeadingLevel.TITLE;\n break;\n case 2:\n headingLevel = HeadingLevel.HEADING_1;\n break;\n case 3:\n headingLevel = HeadingLevel.HEADING_2;\n break;\n case 4:\n headingLevel = HeadingLevel.HEADING_3;\n break;\n case 5:\n headingLevel = HeadingLevel.HEADING_4;\n break;\n case 6:\n headingLevel = HeadingLevel.HEADING_5;\n break;\n }\n const nodes = ctx.render(children);\n return new Paragraph({\n heading: headingLevel,\n children: nodes,\n });\n};\n\nconst buildThematicBreak: NodeBuilder<\"thematicBreak\"> = (_, ctx) => {\n if (ctx.thematicBreak === \"section\") {\n // Returning empty array at toplevel means section insertion.\n return [];\n }\n return new Paragraph({ children: [new PageBreak()] });\n};\n\nconst buildBlockquote: NodeBuilder<\"blockquote\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n indent: ctx.indent + 1,\n });\n};\n\nconst buildList: NodeBuilder<\"list\"> = ({ children, ordered }, ctx) => {\n const parentList = ctx.list;\n\n let meta: ListContext[\"meta\"];\n if (ordered) {\n meta = {\n type: \"ordered\",\n reference:\n parentList && parentList.meta.type === \"ordered\"\n ? parentList.meta.reference\n : ctx.orderedId(),\n };\n } else {\n meta = { type: \"bullet\" };\n }\n\n return ctx.render(children, {\n ...ctx,\n list: {\n level: !parentList ? 0 : parentList.level + 1,\n meta,\n },\n });\n};\n\nconst buildListItem: NodeBuilder<\"listItem\"> = ({ children, checked }, ctx) => {\n let list = ctx.list;\n if (list) {\n // listItem must be the child of list\n if (checked != null) {\n list = {\n level: list.level,\n meta: {\n type: \"task\",\n checked,\n },\n };\n }\n }\n return ctx.render(children, {\n ...ctx,\n list,\n });\n};\n\nconst buildTable: NodeBuilder<\"table\"> = ({ children, align }, ctx) => {\n const cellAligns:\n | (typeof AlignmentType)[keyof typeof AlignmentType][]\n | undefined = align?.map((a) => {\n switch (a) {\n case \"left\":\n return AlignmentType.LEFT;\n case \"right\":\n return AlignmentType.RIGHT;\n case \"center\":\n return AlignmentType.CENTER;\n default:\n return AlignmentType.LEFT;\n }\n });\n\n const columnLength = children[0]!.children.length;\n const columnWidth = ctx.width / columnLength;\n\n return new Table({\n columnWidths: Array.from({ length: columnLength }).map(() => columnWidth),\n rows: children.map((r) => {\n return new TableRow({\n children: r.children.map((c, i) => {\n return new TableCell({\n width: { size: columnWidth, type: \"dxa\" },\n children: [\n new Paragraph({\n alignment: cellAligns?.[i],\n children: ctx.render(c.children),\n }),\n ],\n });\n }),\n });\n }),\n });\n};\n\nconst buildText: NodeBuilder<\"text\"> = ({ value }, { deco }) => {\n const options: Writeable<IRunOptions> = {\n text: value,\n bold: deco.bold,\n italics: deco.italic,\n strike: deco.strike,\n };\n if (deco.link) {\n // https://docx.js.org/#/usage/hyperlinks?id=styling-hyperlinks\n options.style = HYPERLINK_STYLE_ID;\n }\n return new TextRun(options);\n};\n\nconst buildEmphasis: NodeBuilder<\"emphasis\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, italic: true },\n });\n};\n\nconst buildStrong: NodeBuilder<\"strong\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, bold: true },\n });\n};\n\nconst buildDelete: NodeBuilder<\"delete\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, strike: true },\n });\n};\n\nconst buildInlineCode: NodeBuilder<\"inlineCode\"> = ({ value }) => {\n return new TextRun({\n text: value,\n style: INLINE_CODE_STYLE_ID,\n });\n};\n\nconst buildBreak: NodeBuilder<\"break\"> = () => {\n return new TextRun({ text: \"\", break: 1 });\n};\n\nconst buildLink: NodeBuilder<\"link\"> = ({ children, url }, ctx) => {\n const nodes = ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, link: true },\n });\n return new ExternalHyperlink({\n link: url,\n children: nodes,\n });\n};\n\nconst buildLinkReference: NodeBuilder<\"linkReference\"> = (\n { children, identifier },\n ctx,\n) => {\n const def = ctx.definition(identifier);\n if (def == null) {\n return ctx.render(children);\n }\n return buildLink({ type: \"link\", children, url: def.url }, ctx);\n};\n\nconst buildFootnoteDefinition: NodeBuilder<\"footnoteDefinition\"> = (\n { children, identifier },\n ctx,\n) => {\n ctx.footnote.def(\n identifier,\n ctx.render(children).filter((c) => c instanceof Paragraph),\n );\n return null;\n};\n\nconst buildFootnoteReference: NodeBuilder<\"footnoteReference\"> = (\n { identifier },\n ctx,\n) => {\n return new FootnoteReferenceRun(ctx.footnote.ref(identifier));\n};\n\nconst noop = () => {\n return null;\n};\n\nconst fallbackText = (node: { type: string; value: string }, ctx: Context) => {\n warnOnce(\n `${node.type} node is not supported without plugins, falling back to text.`,\n );\n return buildText({ type: \"text\", value: node.value }, ctx);\n};\n","import type { Plugin } from \"unified\";\nimport type { Root } from \"mdast\";\nimport { mdastToDocx, type DocxOptions } from \"./mdast-util-to-docx\";\n\nexport type { DocxOptions };\n\ndeclare module \"unified\" {\n interface CompileResultMap {\n docx: Promise<ArrayBuffer>;\n }\n}\n\nconst plugin: Plugin<[DocxOptions?], Root, Promise<ArrayBuffer>> = function (\n opts,\n) {\n this.compiler = (node) => {\n return mdastToDocx(node as Root, opts);\n };\n};\nexport default plugin;\n"],"names":[],"mappings":";;;AAAA,MAAM,aAAa,GAAmC,EAAE;AAExD;;AAEG;SACa,QAAQ,CAAC,OAAe,EAAE,OAAgB,KAAK,EAAA;IAC7D,IAAI,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE;AACpC,QAAA,aAAa,CAAC,OAAO,CAAC,GAAG,IAAI;AAC7B,QAAA,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;IACvB;AACF;;AC6BA,MAAM,gBAAgB,GAAG,SAAS;AAClC,MAAM,aAAa,GAAG,MAAM;AAC5B,MAAM,kBAAkB,GAAG,WAAW;AACtC,MAAM,oBAAoB,GAAG,YAAY;AACzC,MAAM,MAAM,GAAG,GAAG;AAElB,MAAM,sBAAsB,GAAG,MAAuB;AACpD,IAAA,MAAM,cAAc,GAAG,IAAI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AAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,SAAS,CAAC,CAC3D;AACD,IAAA,OAAO,IAAI;AACb,CAAC;AAED,MAAM,sBAAsB,GAAqC,CAC/D,EAAE,UAAU,EAAE,EACd,GAAG,KACD;AACF,IAAA,OAAO,IAAI,oBAAoB,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAC/D,CAAC;AAED,MAAM,IAAI,GAAG,MAAK;AAChB,IAAA,OAAO,IAAI;AACb,CAAC;AAED,MAAM,YAAY,GAAG,CAAC,IAAqC,EAAE,GAAY,KAAI;AAC3E,IAAA,QAAQ,CACN,CAAA,EAAG,IAAI,CAAC,IAAI,CAAA,6DAAA,CAA+D,CAC5E;AACD,IAAA,OAAO,SAAS,CAAC,EAAgB,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,GAAG,CAAC;AAC5D,CAAC;;ACrlBD,MAAM,MAAM,GAAuD,UACjE,IAAI,EAAA;AAEJ,IAAA,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,KAAI;AACvB,QAAA,OAAO,WAAW,CAAC,IAAY,EAAE,IAAI,CAAC;AACxC,IAAA,CAAC;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/src/utils.ts","../src/src/mdast-util-to-docx.ts","../src/src/plugin.ts"],"sourcesContent":["const alreadyWarned: { [message: string]: boolean } = {};\n\n/**\n * @internal\n */\nexport function warnOnce(message: string, cond: boolean = false): void {\n if (!cond && !alreadyWarned[message]) {\n alreadyWarned[message] = true;\n console.warn(message);\n }\n}\n","import {\n convertInchesToTwip,\n Packer,\n Document,\n Paragraph,\n Table,\n TableRow,\n TableCell,\n TextRun,\n ExternalHyperlink,\n HeadingLevel,\n LevelFormat,\n AlignmentType,\n type ILevelsOptions,\n FootnoteReferenceRun,\n CheckBox,\n type IPropertiesOptions,\n sectionPageSizeDefaults,\n sectionMarginDefaults,\n type IRunOptions,\n type IParagraphOptions,\n PageBreak,\n type ISectionPropertiesOptions,\n} from \"docx\";\nimport type * as mdast from \"mdast\";\nimport { warnOnce } from \"./utils\";\nimport { definitions } from \"mdast-util-definitions\";\nimport type {\n Context,\n DocxChild,\n DocxContent,\n FootnoteRegistry,\n ListContext,\n NodeBuilder,\n NodeBuilders,\n RemarkDocxPlugin,\n ThematicBreakType,\n Writeable,\n} from \"./types\";\n\nconst ORDERED_LIST_REF = \"ordered\";\nconst TASK_LIST_REF = \"task\";\nconst HYPERLINK_STYLE_ID = \"Hyperlink\";\nconst INDENT = 0.5;\n\nconst createFootnoteRegistry = (): FootnoteRegistry => {\n const idToInternalId = new Map<string, number>();\n const defs = new Map<number, Paragraph[]>();\n\n const getId = (id: string): number => {\n let internalId = idToInternalId.get(id);\n if (internalId == null) {\n idToInternalId.set(id, (internalId = idToInternalId.size + 1));\n }\n return internalId;\n };\n\n return {\n ref: (id) => {\n return getId(id);\n },\n def: (id, def) => {\n const internalId = getId(id);\n defs.set(internalId, def);\n },\n toConfig: () => {\n return defs.entries().reduce(\n (acc, [key, def]) => {\n acc[key] = { children: def };\n return acc;\n },\n {} as {\n [key: string]: { children: Paragraph[] };\n },\n );\n },\n };\n};\n\ntype ListFormat = {\n format: keyof typeof LevelFormat;\n text: string;\n};\n\ntype NumberingRegistry = {\n createId: () => string;\n getIds: () => string[];\n};\nconst createNumberingRegistry = (): NumberingRegistry => {\n let counter = 1;\n\n return {\n createId: () => {\n return `${ORDERED_LIST_REF}-${counter++}`;\n },\n getIds: () => {\n return Array.from(\n { length: counter },\n (_, i) => `${ORDERED_LIST_REF}-${i}`,\n );\n },\n };\n};\n\nconst composeBuilders = (\n pluginsBuilders: readonly NodeBuilders[],\n defaultBuilders: NodeBuilders,\n): NodeBuilders => {\n return pluginsBuilders.reduceRight<NodeBuilders>((acc, p) => {\n type Key = keyof typeof p;\n for (const [k, cur] of Object.entries(p)) {\n const prev = acc[k as Key];\n acc[k as Key] = (\n prev\n ? (n, c) => {\n const r = cur(n as any, c);\n if (r) {\n return r;\n }\n return prev(n as any, c);\n }\n : cur\n ) as NodeBuilder<any>;\n }\n return acc;\n }, defaultBuilders);\n};\nconst defaultTaskList: ListFormat[] = [\n { text: \"\", format: \"NONE\" },\n { text: \"\", format: \"NONE\" },\n { text: \"\", format: \"NONE\" },\n { text: \"\", format: \"NONE\" },\n { text: \"\", format: \"NONE\" },\n { text: \"\", format: \"NONE\" },\n];\n\nconst defaultOrderedList: ListFormat[] = [\n { text: \"%1.\", format: \"DECIMAL\" },\n { text: \"%2.\", format: \"DECIMAL\" },\n { text: \"%3.\", format: \"DECIMAL\" },\n { text: \"%4.\", format: \"DECIMAL\" },\n { text: \"%5.\", format: \"DECIMAL\" },\n { text: \"%6.\", format: \"DECIMAL\" },\n];\n\nconst buildLevels = (formats: readonly ListFormat[]): ILevelsOptions[] =>\n formats.map(({ format, text }, i) => {\n return {\n level: i,\n format: LevelFormat[format],\n text: text,\n alignment: AlignmentType.START,\n style:\n i === 0\n ? undefined\n : {\n paragraph: {\n indent: { start: convertInchesToTwip(INDENT * i) },\n },\n },\n };\n });\n\nexport interface DocxOptions extends Pick<\n IPropertiesOptions,\n | \"title\"\n | \"subject\"\n | \"creator\"\n | \"keywords\"\n | \"description\"\n | \"styles\"\n | \"background\"\n> {\n /**\n * Page size defined in twip (1 twip == 1/1440 inch).\n * @default A4 ({@link sectionPageSizeDefaults})\n */\n size?: { width?: number; height?: number };\n /**\n * Page margin defined in twip (1 twip == 1/1440 inch).\n * @default 1 inch ({@link sectionMarginDefaults})\n */\n margin?: { top?: number; left?: number; bottom?: number; right?: number };\n /**\n * An option to override the text format of ordered list.\n * See https://docx.js.org/#/usage/numbering?id=level-options for more details.\n * @default {@link defaultOrderedList}\n */\n orderedListFormat?: ListFormat[];\n /**\n * An option to select how thematicBreak works. \"page\" is Page Break. \"section\" is Section Break.\n * @default \"page\"\n */\n thematicBreak?: ThematicBreakType;\n /**\n * Plugins to customize how mdast nodes are compiled.\n */\n plugins?: RemarkDocxPlugin[];\n}\n\nexport const mdastToDocx = async (\n node: mdast.Root,\n {\n plugins = [],\n title,\n subject,\n creator,\n keywords,\n description,\n styles,\n size,\n margin,\n background,\n thematicBreak = \"page\",\n orderedListFormat = defaultOrderedList,\n }: DocxOptions = {},\n): Promise<ArrayBuffer> => {\n const definition = definitions(node);\n\n const numbering = createNumberingRegistry();\n const footnote = createFootnoteRegistry();\n\n const pluginCtx = { root: node, definition };\n\n const builders = composeBuilders(\n await Promise.all(plugins.map((p) => p(pluginCtx))),\n {\n paragraph: buildParagraph,\n heading: buildHeading,\n thematicBreak: buildThematicBreak,\n blockquote: buildBlockquote,\n list: buildList,\n listItem: buildListItem,\n table: buildTable,\n tableRow: noop,\n tableCell: noop,\n html: fallbackText,\n code: fallbackText,\n definition: noop,\n footnoteDefinition: buildFootnoteDefinition,\n text: buildText,\n emphasis: buildEmphasis,\n strong: buildStrong,\n delete: buildDelete,\n inlineCode: buildInlineCode,\n break: buildBreak,\n link: buildLink,\n linkReference: buildLinkReference,\n // image: warnImage,\n // imageReference: warnImage,\n footnoteReference: buildFootnoteReference,\n math: fallbackText,\n inlineMath: fallbackText,\n },\n );\n\n const renderNode = (\n node: mdast.RootContent,\n c: Context,\n ): DocxContent[] | null => {\n const builder = builders[node.type];\n if (!builder) {\n warnOnce(`${node.type} node is not supported without plugins.`);\n return null;\n }\n const r = builder(node as any, c);\n if (r) {\n if (Array.isArray(r)) {\n return r;\n } else {\n return [r];\n }\n }\n return null;\n };\n\n let { WIDTH: pageWidth, HEIGHT: pageHeight } = sectionPageSizeDefaults;\n if (size) {\n if (size.width != null) {\n pageWidth = size.width;\n }\n if (size.height != null) {\n pageHeight = size.height;\n }\n }\n let {\n TOP: marginTop,\n LEFT: marginLeft,\n BOTTOM: marginBottom,\n RIGHT: marginRight,\n } = sectionMarginDefaults;\n if (margin) {\n if (margin.top != null) {\n marginTop = margin.top;\n }\n if (margin.left != null) {\n marginLeft = margin.left;\n }\n if (margin.bottom != null) {\n marginBottom = margin.bottom;\n }\n if (margin.right != null) {\n marginRight = margin.right;\n }\n }\n\n const ctx: Context = {\n render(nodes, c) {\n const results: DocxContent[] = [];\n for (const node of nodes) {\n const r = renderNode(node, c ?? this);\n if (r) {\n results.push(...r);\n }\n }\n return results;\n },\n width: pageWidth - marginLeft - marginRight,\n deco: {},\n indent: 0,\n thematicBreak,\n definition: definition,\n footnote,\n orderedId: numbering.createId,\n };\n\n const sections: DocxContent[][] = [[]];\n for (const n of node.children) {\n const r = renderNode(n, ctx);\n if (r) {\n if (!r.length) {\n // thematicBreak\n sections.push([]);\n } else {\n const lastSection = sections[sections.length - 1]!;\n lastSection.push(...r);\n }\n }\n }\n\n const orderedLevels = buildLevels(orderedListFormat);\n\n const sectionProperties: ISectionPropertiesOptions = {\n page: {\n size: { width: pageWidth, height: pageHeight },\n margin: {\n top: marginTop,\n left: marginLeft,\n bottom: marginBottom,\n right: marginRight,\n },\n },\n };\n\n const doc = new Document({\n title,\n subject,\n creator,\n keywords,\n description,\n styles: styles,\n background,\n sections: sections\n .filter((s) => s.length)\n .map((s) => ({\n properties: sectionProperties,\n children: s as DocxChild[],\n })),\n footnotes: footnote.toConfig(),\n numbering: {\n config: [\n ...numbering.getIds().map((ref) => ({\n reference: ref,\n levels: orderedLevels,\n })),\n {\n reference: TASK_LIST_REF,\n levels: buildLevels(defaultTaskList),\n },\n ],\n },\n });\n\n return Packer.toArrayBuffer(doc);\n};\n\nconst buildParagraph: NodeBuilder<\"paragraph\"> = ({ children }, ctx) => {\n const list = ctx.list;\n const nodes = ctx.render(children);\n\n const options: Writeable<IParagraphOptions> = {\n children: nodes,\n };\n\n if (ctx.indent > 0) {\n options.indent = {\n start: convertInchesToTwip(INDENT * ctx.indent),\n };\n }\n\n if (list) {\n const { level, meta } = list;\n if (meta.type === \"task\") {\n nodes.unshift(\n new CheckBox({\n checked: meta.checked,\n checkedState: { value: \"2611\" },\n uncheckedState: { value: \"2610\" },\n }),\n );\n options.numbering = {\n reference: TASK_LIST_REF,\n level,\n };\n } else if (meta.type === \"ordered\") {\n options.numbering = {\n reference: meta.reference,\n level,\n };\n } else {\n options.bullet = {\n level,\n };\n }\n }\n\n return new Paragraph(options);\n};\n\nconst buildHeading: NodeBuilder<\"heading\"> = ({ children, depth }, ctx) => {\n let headingLevel: (typeof HeadingLevel)[keyof typeof HeadingLevel];\n switch (depth) {\n case 1:\n headingLevel = HeadingLevel.TITLE;\n break;\n case 2:\n headingLevel = HeadingLevel.HEADING_1;\n break;\n case 3:\n headingLevel = HeadingLevel.HEADING_2;\n break;\n case 4:\n headingLevel = HeadingLevel.HEADING_3;\n break;\n case 5:\n headingLevel = HeadingLevel.HEADING_4;\n break;\n case 6:\n headingLevel = HeadingLevel.HEADING_5;\n break;\n }\n const nodes = ctx.render(children);\n return new Paragraph({\n heading: headingLevel,\n children: nodes,\n });\n};\n\nconst buildThematicBreak: NodeBuilder<\"thematicBreak\"> = (_, ctx) => {\n if (ctx.thematicBreak === \"section\") {\n // Returning empty array at toplevel means section insertion.\n return [];\n }\n return new Paragraph({ children: [new PageBreak()] });\n};\n\nconst buildBlockquote: NodeBuilder<\"blockquote\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n indent: ctx.indent + 1,\n });\n};\n\nconst buildList: NodeBuilder<\"list\"> = ({ children, ordered }, ctx) => {\n const parentList = ctx.list;\n\n let meta: ListContext[\"meta\"];\n if (ordered) {\n meta = {\n type: \"ordered\",\n reference:\n parentList && parentList.meta.type === \"ordered\"\n ? parentList.meta.reference\n : ctx.orderedId(),\n };\n } else {\n meta = { type: \"bullet\" };\n }\n\n return ctx.render(children, {\n ...ctx,\n list: {\n level: !parentList ? 0 : parentList.level + 1,\n meta,\n },\n });\n};\n\nconst buildListItem: NodeBuilder<\"listItem\"> = ({ children, checked }, ctx) => {\n let list = ctx.list;\n if (list) {\n // listItem must be the child of list\n if (checked != null) {\n list = {\n level: list.level,\n meta: {\n type: \"task\",\n checked,\n },\n };\n }\n }\n return ctx.render(children, {\n ...ctx,\n list,\n });\n};\n\nconst buildTable: NodeBuilder<\"table\"> = ({ children, align }, ctx) => {\n const cellAligns:\n | (typeof AlignmentType)[keyof typeof AlignmentType][]\n | undefined = align?.map((a) => {\n switch (a) {\n case \"left\":\n return AlignmentType.LEFT;\n case \"right\":\n return AlignmentType.RIGHT;\n case \"center\":\n return AlignmentType.CENTER;\n default:\n return AlignmentType.LEFT;\n }\n });\n\n const columnLength = children[0]!.children.length;\n const columnWidth = ctx.width / columnLength;\n\n return new Table({\n columnWidths: Array.from({ length: columnLength }).map(() => columnWidth),\n rows: children.map((r) => {\n return new TableRow({\n children: r.children.map((c, i) => {\n return new TableCell({\n width: { size: columnWidth, type: \"dxa\" },\n children: [\n new Paragraph({\n alignment: cellAligns?.[i],\n children: ctx.render(c.children),\n }),\n ],\n });\n }),\n });\n }),\n });\n};\n\nconst buildText: NodeBuilder<\"text\"> = ({ value }, { deco }) => {\n const options: Writeable<IRunOptions> = {\n text: value,\n bold: deco.bold,\n italics: deco.italic,\n strike: deco.strike,\n };\n if (deco.inlineCode) {\n options.highlight = \"lightGray\";\n }\n if (deco.link) {\n // https://docx.js.org/#/usage/hyperlinks?id=styling-hyperlinks\n options.style = HYPERLINK_STYLE_ID;\n }\n return new TextRun(options);\n};\n\nconst buildEmphasis: NodeBuilder<\"emphasis\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, italic: true },\n });\n};\n\nconst buildStrong: NodeBuilder<\"strong\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, bold: true },\n });\n};\n\nconst buildDelete: NodeBuilder<\"delete\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, strike: true },\n });\n};\n\nconst buildInlineCode: NodeBuilder<\"inlineCode\"> = ({ value }, ctx) => {\n return buildText(\n { type: \"text\", value },\n {\n ...ctx,\n deco: { ...ctx.deco, inlineCode: true },\n },\n );\n};\n\nconst buildBreak: NodeBuilder<\"break\"> = () => {\n return new TextRun({ text: \"\", break: 1 });\n};\n\nconst buildLink: NodeBuilder<\"link\"> = ({ children, url }, ctx) => {\n const nodes = ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, link: true },\n });\n return new ExternalHyperlink({\n link: url,\n children: nodes,\n });\n};\n\nconst buildLinkReference: NodeBuilder<\"linkReference\"> = (\n { children, identifier },\n ctx,\n) => {\n const def = ctx.definition(identifier);\n if (def == null) {\n return ctx.render(children);\n }\n return buildLink({ type: \"link\", children, url: def.url }, ctx);\n};\n\nconst buildFootnoteDefinition: NodeBuilder<\"footnoteDefinition\"> = (\n { children, identifier },\n ctx,\n) => {\n ctx.footnote.def(\n identifier,\n ctx.render(children).filter((c) => c instanceof Paragraph),\n );\n return null;\n};\n\nconst buildFootnoteReference: NodeBuilder<\"footnoteReference\"> = (\n { identifier },\n ctx,\n) => {\n return new FootnoteReferenceRun(ctx.footnote.ref(identifier));\n};\n\nconst noop = () => {\n return null;\n};\n\nconst fallbackText = (node: { type: string; value: string }, ctx: Context) => {\n warnOnce(\n `${node.type} node is not supported without plugins, falling back to text.`,\n );\n return buildText({ type: \"text\", value: node.value }, ctx);\n};\n","import type { Plugin } from \"unified\";\nimport type { Root } from \"mdast\";\nimport { mdastToDocx, type DocxOptions } from \"./mdast-util-to-docx\";\n\nexport type { DocxOptions };\n\ndeclare module \"unified\" {\n interface CompileResultMap {\n docx: Promise<ArrayBuffer>;\n }\n}\n\nconst plugin: Plugin<[DocxOptions?], Root, Promise<ArrayBuffer>> = function (\n opts,\n) {\n this.compiler = (node) => {\n return mdastToDocx(node as Root, opts);\n };\n};\nexport default plugin;\n"],"names":[],"mappings":";;;AAAA,MAAM,aAAa,GAAmC,EAAE;AAExD;;AAEG;SACa,QAAQ,CAAC,OAAe,EAAE,OAAgB,KAAK,EAAA;IAC7D,IAAI,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,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Q,CAAC,GAAG,CACd,UAAU,EACV,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,SAAS,CAAC,CAC3D;AACD,IAAA,OAAO,IAAI;AACb,CAAC;AAED,MAAM,sBAAsB,GAAqC,CAC/D,EAAE,UAAU,EAAE,EACd,GAAG,KACD;AACF,IAAA,OAAO,IAAI,oBAAoB,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAC/D,CAAC;AAED,MAAM,IAAI,GAAG,MAAK;AAChB,IAAA,OAAO,IAAI;AACb,CAAC;AAED,MAAM,YAAY,GAAG,CAAC,IAAqC,EAAE,GAAY,KAAI;AAC3E,IAAA,QAAQ,CACN,CAAA,EAAG,IAAI,CAAC,IAAI,CAAA,6DAAA,CAA+D,CAC5E;AACD,IAAA,OAAO,SAAS,CAAC,EAAgB,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,GAAG,CAAC;AAC5D,CAAC;;ACtoBD,MAAM,MAAM,GAAuD,UACjE,IAAI,EAAA;AAEJ,IAAA,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,KAAI;AACvB,QAAA,OAAO,WAAW,CAAC,IAAY,EAAE,IAAI,CAAC;AACxC,IAAA,CAAC;AACH;;;;"}
|
|
@@ -6,6 +6,24 @@ type ListFormat = {
|
|
|
6
6
|
text: string;
|
|
7
7
|
};
|
|
8
8
|
export interface DocxOptions extends Pick<IPropertiesOptions, "title" | "subject" | "creator" | "keywords" | "description" | "styles" | "background"> {
|
|
9
|
+
/**
|
|
10
|
+
* Page size defined in twip (1 twip == 1/1440 inch).
|
|
11
|
+
* @default A4 ({@link sectionPageSizeDefaults})
|
|
12
|
+
*/
|
|
13
|
+
size?: {
|
|
14
|
+
width?: number;
|
|
15
|
+
height?: number;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Page margin defined in twip (1 twip == 1/1440 inch).
|
|
19
|
+
* @default 1 inch ({@link sectionMarginDefaults})
|
|
20
|
+
*/
|
|
21
|
+
margin?: {
|
|
22
|
+
top?: number;
|
|
23
|
+
left?: number;
|
|
24
|
+
bottom?: number;
|
|
25
|
+
right?: number;
|
|
26
|
+
};
|
|
9
27
|
/**
|
|
10
28
|
* An option to override the text format of ordered list.
|
|
11
29
|
* See https://docx.js.org/#/usage/numbering?id=level-options for more details.
|
|
@@ -22,5 +40,5 @@ export interface DocxOptions extends Pick<IPropertiesOptions, "title" | "subject
|
|
|
22
40
|
*/
|
|
23
41
|
plugins?: RemarkDocxPlugin[];
|
|
24
42
|
}
|
|
25
|
-
export declare const mdastToDocx: (node: mdast.Root, { plugins, title, subject, creator, keywords, description, styles, background, thematicBreak, orderedListFormat, }?: DocxOptions) => Promise<ArrayBuffer>;
|
|
43
|
+
export declare const mdastToDocx: (node: mdast.Root, { plugins, title, subject, creator, keywords, description, styles, size, margin, background, thematicBreak, orderedListFormat, }?: DocxOptions) => Promise<ArrayBuffer>;
|
|
26
44
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../../src/plugins/image/index.ts"],"sourcesContent":["import { warnOnce } from \"../../utils\";\nimport type { RemarkDocxPlugin } from \"../../types\";\nimport type * as mdast from \"mdast\";\nimport { ImageRun } from \"docx\";\nimport { visit } from \"unist-util-visit\";\nimport { imageSize } from \"image-size\";\n\nconst supportedTypes = [\"png\", \"jpg\", \"gif\", \"bmp\", \"svg\"] as const;\n\ntype SupportedImageType = (typeof supportedTypes)[number];\n\ntype ImageData = Readonly<\n {\n data: ArrayBuffer;\n width: number;\n height: number;\n } & (\n | { type: Exclude<SupportedImageType, \"svg\"> }\n | {\n type: Extract<SupportedImageType, \"svg\">;\n fallback: ArrayBuffer;\n }\n )\n>;\n\nconst buildImage = (\n image: ImageData,\n node: { alt?: string | null; title?: string | null },\n) => {\n const altText =\n node.alt || node.title\n ? {\n name: \"\",\n description: node.alt ?? undefined,\n title: node.title ?? undefined,\n }\n : undefined;\n\n if (image.type === \"svg\") {\n const { type, data, width, height, fallback } = image;\n return new ImageRun({\n type: type,\n data: data,\n transformation: {\n width,\n height,\n },\n // https://github.com/dolanmiu/docx/issues/1162#issuecomment-3228368003\n fallback: { type: \"png\", data: fallback },\n altText,\n });\n }\n\n const { type, data, width, height } = image;\n return new ImageRun({\n type: type,\n data: data,\n transformation: {\n width,\n height,\n },\n altText,\n });\n};\n\nconst isSupportedType = (\n type: string | undefined,\n): type is SupportedImageType => {\n if (!type) return false;\n if ((supportedTypes as readonly string[]).includes(type)) {\n return true;\n }\n return false;\n};\n\ntype LoadFn = (url: string) => Promise<ArrayBuffer>;\n\ntype SvgToPngFn = (options: {\n buffer: ArrayBuffer;\n width: number;\n height: number;\n}) => Promise<ArrayBuffer>;\n\nconst loadWithFetch: LoadFn = async (url) => {\n const res = await fetch(url);\n return res.arrayBuffer();\n};\n\nconst browserSvgToPng: SvgToPngFn = async ({ buffer, width, height }) => {\n const svgBlob = new Blob([buffer], { type: \"image/svg+xml\" });\n const url = URL.createObjectURL(svgBlob);\n\n try {\n const img = new Image();\n img.src = url;\n await img.decode();\n\n const dpr = window.devicePixelRatio;\n\n const canvas = document.createElement(\"canvas\");\n const scaledWidth = width * dpr;\n const scaledHeight = height * dpr;\n canvas.width = scaledWidth;\n canvas.height = scaledHeight;\n const ctx = canvas.getContext(\"2d\")!;\n ctx.drawImage(img, 0, 0, scaledWidth, scaledHeight);\n\n return new Promise<ArrayBuffer>((resolve) => {\n canvas.toBlob((blob) => {\n blob!.arrayBuffer().then(resolve);\n }, \"image/png\");\n });\n } finally {\n URL.revokeObjectURL(url);\n }\n};\n\nexport interface ImagePluginOptions {\n /**\n * A function to resolve image data from url.\n * @default {@link loadWithFetch}\n */\n load?: LoadFn;\n /**\n * A function to convert SVG to PNG. According to the docx specifications, embedding SVG images also requires including PNG.\n * @default {@link browserSvgToPng}, which handles conversion only on browser\n */\n fallbackSvg?: SvgToPngFn;\n}\n\n/**\n * A plugin to render \"image\" nodes\n */\nexport const imagePlugin = ({\n load = loadWithFetch,\n fallbackSvg = browserSvgToPng,\n}: ImagePluginOptions = {}): RemarkDocxPlugin => {\n const images = new Map<string, ImageData>();\n\n return async ({ root, definition }) => {\n const imageList: (mdast.Image | mdast.Definition)[] = [];\n visit(root, \"image\", (node) => {\n imageList.push(node);\n });\n visit(root, \"imageReference\", (node) => {\n const maybeImage = definition(node.identifier)!;\n if (maybeImage) {\n imageList.push(maybeImage);\n }\n });\n\n if (imageList.length !== 0) {\n const promises = new Map<string, Promise<void>>();\n imageList.forEach(({ url }) => {\n if (!images.has(url) && !promises.has(url)) {\n promises.set(\n url,\n (async () => {\n let data: ArrayBuffer;\n try {\n data = await load(url);\n } catch (e) {\n warnOnce(`Failed to load image: ${url} ${e}`);\n return;\n }\n\n const { width, height, type } = imageSize(new Uint8Array(data));\n if (!isSupportedType(type)) {\n warnOnce(`Not supported image type: ${type}`);\n return;\n }\n\n if (type === \"svg\") {\n try {\n const fallback = await fallbackSvg({\n buffer: data,\n width,\n height,\n });\n images.set(url, {\n type,\n width,\n height,\n data,\n fallback: fallback,\n });\n } catch (e) {\n warnOnce(`Failed to create fallback image: ${url} ${e}`);\n return;\n }\n } else {\n images.set(url, { type, width, height, data });\n }\n })(),\n );\n }\n });\n\n await Promise.all(promises.values());\n }\n\n return {\n image: (node) => {\n const data = images.get(node.url);\n if (!data) {\n return null;\n }\n return buildImage(data, node);\n },\n imageReference: (node) => {\n const def = definition(node.identifier);\n if (def == null) {\n return null;\n }\n const data = images.get(def.url);\n if (!data) {\n return null;\n }\n return buildImage(data, { alt: node.alt, title: def.title });\n },\n };\n };\n};\n"],"names":["ImageRun","visit","warnOnce","imageSize"],"mappings":";;;;;;;AAOA,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAU;AAkBnE,MAAM,UAAU,GAAG,CACjB,KAAgB,EAChB,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,CAAC,IAAI,KAAI;gBACvB,MAAM,GAAG,GAAG,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC;AACvC,gBAAA,IAAI,GAAG,IAAI,IAAI,EAAE;AACf,oBAAA,OAAO,IAAI;gBACb;gBACA,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;gBAChC,IAAI,CAAC,IAAI,EAAE;AACT,oBAAA,OAAO,IAAI;gBACb;AACA,gBAAA,OAAO,UAAU,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC;YAC9D,CAAC;SACF;AACH,IAAA,CAAC;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../src/plugins/image/index.ts"],"sourcesContent":["import { warnOnce } from \"../../utils\";\nimport type { RemarkDocxPlugin } from \"../../types\";\nimport type * as mdast from \"mdast\";\nimport { ImageRun } from \"docx\";\nimport { visit } from \"unist-util-visit\";\nimport { imageSize } from \"image-size\";\n\nconst supportedTypes = [\"png\", \"jpg\", \"gif\", \"bmp\", \"svg\"] as const;\n\ntype SupportedImageType = (typeof supportedTypes)[number];\n\ntype ImageData = Readonly<\n {\n data: ArrayBuffer;\n width: number;\n height: number;\n } & (\n | { type: Exclude<SupportedImageType, \"svg\"> }\n | {\n type: Extract<SupportedImageType, \"svg\">;\n fallback: ArrayBuffer;\n }\n )\n>;\n\nconst buildImage = (\n image: ImageData,\n node: { alt?: string | null; title?: string | null },\n) => {\n const altText =\n node.alt || node.title\n ? {\n name: \"\",\n description: node.alt ?? undefined,\n title: node.title ?? undefined,\n }\n : undefined;\n\n if (image.type === \"svg\") {\n const { type, data, width, height, fallback } = image;\n return new ImageRun({\n type: type,\n data: data,\n transformation: {\n width,\n height,\n },\n // https://github.com/dolanmiu/docx/issues/1162#issuecomment-3228368003\n fallback: { type: \"png\", data: fallback },\n altText,\n });\n }\n\n const { type, data, width, height } = image;\n return new ImageRun({\n type: type,\n data: data,\n transformation: {\n width,\n height,\n },\n altText,\n });\n};\n\nconst isSupportedType = (\n type: string | undefined,\n): type is SupportedImageType => {\n if (!type) return false;\n if ((supportedTypes as readonly string[]).includes(type)) {\n return true;\n }\n return false;\n};\n\ntype LoadFn = (url: string) => Promise<ArrayBuffer>;\n\ntype SvgToPngFn = (options: {\n buffer: ArrayBuffer;\n width: number;\n height: number;\n}) => Promise<ArrayBufferLike>;\n\nconst loadWithFetch: LoadFn = async (url) => {\n const res = await fetch(url);\n return res.arrayBuffer();\n};\n\nconst browserSvgToPng: SvgToPngFn = async ({ buffer, width, height }) => {\n const svgBlob = new Blob([buffer], { type: \"image/svg+xml\" });\n const url = URL.createObjectURL(svgBlob);\n\n try {\n const img = new Image();\n img.src = url;\n await img.decode();\n\n const dpr = window.devicePixelRatio;\n\n const canvas = document.createElement(\"canvas\");\n const scaledWidth = width * dpr;\n const scaledHeight = height * dpr;\n canvas.width = scaledWidth;\n canvas.height = scaledHeight;\n const ctx = canvas.getContext(\"2d\")!;\n ctx.drawImage(img, 0, 0, scaledWidth, scaledHeight);\n\n return new Promise<ArrayBuffer>((resolve) => {\n canvas.toBlob((blob) => {\n blob!.arrayBuffer().then(resolve);\n }, \"image/png\");\n });\n } finally {\n URL.revokeObjectURL(url);\n }\n};\n\nexport interface ImagePluginOptions {\n /**\n * A function to resolve image data from url.\n * @default {@link loadWithFetch}\n */\n load?: LoadFn;\n /**\n * A function to convert SVG to PNG. According to the docx specifications, embedding SVG images also requires including PNG.\n * @default {@link browserSvgToPng}, which handles conversion only on browser\n */\n fallbackSvg?: SvgToPngFn;\n}\n\n/**\n * A plugin to render \"image\" nodes\n */\nexport const imagePlugin = ({\n load = loadWithFetch,\n fallbackSvg = browserSvgToPng,\n}: ImagePluginOptions = {}): RemarkDocxPlugin => {\n const images = new Map<string, ImageData>();\n\n return async ({ root, definition }) => {\n const imageList: (mdast.Image | mdast.Definition)[] = [];\n visit(root, \"image\", (node) => {\n imageList.push(node);\n });\n visit(root, \"imageReference\", (node) => {\n const maybeImage = definition(node.identifier)!;\n if (maybeImage) {\n imageList.push(maybeImage);\n }\n });\n\n if (imageList.length !== 0) {\n const promises = new Map<string, Promise<void>>();\n imageList.forEach(({ url }) => {\n if (!images.has(url) && !promises.has(url)) {\n promises.set(\n url,\n (async () => {\n let data: ArrayBuffer;\n try {\n data = await load(url);\n } catch (e) {\n warnOnce(`Failed to load image: ${url} ${e}`);\n return;\n }\n\n const { width, height, type } = imageSize(new Uint8Array(data));\n if (!isSupportedType(type)) {\n warnOnce(`Not supported image type: ${type}`);\n return;\n }\n\n if (type === \"svg\") {\n try {\n const fallback = await fallbackSvg({\n buffer: data,\n width,\n height,\n });\n images.set(url, {\n type,\n width,\n height,\n data,\n fallback: fallback as ArrayBuffer,\n });\n } catch (e) {\n warnOnce(`Failed to create fallback image: ${url} ${e}`);\n return;\n }\n } else {\n images.set(url, { type, width, height, data });\n }\n })(),\n );\n }\n });\n\n await Promise.all(promises.values());\n }\n\n return {\n image: (node) => {\n const data = images.get(node.url);\n if (!data) {\n return null;\n }\n return buildImage(data, node);\n },\n imageReference: (node) => {\n const def = definition(node.identifier);\n if (def == null) {\n return null;\n }\n const data = images.get(def.url);\n if (!data) {\n return null;\n }\n return buildImage(data, { alt: node.alt, title: def.title });\n },\n };\n };\n};\n"],"names":["ImageRun","visit","warnOnce","imageSize"],"mappings":";;;;;;;AAOA,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAU;AAkBnE,MAAM,UAAU,GAAG,CACjB,KAAgB,EAChB,IAAoD,KAClD;;IACF,MAAM,OAAO,GACX,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC;AACf,UAAE;AACE,YAAA,IAAI,EAAE,EAAE;AACR,YAAA,WAAW,EAAE,CAAA,EAAA,GAAA,IAAI,CAAC,GAAG,mCAAI,SAAS;AAClC,YAAA,KAAK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,GAAG,CAAC,GAAG,CAAC;gBAChC,IAAI,CAAC,IAAI,EAAE;AACT,oBAAA,OAAO,IAAI;gBACb;AACA,gBAAA,OAAO,UAAU,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC;YAC9D,CAAC;SACF;AACH,IAAA,CAAC;AACH;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/plugins/image/index.ts"],"sourcesContent":["import { warnOnce } from \"../../utils\";\nimport type { RemarkDocxPlugin } from \"../../types\";\nimport type * as mdast from \"mdast\";\nimport { ImageRun } from \"docx\";\nimport { visit } from \"unist-util-visit\";\nimport { imageSize } from \"image-size\";\n\nconst supportedTypes = [\"png\", \"jpg\", \"gif\", \"bmp\", \"svg\"] as const;\n\ntype SupportedImageType = (typeof supportedTypes)[number];\n\ntype ImageData = Readonly<\n {\n data: ArrayBuffer;\n width: number;\n height: number;\n } & (\n | { type: Exclude<SupportedImageType, \"svg\"> }\n | {\n type: Extract<SupportedImageType, \"svg\">;\n fallback: ArrayBuffer;\n }\n )\n>;\n\nconst buildImage = (\n image: ImageData,\n node: { alt?: string | null; title?: string | null },\n) => {\n const altText =\n node.alt || node.title\n ? {\n name: \"\",\n description: node.alt ?? undefined,\n title: node.title ?? undefined,\n }\n : undefined;\n\n if (image.type === \"svg\") {\n const { type, data, width, height, fallback } = image;\n return new ImageRun({\n type: type,\n data: data,\n transformation: {\n width,\n height,\n },\n // https://github.com/dolanmiu/docx/issues/1162#issuecomment-3228368003\n fallback: { type: \"png\", data: fallback },\n altText,\n });\n }\n\n const { type, data, width, height } = image;\n return new ImageRun({\n type: type,\n data: data,\n transformation: {\n width,\n height,\n },\n altText,\n });\n};\n\nconst isSupportedType = (\n type: string | undefined,\n): type is SupportedImageType => {\n if (!type) return false;\n if ((supportedTypes as readonly string[]).includes(type)) {\n return true;\n }\n return false;\n};\n\ntype LoadFn = (url: string) => Promise<ArrayBuffer>;\n\ntype SvgToPngFn = (options: {\n buffer: ArrayBuffer;\n width: number;\n height: number;\n}) => Promise<ArrayBuffer>;\n\nconst loadWithFetch: LoadFn = async (url) => {\n const res = await fetch(url);\n return res.arrayBuffer();\n};\n\nconst browserSvgToPng: SvgToPngFn = async ({ buffer, width, height }) => {\n const svgBlob = new Blob([buffer], { type: \"image/svg+xml\" });\n const url = URL.createObjectURL(svgBlob);\n\n try {\n const img = new Image();\n img.src = url;\n await img.decode();\n\n const dpr = window.devicePixelRatio;\n\n const canvas = document.createElement(\"canvas\");\n const scaledWidth = width * dpr;\n const scaledHeight = height * dpr;\n canvas.width = scaledWidth;\n canvas.height = scaledHeight;\n const ctx = canvas.getContext(\"2d\")!;\n ctx.drawImage(img, 0, 0, scaledWidth, scaledHeight);\n\n return new Promise<ArrayBuffer>((resolve) => {\n canvas.toBlob((blob) => {\n blob!.arrayBuffer().then(resolve);\n }, \"image/png\");\n });\n } finally {\n URL.revokeObjectURL(url);\n }\n};\n\nexport interface ImagePluginOptions {\n /**\n * A function to resolve image data from url.\n * @default {@link loadWithFetch}\n */\n load?: LoadFn;\n /**\n * A function to convert SVG to PNG. According to the docx specifications, embedding SVG images also requires including PNG.\n * @default {@link browserSvgToPng}, which handles conversion only on browser\n */\n fallbackSvg?: SvgToPngFn;\n}\n\n/**\n * A plugin to render \"image\" nodes\n */\nexport const imagePlugin = ({\n load = loadWithFetch,\n fallbackSvg = browserSvgToPng,\n}: ImagePluginOptions = {}): RemarkDocxPlugin => {\n const images = new Map<string, ImageData>();\n\n return async ({ root, definition }) => {\n const imageList: (mdast.Image | mdast.Definition)[] = [];\n visit(root, \"image\", (node) => {\n imageList.push(node);\n });\n visit(root, \"imageReference\", (node) => {\n const maybeImage = definition(node.identifier)!;\n if (maybeImage) {\n imageList.push(maybeImage);\n }\n });\n\n if (imageList.length !== 0) {\n const promises = new Map<string, Promise<void>>();\n imageList.forEach(({ url }) => {\n if (!images.has(url) && !promises.has(url)) {\n promises.set(\n url,\n (async () => {\n let data: ArrayBuffer;\n try {\n data = await load(url);\n } catch (e) {\n warnOnce(`Failed to load image: ${url} ${e}`);\n return;\n }\n\n const { width, height, type } = imageSize(new Uint8Array(data));\n if (!isSupportedType(type)) {\n warnOnce(`Not supported image type: ${type}`);\n return;\n }\n\n if (type === \"svg\") {\n try {\n const fallback = await fallbackSvg({\n buffer: data,\n width,\n height,\n });\n images.set(url, {\n type,\n width,\n height,\n data,\n fallback: fallback,\n });\n } catch (e) {\n warnOnce(`Failed to create fallback image: ${url} ${e}`);\n return;\n }\n } else {\n images.set(url, { type, width, height, data });\n }\n })(),\n );\n }\n });\n\n await Promise.all(promises.values());\n }\n\n return {\n image: (node) => {\n const data = images.get(node.url);\n if (!data) {\n return null;\n }\n return buildImage(data, node);\n },\n imageReference: (node) => {\n const def = definition(node.identifier);\n if (def == null) {\n return null;\n }\n const data = images.get(def.url);\n if (!data) {\n return null;\n }\n return buildImage(data, { alt: node.alt, title: def.title });\n },\n };\n };\n};\n"],"names":[],"mappings":";;;;;AAOA,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAU;AAkBnE,MAAM,UAAU,GAAG,CACjB,KAAgB,EAChB,IAAoD,KAClD;;IACF,MAAM,OAAO,GACX,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC;AACf,UAAE;AACE,YAAA,IAAI,EAAE,EAAE;AACR,YAAA,WAAW,EAAE,CAAA,EAAA,GAAA,IAAI,CAAC,GAAG,mCAAI,SAAS;AAClC,YAAA,KAAK,EAAE,CAAA,EAAA,GAAA,IAAI,CAAC,KAAK,mCAAI,SAAS;AAC/B;UACD,SAAS;AAEf,IAAA,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,EAAE;AACxB,QAAA,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,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H,IAAA,CAAC;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/plugins/image/index.ts"],"sourcesContent":["import { warnOnce } from \"../../utils\";\nimport type { RemarkDocxPlugin } from \"../../types\";\nimport type * as mdast from \"mdast\";\nimport { ImageRun } from \"docx\";\nimport { visit } from \"unist-util-visit\";\nimport { imageSize } from \"image-size\";\n\nconst supportedTypes = [\"png\", \"jpg\", \"gif\", \"bmp\", \"svg\"] as const;\n\ntype SupportedImageType = (typeof supportedTypes)[number];\n\ntype ImageData = Readonly<\n {\n data: ArrayBuffer;\n width: number;\n height: number;\n } & (\n | { type: Exclude<SupportedImageType, \"svg\"> }\n | {\n type: Extract<SupportedImageType, \"svg\">;\n fallback: ArrayBuffer;\n }\n )\n>;\n\nconst buildImage = (\n image: ImageData,\n node: { alt?: string | null; title?: string | null },\n) => {\n const altText =\n node.alt || node.title\n ? {\n name: \"\",\n description: node.alt ?? undefined,\n title: node.title ?? undefined,\n }\n : undefined;\n\n if (image.type === \"svg\") {\n const { type, data, width, height, fallback } = image;\n return new ImageRun({\n type: type,\n data: data,\n transformation: {\n width,\n height,\n },\n // https://github.com/dolanmiu/docx/issues/1162#issuecomment-3228368003\n fallback: { type: \"png\", data: fallback },\n altText,\n });\n }\n\n const { type, data, width, height } = image;\n return new ImageRun({\n type: type,\n data: data,\n transformation: {\n width,\n height,\n },\n altText,\n });\n};\n\nconst isSupportedType = (\n type: string | undefined,\n): type is SupportedImageType => {\n if (!type) return false;\n if ((supportedTypes as readonly string[]).includes(type)) {\n return true;\n }\n return false;\n};\n\ntype LoadFn = (url: string) => Promise<ArrayBuffer>;\n\ntype SvgToPngFn = (options: {\n buffer: ArrayBuffer;\n width: number;\n height: number;\n}) => Promise<ArrayBufferLike>;\n\nconst loadWithFetch: LoadFn = async (url) => {\n const res = await fetch(url);\n return res.arrayBuffer();\n};\n\nconst browserSvgToPng: SvgToPngFn = async ({ buffer, width, height }) => {\n const svgBlob = new Blob([buffer], { type: \"image/svg+xml\" });\n const url = URL.createObjectURL(svgBlob);\n\n try {\n const img = new Image();\n img.src = url;\n await img.decode();\n\n const dpr = window.devicePixelRatio;\n\n const canvas = document.createElement(\"canvas\");\n const scaledWidth = width * dpr;\n const scaledHeight = height * dpr;\n canvas.width = scaledWidth;\n canvas.height = scaledHeight;\n const ctx = canvas.getContext(\"2d\")!;\n ctx.drawImage(img, 0, 0, scaledWidth, scaledHeight);\n\n return new Promise<ArrayBuffer>((resolve) => {\n canvas.toBlob((blob) => {\n blob!.arrayBuffer().then(resolve);\n }, \"image/png\");\n });\n } finally {\n URL.revokeObjectURL(url);\n }\n};\n\nexport interface ImagePluginOptions {\n /**\n * A function to resolve image data from url.\n * @default {@link loadWithFetch}\n */\n load?: LoadFn;\n /**\n * A function to convert SVG to PNG. According to the docx specifications, embedding SVG images also requires including PNG.\n * @default {@link browserSvgToPng}, which handles conversion only on browser\n */\n fallbackSvg?: SvgToPngFn;\n}\n\n/**\n * A plugin to render \"image\" nodes\n */\nexport const imagePlugin = ({\n load = loadWithFetch,\n fallbackSvg = browserSvgToPng,\n}: ImagePluginOptions = {}): RemarkDocxPlugin => {\n const images = new Map<string, ImageData>();\n\n return async ({ root, definition }) => {\n const imageList: (mdast.Image | mdast.Definition)[] = [];\n visit(root, \"image\", (node) => {\n imageList.push(node);\n });\n visit(root, \"imageReference\", (node) => {\n const maybeImage = definition(node.identifier)!;\n if (maybeImage) {\n imageList.push(maybeImage);\n }\n });\n\n if (imageList.length !== 0) {\n const promises = new Map<string, Promise<void>>();\n imageList.forEach(({ url }) => {\n if (!images.has(url) && !promises.has(url)) {\n promises.set(\n url,\n (async () => {\n let data: ArrayBuffer;\n try {\n data = await load(url);\n } catch (e) {\n warnOnce(`Failed to load image: ${url} ${e}`);\n return;\n }\n\n const { width, height, type } = imageSize(new Uint8Array(data));\n if (!isSupportedType(type)) {\n warnOnce(`Not supported image type: ${type}`);\n return;\n }\n\n if (type === \"svg\") {\n try {\n const fallback = await fallbackSvg({\n buffer: data,\n width,\n height,\n });\n images.set(url, {\n type,\n width,\n height,\n data,\n fallback: fallback as ArrayBuffer,\n });\n } catch (e) {\n warnOnce(`Failed to create fallback image: ${url} ${e}`);\n return;\n }\n } else {\n images.set(url, { type, width, height, data });\n }\n })(),\n );\n }\n });\n\n await Promise.all(promises.values());\n }\n\n return {\n image: (node) => {\n const data = images.get(node.url);\n if (!data) {\n return null;\n }\n return buildImage(data, node);\n },\n imageReference: (node) => {\n const def = definition(node.identifier);\n if (def == null) {\n return null;\n }\n const data = images.get(def.url);\n if (!data) {\n return null;\n }\n return buildImage(data, { alt: node.alt, title: def.title });\n },\n };\n };\n};\n"],"names":[],"mappings":";;;;;AAOA,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAU;AAkBnE,MAAM,UAAU,GAAG,CACjB,KAAgB,EAChB,IAAoD,KAClD;;IACF,MAAM,OAAO,GACX,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC;AACf,UAAE;AACE,YAAA,IAAI,EAAE,EAAE;AACR,YAAA,WAAW,EAAE,CAAA,EAAA,GAAA,IAAI,CAAC,GAAG,mCAAI,SAAS;AAClC,YAAA,KAAK,EAAE,CAAA,EAAA,GAAA,IAAI,CAAC,KAAK,mCAAI,SAAS;AAC/B;UACD,SAAS;AAEf,IAAA,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,EAAE;AACxB,QAAA,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK;QACrD,OAAO,IAAI,QAAQ,CAAC;AAClB,YAAA,IAAI,EAAE,IAAI;AACV,YAAA,IAAI,EAAE,IAAI;AACV,YAAA,cAAc,EAAE;gBACd,KAAK;gBACL,MAAM;AACP,aAAA;;YAED,QAAQ,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE;YACzC,OAAO;AAC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