remark-docx 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -57
- package/lib/index.cjs +3 -1
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +487 -220
- package/lib/index.js.map +1 -1
- package/lib/mdast-util-to-docx.d.ts +38 -1
- package/lib/plugins/mermaid/index.cjs +1 -1
- package/lib/plugins/mermaid/index.cjs.map +1 -1
- package/lib/plugins/mermaid/index.js +11 -13
- package/lib/plugins/mermaid/index.js.map +1 -1
- package/lib/plugins/shiki/index.cjs +1 -1
- package/lib/plugins/shiki/index.cjs.map +1 -1
- package/lib/plugins/shiki/index.js +6 -7
- package/lib/plugins/shiki/index.js.map +1 -1
- package/lib/types.d.ts +5 -0
- package/lib/utils-69xMoTal.cjs +2 -0
- package/lib/utils-69xMoTal.cjs.map +1 -0
- package/lib/utils-D8YPA4Mf.js +31 -0
- package/lib/utils-D8YPA4Mf.js.map +1 -0
- package/lib/utils.d.ts +9 -0
- package/package.json +18 -21
- package/lib/plugins/html/index.cjs +0 -2
- package/lib/plugins/html/index.cjs.map +0 -1
- package/lib/plugins/html/index.d.ts +0 -5
- package/lib/plugins/html/index.js +0 -11
- package/lib/plugins/html/index.js.map +0 -1
- package/lib/plugins/image/index.cjs +0 -2
- package/lib/plugins/image/index.cjs.map +0 -1
- package/lib/plugins/image/index.d.ts +0 -24
- package/lib/plugins/image/index.js +0 -89
- package/lib/plugins/image/index.js.map +0 -1
- package/lib/plugins/latex/index.cjs +0 -2
- package/lib/plugins/latex/index.cjs.map +0 -1
- package/lib/plugins/latex/index.d.ts +0 -5
- package/lib/plugins/latex/index.js +0 -75
- package/lib/plugins/latex/index.js.map +0 -1
- package/lib/utils-BBifD5si.js +0 -16
- package/lib/utils-BBifD5si.js.map +0 -1
- package/lib/utils-D_YAYv4R.cjs +0 -2
- package/lib/utils-D_YAYv4R.cjs.map +0 -1
package/lib/index.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import { n as e } from "./utils-
|
|
2
|
-
import { AlignmentType as
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { n as e, r as t, t as n } from "./utils-D8YPA4Mf.js";
|
|
2
|
+
import { AlignmentType as r, Bookmark as i, Document as a, ExternalHyperlink as o, FootnoteReferenceRun as s, HeadingLevel as c, ImageRun as l, InternalHyperlink as u, LevelFormat as d, Math as f, Packer as ee, PageBreak as te, Paragraph as p, Table as m, TableCell as h, TableOfContents as ne, TableRow as g, TextRun as _, sectionMarginDefaults as re, sectionPageSizeDefaults as ie } from "docx";
|
|
3
|
+
import { latexToMath as v } from "docx/math";
|
|
4
|
+
import { htmlToContent as y, htmlToRuns as b } from "docx/html";
|
|
5
|
+
import { imageSize as x } from "image-size";
|
|
6
|
+
import { definitions as ae } from "mdast-util-definitions";
|
|
7
|
+
import { visit as S } from "unist-util-visit";
|
|
8
|
+
import oe from "deepmerge";
|
|
9
|
+
import se from "github-slugger";
|
|
10
|
+
import { toString as ce } from "mdast-util-to-string";
|
|
11
|
+
// src/mdast-util-to-docx.ts
|
|
12
|
+
var le = "bullet", ue = "ordered", C = "task-complete", w = "task-incomplete", T = "Hyperlink", E = "TOCHeading", de = 720, D = (e) => ({
|
|
7
13
|
hanging: 400,
|
|
8
14
|
left: 400 * (e + 1)
|
|
9
|
-
}),
|
|
15
|
+
}), fe = () => {
|
|
10
16
|
let e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map();
|
|
11
17
|
return {
|
|
12
18
|
id: (t) => {
|
|
@@ -18,106 +24,231 @@ var _ = "bullet", v = "ordered", y = "task-complete", b = "task-incomplete", x =
|
|
|
18
24
|
},
|
|
19
25
|
toConfig: () => t.entries().reduce((e, [t, n]) => (e[t] = { children: n }, e), {})
|
|
20
26
|
};
|
|
21
|
-
},
|
|
22
|
-
let e = 1, t =
|
|
27
|
+
}, pe = () => {
|
|
28
|
+
let e = 1, t = /* @__PURE__ */ new Map();
|
|
23
29
|
return {
|
|
24
30
|
createId: () => {
|
|
25
|
-
let n = `${
|
|
26
|
-
return t.
|
|
31
|
+
let n = `${ue}-${e++}`;
|
|
32
|
+
return t.set(n, []), n;
|
|
27
33
|
},
|
|
28
|
-
|
|
34
|
+
setStart: (e, n, r) => {
|
|
35
|
+
t.get(e)[n] ??= r;
|
|
36
|
+
},
|
|
37
|
+
toConfig: (e) => [...t].map(([t, n]) => ({
|
|
38
|
+
reference: t,
|
|
39
|
+
levels: e.map((e, t) => n[t] == null ? e : {
|
|
40
|
+
...e,
|
|
41
|
+
start: n[t]
|
|
42
|
+
})
|
|
43
|
+
}))
|
|
29
44
|
};
|
|
30
|
-
},
|
|
45
|
+
}, me = (e, t) => e.reduceRight((e, t) => {
|
|
31
46
|
for (let [n, r] of Object.entries(t)) {
|
|
32
47
|
let t = e[n];
|
|
33
48
|
e[n] = t ? (e, n) => r(e, n) || t(e, n) : r;
|
|
34
49
|
}
|
|
35
50
|
return e;
|
|
36
|
-
}, t),
|
|
37
|
-
level:
|
|
38
|
-
format:
|
|
39
|
-
text:
|
|
40
|
-
alignment:
|
|
41
|
-
style: { paragraph: { indent:
|
|
42
|
-
})),
|
|
43
|
-
if (t.quote != null && (e.indent =
|
|
44
|
-
let { level: n, meta: r } = t.list;
|
|
45
|
-
e.numbering = r.type === "task" ? {
|
|
46
|
-
reference: r.checked ?
|
|
51
|
+
}, t), O = (e) => e.map(({ format: e, text: t }, n) => ({
|
|
52
|
+
level: n,
|
|
53
|
+
format: d[e],
|
|
54
|
+
text: t,
|
|
55
|
+
alignment: r.LEFT,
|
|
56
|
+
style: { paragraph: { indent: D(n) } }
|
|
57
|
+
})), k = (e, t) => {
|
|
58
|
+
if (t.quote != null && (e.indent = D(t.quote + 1)), t.list) {
|
|
59
|
+
let { level: n, meta: r, continuation: i } = t.list;
|
|
60
|
+
i ? e.indent = { left: D(t.quote == null ? n : t.quote + 1).left } : e.numbering = r.type === "task" ? {
|
|
61
|
+
reference: r.checked ? C : w,
|
|
47
62
|
level: n
|
|
48
63
|
} : r.type === "ordered" ? {
|
|
49
64
|
reference: r.reference,
|
|
50
65
|
level: n
|
|
51
66
|
} : {
|
|
52
|
-
reference:
|
|
67
|
+
reference: le,
|
|
53
68
|
level: n
|
|
54
69
|
};
|
|
55
70
|
}
|
|
56
|
-
return t.rtl && (e.bidirectional = !0), new
|
|
57
|
-
},
|
|
58
|
-
let
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
71
|
+
return t.rtl && (e.bidirectional = !0), new p(e);
|
|
72
|
+
}, he = async (e) => {
|
|
73
|
+
let t = await fetch(e);
|
|
74
|
+
if (!t.ok) throw Error(`${t.status} ${t.statusText}`);
|
|
75
|
+
return t.arrayBuffer();
|
|
76
|
+
}, A = 100, j = async (n, r, i, a) => {
|
|
77
|
+
let o;
|
|
78
|
+
try {
|
|
79
|
+
let e = await i(n, r);
|
|
80
|
+
o = ArrayBuffer.isView(e) ? new Uint8Array(e.buffer, e.byteOffset, e.byteLength).slice().buffer : e;
|
|
81
|
+
} catch (e) {
|
|
82
|
+
t(`Failed to load image: ${n} ${e}`);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
let s;
|
|
86
|
+
try {
|
|
87
|
+
s = x(new Uint8Array(o));
|
|
88
|
+
} catch (e) {
|
|
89
|
+
t(`Failed to detect image type: ${n} ${e}`);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
let { width: c, height: l } = s, u = s.type;
|
|
93
|
+
if (e(u) && u !== "svg") return {
|
|
94
|
+
type: u,
|
|
95
|
+
width: c,
|
|
96
|
+
height: l,
|
|
97
|
+
data: o
|
|
98
|
+
};
|
|
99
|
+
if (!a) {
|
|
100
|
+
t(`toPng option is required to embed ${u}: ${n}`);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
let d;
|
|
104
|
+
try {
|
|
105
|
+
d = await a({
|
|
106
|
+
buffer: o,
|
|
107
|
+
width: c,
|
|
108
|
+
height: l
|
|
109
|
+
});
|
|
110
|
+
} catch (e) {
|
|
111
|
+
t(`Failed to convert image to png: ${n} ${e}`);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
return u === "svg" ? {
|
|
115
|
+
type: u,
|
|
116
|
+
width: c,
|
|
117
|
+
height: l,
|
|
118
|
+
data: o,
|
|
119
|
+
fallback: d
|
|
120
|
+
} : {
|
|
121
|
+
type: "png",
|
|
122
|
+
width: c,
|
|
123
|
+
height: l,
|
|
124
|
+
data: d
|
|
125
|
+
};
|
|
126
|
+
}, ge = async (e, t, n, r, i, { load: a = he, toPng: o }) => {
|
|
127
|
+
let s = /* @__PURE__ */ new Set();
|
|
128
|
+
S(e, (e) => {
|
|
129
|
+
if (e.type === "image") s.add(e.url);
|
|
130
|
+
else if (e.type === "imageReference") {
|
|
131
|
+
let n = t(e.identifier);
|
|
132
|
+
n && s.add(n.url);
|
|
133
|
+
}
|
|
134
|
+
}), await Promise.all(Array.from(s, async (e) => {
|
|
135
|
+
if (n.has(e)) return;
|
|
136
|
+
let t = `${i.dirname}\0${e}`, s = r.get(t) ?? await j(e, i, a, o);
|
|
137
|
+
s && (r.set(t, s), n.has(e) || n.set(e, s));
|
|
138
|
+
}));
|
|
139
|
+
for (let e of r.keys()) {
|
|
140
|
+
if (r.size <= A) break;
|
|
141
|
+
r.delete(e);
|
|
142
|
+
}
|
|
143
|
+
}, M = async (e, { plugins: n = [], image: r, title: i, subject: o, creator: s, keywords: c, description: l, styles: u, size: d, margin: f, orientation: m, columns: h, spacing: g, direction: _, background: v, thematicBreak: y = "page", toc: b, orderedListFormat: x } = {}, ue, T) => {
|
|
144
|
+
let D = ae(e), he = new se(), A = /* @__PURE__ */ new Map(), j = /* @__PURE__ */ new Map();
|
|
145
|
+
S(e, (e) => {
|
|
146
|
+
if (e.type === "heading") {
|
|
147
|
+
let t = ce(e, {
|
|
148
|
+
includeHtml: !1,
|
|
149
|
+
includeImageAlt: !1
|
|
150
|
+
});
|
|
151
|
+
A.set(e, he.slug(t));
|
|
152
|
+
} else if (e.type === "link" || e.type === "linkReference") {
|
|
153
|
+
let t = e.type === "link" ? e.url : D(e.identifier)?.url;
|
|
154
|
+
if (t?.startsWith("#")) try {
|
|
155
|
+
j.set(t, decodeURIComponent(t.slice(1)));
|
|
156
|
+
} catch {}
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
let M = new Set(j.values()), I = /* @__PURE__ */ new Map(), L = /* @__PURE__ */ new Map();
|
|
160
|
+
for (let [e, t] of A) if (M.has(t)) {
|
|
161
|
+
let n = `md_heading_${I.size + 1}`;
|
|
162
|
+
I.set(t, n), L.set(e, n);
|
|
163
|
+
}
|
|
164
|
+
for (let [e, t] of j) {
|
|
165
|
+
let n = I.get(t) ?? (/^(top)?$/i.test(t) ? "_top" : void 0);
|
|
166
|
+
n && L.set(e, n);
|
|
167
|
+
}
|
|
168
|
+
let R = pe(), z = fe(), B = /* @__PURE__ */ new WeakSet(), V = /* @__PURE__ */ new WeakMap();
|
|
169
|
+
S(e, (e) => {
|
|
170
|
+
if (!("children" in e) || Fe.has(e.type) || !e.children.some((e) => e.type === "html")) return;
|
|
171
|
+
let t = Ie(e.children);
|
|
172
|
+
for (let e of t) e.type === "html" && B.add(e);
|
|
173
|
+
V.set(e.children, t);
|
|
174
|
+
});
|
|
175
|
+
let U = /* @__PURE__ */ new Map(), ze = {
|
|
176
|
+
root: e,
|
|
177
|
+
images: U,
|
|
178
|
+
definition: D
|
|
179
|
+
}, [Be] = await Promise.all([Promise.all(n.map((e) => e(ze))), r && ge(e, D, U, ue, T, r === !0 ? {} : r)]), Ve = me(Be, {
|
|
180
|
+
paragraph: _e,
|
|
181
|
+
heading: ve,
|
|
182
|
+
thematicBreak: ye,
|
|
183
|
+
blockquote: be,
|
|
184
|
+
list: xe,
|
|
185
|
+
listItem: Se,
|
|
186
|
+
table: Ce,
|
|
187
|
+
tableRow: H,
|
|
188
|
+
tableCell: H,
|
|
189
|
+
html: (e, t) => Le(e, t, B.has(e)),
|
|
190
|
+
code: Re,
|
|
191
|
+
definition: H,
|
|
192
|
+
footnoteDefinition: je,
|
|
193
|
+
text: N,
|
|
194
|
+
emphasis: we,
|
|
195
|
+
strong: Te,
|
|
196
|
+
delete: Ee,
|
|
197
|
+
inlineCode: De,
|
|
198
|
+
break: Oe,
|
|
199
|
+
link: P,
|
|
200
|
+
linkReference: ke,
|
|
201
|
+
image: F,
|
|
202
|
+
imageReference: Ae,
|
|
203
|
+
footnoteReference: Me,
|
|
204
|
+
math: Ne,
|
|
205
|
+
inlineMath: Pe
|
|
206
|
+
}), W = (e, n) => {
|
|
207
|
+
let r = Ve[e.type];
|
|
208
|
+
if (!r) return t(`${e.type} node is not supported without plugins.`), null;
|
|
209
|
+
let i = r(e, n);
|
|
93
210
|
return i ? Array.isArray(i) ? i : [i] : null;
|
|
94
|
-
}, { WIDTH:
|
|
95
|
-
d && (d.width != null && (
|
|
96
|
-
let { TOP:
|
|
97
|
-
f && (f.top != null && (
|
|
98
|
-
let
|
|
211
|
+
}, { WIDTH: G, HEIGHT: K } = ie;
|
|
212
|
+
d && (d.width != null && (G = d.width), d.height != null && (K = d.height));
|
|
213
|
+
let { TOP: q, LEFT: J, BOTTOM: Y, RIGHT: X } = re;
|
|
214
|
+
f && (f.top != null && (q = f.top), f.left != null && (J = f.left), f.bottom != null && (Y = f.bottom), f.right != null && (X = f.right));
|
|
215
|
+
let [He, Ue] = m === "landscape" ? [K, G] : [G, K], Z = h || 1, We = {
|
|
99
216
|
render(e, t) {
|
|
100
217
|
let n = [];
|
|
101
|
-
for (let r of e) {
|
|
102
|
-
let e =
|
|
218
|
+
for (let r of V.get(e) ?? e) {
|
|
219
|
+
let e = W(r, t ?? this);
|
|
103
220
|
e && n.push(...e);
|
|
104
221
|
}
|
|
105
222
|
return n;
|
|
106
223
|
},
|
|
107
|
-
width:
|
|
224
|
+
width: (He - J - X - de * (Z - 1)) / Z,
|
|
225
|
+
height: Ue - q - Y,
|
|
108
226
|
style: {},
|
|
109
|
-
thematicBreak:
|
|
110
|
-
rtl:
|
|
111
|
-
definition:
|
|
112
|
-
images:
|
|
113
|
-
footnote:
|
|
114
|
-
orderedId:
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
227
|
+
thematicBreak: y,
|
|
228
|
+
rtl: _ === "rtl",
|
|
229
|
+
definition: D,
|
|
230
|
+
images: U,
|
|
231
|
+
footnote: z,
|
|
232
|
+
orderedId: R.createId,
|
|
233
|
+
orderedStart: R.setStart,
|
|
234
|
+
bookmarks: L
|
|
235
|
+
}, Q = [[]];
|
|
236
|
+
for (let t of e.children) {
|
|
237
|
+
let e = W(t, We);
|
|
238
|
+
e && (e.length ? Q[Q.length - 1].push(...e) : Q.push([]));
|
|
119
239
|
}
|
|
120
|
-
let
|
|
240
|
+
let $ = b === !0 ? {} : b || void 0;
|
|
241
|
+
if ($) {
|
|
242
|
+
let { title: e, depth: t = 3 } = $, n = Q[0], r = n.length > 0;
|
|
243
|
+
n.unshift(...e ? [k({
|
|
244
|
+
style: E,
|
|
245
|
+
text: e
|
|
246
|
+
}, We)] : [], new ne(void 0, {
|
|
247
|
+
headingStyleRange: `1-${t}`,
|
|
248
|
+
hyperlink: !0
|
|
249
|
+
}), ...r ? [new p({ children: [new te()] })] : []);
|
|
250
|
+
}
|
|
251
|
+
let Ge = O(x ?? [
|
|
121
252
|
{
|
|
122
253
|
text: "%1.",
|
|
123
254
|
format: "DECIMAL"
|
|
@@ -142,39 +273,56 @@ var _ = "bullet", v = "ordered", y = "task-complete", b = "task-incomplete", x =
|
|
|
142
273
|
text: "%6.",
|
|
143
274
|
format: "DECIMAL"
|
|
144
275
|
}
|
|
145
|
-
]),
|
|
146
|
-
column:
|
|
276
|
+
]), Ke = {
|
|
277
|
+
column: h ? { count: h } : void 0,
|
|
147
278
|
page: {
|
|
148
|
-
textDirection:
|
|
279
|
+
textDirection: _ === "vertical" ? "tbRl" : void 0,
|
|
149
280
|
size: {
|
|
150
|
-
width:
|
|
151
|
-
height:
|
|
152
|
-
orientation:
|
|
281
|
+
width: G,
|
|
282
|
+
height: K,
|
|
283
|
+
orientation: m
|
|
153
284
|
},
|
|
154
285
|
margin: {
|
|
155
|
-
top:
|
|
156
|
-
left:
|
|
157
|
-
bottom:
|
|
158
|
-
right:
|
|
286
|
+
top: q,
|
|
287
|
+
left: J,
|
|
288
|
+
bottom: Y,
|
|
289
|
+
right: X
|
|
159
290
|
}
|
|
160
291
|
}
|
|
161
|
-
},
|
|
292
|
+
}, qe = new a({
|
|
162
293
|
title: i,
|
|
163
|
-
subject:
|
|
164
|
-
creator:
|
|
165
|
-
keywords:
|
|
294
|
+
subject: o,
|
|
295
|
+
creator: s,
|
|
296
|
+
keywords: c,
|
|
166
297
|
description: l,
|
|
167
|
-
styles:
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
298
|
+
styles: oe({
|
|
299
|
+
default: {
|
|
300
|
+
document: { paragraph: { spacing: g ? { after: g } : void 0 } },
|
|
301
|
+
heading1: { paragraph: { outlineLevel: 0 } },
|
|
302
|
+
heading2: { paragraph: { outlineLevel: 1 } },
|
|
303
|
+
heading3: { paragraph: { outlineLevel: 2 } },
|
|
304
|
+
heading4: { paragraph: { outlineLevel: 3 } },
|
|
305
|
+
heading5: { paragraph: { outlineLevel: 4 } },
|
|
306
|
+
heading6: { paragraph: { outlineLevel: 5 } }
|
|
307
|
+
},
|
|
308
|
+
paragraphStyles: $?.title && !u?.paragraphStyles?.some((e) => e.id === E) ? [{
|
|
309
|
+
id: E,
|
|
310
|
+
name: "TOC Heading",
|
|
311
|
+
basedOn: "Heading1",
|
|
312
|
+
paragraph: { outlineLevel: 9 }
|
|
313
|
+
}] : []
|
|
314
|
+
}, u || {}),
|
|
315
|
+
background: v,
|
|
316
|
+
features: $ ? { updateFields: !0 } : void 0,
|
|
317
|
+
sections: Q.filter((e) => e.length).map((e) => ({
|
|
318
|
+
properties: Ke,
|
|
171
319
|
children: e
|
|
172
320
|
})),
|
|
173
|
-
footnotes:
|
|
321
|
+
footnotes: z.toConfig(),
|
|
174
322
|
numbering: { config: [
|
|
175
323
|
{
|
|
176
|
-
reference:
|
|
177
|
-
levels:
|
|
324
|
+
reference: le,
|
|
325
|
+
levels: O([
|
|
178
326
|
{
|
|
179
327
|
text: "●",
|
|
180
328
|
format: "BULLET"
|
|
@@ -201,13 +349,10 @@ var _ = "bullet", v = "ordered", y = "task-complete", b = "task-incomplete", x =
|
|
|
201
349
|
}
|
|
202
350
|
])
|
|
203
351
|
},
|
|
204
|
-
...
|
|
205
|
-
reference: e,
|
|
206
|
-
levels: _e
|
|
207
|
-
})),
|
|
352
|
+
...R.toConfig(Ge),
|
|
208
353
|
{
|
|
209
|
-
reference:
|
|
210
|
-
levels:
|
|
354
|
+
reference: C,
|
|
355
|
+
levels: O([
|
|
211
356
|
{
|
|
212
357
|
text: "☑",
|
|
213
358
|
format: "BULLET"
|
|
@@ -235,8 +380,8 @@ var _ = "bullet", v = "ordered", y = "task-complete", b = "task-incomplete", x =
|
|
|
235
380
|
])
|
|
236
381
|
},
|
|
237
382
|
{
|
|
238
|
-
reference:
|
|
239
|
-
levels:
|
|
383
|
+
reference: w,
|
|
384
|
+
levels: O([
|
|
240
385
|
{
|
|
241
386
|
text: "☐",
|
|
242
387
|
format: "BULLET"
|
|
@@ -264,118 +409,122 @@ var _ = "bullet", v = "ordered", y = "task-complete", b = "task-incomplete", x =
|
|
|
264
409
|
])
|
|
265
410
|
}
|
|
266
411
|
] }
|
|
267
|
-
}),
|
|
268
|
-
return
|
|
269
|
-
},
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
r = "HEADING_3";
|
|
283
|
-
break;
|
|
284
|
-
case 5:
|
|
285
|
-
r = "HEADING_4";
|
|
286
|
-
break;
|
|
287
|
-
case 6: r = "HEADING_5";
|
|
288
|
-
}
|
|
289
|
-
return w({
|
|
290
|
-
heading: a[r],
|
|
291
|
-
outlineLevel: t - 1,
|
|
292
|
-
children: n.render(e)
|
|
293
|
-
}, n);
|
|
294
|
-
}, D = (e, t) => {
|
|
412
|
+
}), Je = "default-bullet-numbering", Ye = qe.numbering;
|
|
413
|
+
return Ye.abstractNumberingMap.delete(Je), Ye.concreteNumberingMap.delete(Je), new Uint8Array(await ee.toArrayBuffer(qe));
|
|
414
|
+
}, _e = ({ children: e }, t) => k({
|
|
415
|
+
children: t.render(e),
|
|
416
|
+
contextualSpacing: t.list?.tight && !t.list.continuation || void 0
|
|
417
|
+
}, t), ve = (e, t) => {
|
|
418
|
+
let n = t.bookmarks.get(e), r = t.render(e.children);
|
|
419
|
+
return k({
|
|
420
|
+
heading: c[`HEADING_${e.depth}`],
|
|
421
|
+
children: n ? [new i({
|
|
422
|
+
id: n,
|
|
423
|
+
children: r
|
|
424
|
+
})] : r
|
|
425
|
+
}, t);
|
|
426
|
+
}, ye = (e, t) => {
|
|
295
427
|
switch (t.thematicBreak) {
|
|
296
|
-
case "page": return new
|
|
428
|
+
case "page": return new p({ children: [new te()] });
|
|
297
429
|
case "section": return [];
|
|
298
|
-
case "line": return new
|
|
430
|
+
case "line": return new p({ thematicBreak: !0 });
|
|
299
431
|
}
|
|
300
|
-
},
|
|
432
|
+
}, be = ({ children: e }, t) => t.render(e, {
|
|
301
433
|
...t,
|
|
302
434
|
quote: t.quote == null ? 0 : t.quote + 1
|
|
303
|
-
}),
|
|
304
|
-
let
|
|
305
|
-
|
|
306
|
-
type
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
435
|
+
}), xe = ({ children: e, ordered: t, start: n, spread: r }, i) => {
|
|
436
|
+
let a = i.list, o = a ? a.level + 1 : 0, s;
|
|
437
|
+
if (t) {
|
|
438
|
+
let e = a && a.meta.type === "ordered" ? a.meta.reference : i.orderedId();
|
|
439
|
+
n != null && i.orderedStart(e, o, n), s = {
|
|
440
|
+
type: "ordered",
|
|
441
|
+
reference: e
|
|
442
|
+
};
|
|
443
|
+
} else s = { type: "bullet" };
|
|
444
|
+
return i.render(e, {
|
|
445
|
+
...i,
|
|
310
446
|
list: {
|
|
311
|
-
level:
|
|
312
|
-
meta:
|
|
447
|
+
level: o,
|
|
448
|
+
meta: s,
|
|
449
|
+
tight: !r && !e.some((e) => e.spread)
|
|
313
450
|
}
|
|
314
451
|
});
|
|
315
|
-
},
|
|
452
|
+
}, Se = ({ children: e, checked: t }, n) => {
|
|
316
453
|
let r = n.list;
|
|
317
454
|
return r && t != null && (r = {
|
|
318
|
-
|
|
455
|
+
...r,
|
|
319
456
|
meta: {
|
|
320
457
|
type: "task",
|
|
321
458
|
checked: t
|
|
322
459
|
}
|
|
323
|
-
}), n.render(e, {
|
|
460
|
+
}), e.flatMap((e, t) => n.render([e], {
|
|
324
461
|
...n,
|
|
325
|
-
list: r
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
462
|
+
list: r && t > 0 ? {
|
|
463
|
+
...r,
|
|
464
|
+
continuation: !0
|
|
465
|
+
} : r
|
|
466
|
+
}));
|
|
467
|
+
}, Ce = ({ children: e, align: t }, n) => {
|
|
468
|
+
let i = t?.map((e) => {
|
|
329
469
|
switch (e) {
|
|
330
470
|
case "left": return "LEFT";
|
|
331
471
|
case "right": return "RIGHT";
|
|
332
472
|
case "center": return "CENTER";
|
|
333
|
-
default: return
|
|
473
|
+
default: return;
|
|
334
474
|
}
|
|
335
|
-
}), a = e[0].children.length, o =
|
|
475
|
+
}), a = e[0].children.length, o = n.width / a, s = {
|
|
336
476
|
columnWidths: Array.from({ length: a }).map(() => o),
|
|
337
|
-
rows: e.map((e
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
477
|
+
rows: e.map((e, t) => new g({
|
|
478
|
+
tableHeader: t === 0 || void 0,
|
|
479
|
+
children: e.children.map((e, t) => {
|
|
480
|
+
let a = i?.[t];
|
|
481
|
+
return new h({
|
|
482
|
+
width: {
|
|
483
|
+
size: o,
|
|
484
|
+
type: "dxa"
|
|
485
|
+
},
|
|
486
|
+
children: [new p({
|
|
487
|
+
alignment: a ? r[a] : void 0,
|
|
488
|
+
children: n.render(e.children, {
|
|
489
|
+
...n,
|
|
490
|
+
width: o - 216,
|
|
491
|
+
quote: void 0,
|
|
492
|
+
list: void 0,
|
|
493
|
+
rtl: void 0
|
|
494
|
+
})
|
|
495
|
+
})]
|
|
496
|
+
});
|
|
497
|
+
})
|
|
498
|
+
}))
|
|
350
499
|
};
|
|
351
|
-
return
|
|
352
|
-
},
|
|
500
|
+
return n.rtl && (s.visuallyRightToLeft = !0), new m(s);
|
|
501
|
+
}, N = ({ value: e }, { style: t, rtl: n }) => {
|
|
353
502
|
let r = {
|
|
354
503
|
text: e,
|
|
355
504
|
bold: t.bold,
|
|
356
505
|
italics: t.italic,
|
|
357
506
|
strike: t.strike
|
|
358
507
|
};
|
|
359
|
-
return t.inlineCode && (r.highlight = "lightGray"), t.link && (r.style =
|
|
360
|
-
},
|
|
508
|
+
return t.inlineCode && (r.highlight = "lightGray"), t.link && (r.style = T), n && (r.rightToLeft = !0), new _(r);
|
|
509
|
+
}, we = ({ children: e }, t) => t.render(e, {
|
|
361
510
|
...t,
|
|
362
511
|
style: {
|
|
363
512
|
...t.style,
|
|
364
513
|
italic: !0
|
|
365
514
|
}
|
|
366
|
-
}),
|
|
515
|
+
}), Te = ({ children: e }, t) => t.render(e, {
|
|
367
516
|
...t,
|
|
368
517
|
style: {
|
|
369
518
|
...t.style,
|
|
370
519
|
bold: !0
|
|
371
520
|
}
|
|
372
|
-
}),
|
|
521
|
+
}), Ee = ({ children: e }, t) => t.render(e, {
|
|
373
522
|
...t,
|
|
374
523
|
style: {
|
|
375
524
|
...t.style,
|
|
376
525
|
strike: !0
|
|
377
526
|
}
|
|
378
|
-
}),
|
|
527
|
+
}), De = ({ value: e }, t) => N({
|
|
379
528
|
type: "text",
|
|
380
529
|
value: e
|
|
381
530
|
}, {
|
|
@@ -384,85 +533,203 @@ var _ = "bullet", v = "ordered", y = "task-complete", b = "task-incomplete", x =
|
|
|
384
533
|
...t.style,
|
|
385
534
|
inlineCode: !0
|
|
386
535
|
}
|
|
387
|
-
}),
|
|
536
|
+
}), Oe = () => new _({
|
|
388
537
|
text: "",
|
|
389
538
|
break: 1
|
|
390
|
-
}),
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
539
|
+
}), P = ({ children: e, url: t }, n) => {
|
|
540
|
+
if (t.startsWith("#")) {
|
|
541
|
+
let r = n.bookmarks.get(t);
|
|
542
|
+
return r ? new u({
|
|
543
|
+
anchor: r,
|
|
544
|
+
children: n.render(e, {
|
|
545
|
+
...n,
|
|
546
|
+
style: {
|
|
547
|
+
...n.style,
|
|
548
|
+
link: !0
|
|
549
|
+
}
|
|
550
|
+
})
|
|
551
|
+
}) : n.render(e);
|
|
552
|
+
}
|
|
553
|
+
return new o({
|
|
554
|
+
link: t,
|
|
555
|
+
children: n.render(e, {
|
|
556
|
+
...n,
|
|
557
|
+
style: {
|
|
558
|
+
...n.style,
|
|
559
|
+
link: !0
|
|
560
|
+
}
|
|
561
|
+
})
|
|
562
|
+
});
|
|
563
|
+
}, ke = ({ children: e, identifier: t }, n) => {
|
|
400
564
|
let r = n.definition(t);
|
|
401
|
-
return r == null ? n.render(e) :
|
|
565
|
+
return r == null ? n.render(e) : P({
|
|
402
566
|
type: "link",
|
|
403
567
|
children: e,
|
|
404
568
|
url: r.url
|
|
405
569
|
}, n);
|
|
406
|
-
},
|
|
570
|
+
}, F = (e, t) => {
|
|
407
571
|
let n = t.images.get(e.url);
|
|
408
|
-
if (!n) return
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
}
|
|
414
|
-
let s = e.alt || e.title ? {
|
|
572
|
+
if (!n) return e.alt ? N({
|
|
573
|
+
type: "text",
|
|
574
|
+
value: e.alt
|
|
575
|
+
}, t) : null;
|
|
576
|
+
let r = I(t), i = Math.min(1, r.width / n.width, r.height / n.height), a = n.width * i, o = n.height * i, s = e.alt || e.title ? {
|
|
415
577
|
name: "",
|
|
416
578
|
description: e.alt ?? void 0,
|
|
417
579
|
title: e.title ?? void 0
|
|
418
580
|
} : void 0;
|
|
419
581
|
if (n.type === "svg") {
|
|
420
|
-
let { type: e, data: t, fallback:
|
|
421
|
-
return new
|
|
582
|
+
let { type: e, data: t, fallback: r } = n;
|
|
583
|
+
return new l({
|
|
422
584
|
type: e,
|
|
423
585
|
data: t,
|
|
424
586
|
transformation: {
|
|
425
|
-
width:
|
|
426
|
-
height:
|
|
587
|
+
width: a,
|
|
588
|
+
height: o
|
|
427
589
|
},
|
|
428
590
|
fallback: {
|
|
429
591
|
type: "png",
|
|
430
|
-
data:
|
|
592
|
+
data: r
|
|
431
593
|
},
|
|
432
594
|
altText: s
|
|
433
595
|
});
|
|
434
596
|
}
|
|
435
|
-
let { type: c, data:
|
|
436
|
-
return new
|
|
597
|
+
let { type: c, data: u } = n;
|
|
598
|
+
return new l({
|
|
437
599
|
type: c,
|
|
438
|
-
data:
|
|
600
|
+
data: u,
|
|
439
601
|
transformation: {
|
|
440
|
-
width:
|
|
441
|
-
height:
|
|
602
|
+
width: a,
|
|
603
|
+
height: o
|
|
442
604
|
},
|
|
443
605
|
altText: s
|
|
444
606
|
});
|
|
445
|
-
},
|
|
607
|
+
}, I = (e) => {
|
|
608
|
+
let t = e.quote == null ? e.list?.level : e.quote + 1, n = t == null ? 0 : D(t).left;
|
|
609
|
+
return {
|
|
610
|
+
width: (e.width - n) / 1440 * 96,
|
|
611
|
+
height: e.height / 1440 * 96
|
|
612
|
+
};
|
|
613
|
+
}, Ae = (e, t) => {
|
|
446
614
|
let n = t.definition(e.identifier);
|
|
447
|
-
return n == null ? null :
|
|
615
|
+
return n == null ? null : F({
|
|
448
616
|
type: "image",
|
|
449
617
|
url: n.url,
|
|
450
618
|
alt: e.alt,
|
|
451
619
|
title: n.title
|
|
452
620
|
}, t);
|
|
453
|
-
},
|
|
454
|
-
let r = n.render(e).filter((e) => e instanceof
|
|
621
|
+
}, je = ({ children: e, identifier: t }, n) => {
|
|
622
|
+
let r = n.render(e).filter((e) => e instanceof p);
|
|
455
623
|
return n.footnote.set(n.footnote.id(t), r), null;
|
|
456
|
-
},
|
|
624
|
+
}, Me = ({ identifier: e }, t) => new s(t.footnote.id(e)), L = (e) => {
|
|
625
|
+
try {
|
|
626
|
+
return new f({ children: v(e) });
|
|
627
|
+
} catch (e) {
|
|
628
|
+
return t("Failed to convert LaTeX to a Word equation, falling back to text.\n" + (e instanceof Error ? e.message : String(e))), null;
|
|
629
|
+
}
|
|
630
|
+
}, Ne = ({ value: e }, t) => {
|
|
631
|
+
let n = L(e);
|
|
632
|
+
return k(n ? { children: [n] } : { children: e.split(/\r?\n/).map((e, t) => new _({
|
|
633
|
+
text: e,
|
|
634
|
+
break: t === 0 ? void 0 : 1
|
|
635
|
+
})) }, t);
|
|
636
|
+
}, Pe = ({ value: e }, t) => L(e) || N({
|
|
457
637
|
type: "text",
|
|
458
|
-
value:
|
|
459
|
-
},
|
|
638
|
+
value: e
|
|
639
|
+
}, t), Fe = /* @__PURE__ */ new Set([
|
|
640
|
+
"root",
|
|
641
|
+
"blockquote",
|
|
642
|
+
"listItem",
|
|
643
|
+
"footnoteDefinition"
|
|
644
|
+
]), R = /* @__PURE__ */ new Set([
|
|
645
|
+
"area",
|
|
646
|
+
"base",
|
|
647
|
+
"br",
|
|
648
|
+
"col",
|
|
649
|
+
"embed",
|
|
650
|
+
"hr",
|
|
651
|
+
"img",
|
|
652
|
+
"input",
|
|
653
|
+
"link",
|
|
654
|
+
"meta",
|
|
655
|
+
"source",
|
|
656
|
+
"track",
|
|
657
|
+
"wbr"
|
|
658
|
+
]), z = (e) => {
|
|
659
|
+
let t = /^<(\/?)([a-zA-Z][a-zA-Z0-9-]*)/.exec(e);
|
|
660
|
+
if (!t) return null;
|
|
661
|
+
let n = t[2].toLowerCase();
|
|
662
|
+
return R.has(n) ? null : {
|
|
663
|
+
name: n,
|
|
664
|
+
closing: !!t[1]
|
|
665
|
+
};
|
|
666
|
+
}, Ie = (e) => {
|
|
667
|
+
let t = [];
|
|
668
|
+
for (let n = 0; n < e.length; n++) {
|
|
669
|
+
let r = e[n];
|
|
670
|
+
if (r.type !== "html") {
|
|
671
|
+
t.push(r);
|
|
672
|
+
continue;
|
|
673
|
+
}
|
|
674
|
+
let i = z(r.value);
|
|
675
|
+
if (i && !i.closing) {
|
|
676
|
+
let a = [i.name], o = r.value, s, c, l = n + 1;
|
|
677
|
+
for (; l < e.length && a.length; l++) {
|
|
678
|
+
let t = e[l];
|
|
679
|
+
if (t.type === "text") o += t.value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
680
|
+
else if (t.type === "break") o += "<br>";
|
|
681
|
+
else if (t.type === "html") {
|
|
682
|
+
o += t.value;
|
|
683
|
+
let e = z(t.value);
|
|
684
|
+
if (e) {
|
|
685
|
+
if (!e.closing) a.push(e.name);
|
|
686
|
+
else {
|
|
687
|
+
let t = a.lastIndexOf(e.name);
|
|
688
|
+
t !== -1 && (a.length = t);
|
|
689
|
+
}
|
|
690
|
+
continue;
|
|
691
|
+
}
|
|
692
|
+
} else break;
|
|
693
|
+
s ??= t, c = t;
|
|
694
|
+
}
|
|
695
|
+
if (!a.length) {
|
|
696
|
+
let e = {
|
|
697
|
+
type: "text",
|
|
698
|
+
value: " "
|
|
699
|
+
};
|
|
700
|
+
s?.type === "text" && /^\s/.test(s.value) && t.push(e), t.push({
|
|
701
|
+
type: "html",
|
|
702
|
+
value: o
|
|
703
|
+
}), c?.type === "text" && /\s$/.test(c.value) && t.push(e), n = l - 1;
|
|
704
|
+
continue;
|
|
705
|
+
}
|
|
706
|
+
} else if (/^<br[\s/>]/i.test(r.value)) {
|
|
707
|
+
t.push({ type: "break" });
|
|
708
|
+
continue;
|
|
709
|
+
}
|
|
710
|
+
t.push(r);
|
|
711
|
+
}
|
|
712
|
+
return t;
|
|
713
|
+
}, B = "remark-docx-link", V = {
|
|
714
|
+
styleMap: { [`.${B}`]: T },
|
|
715
|
+
onWarning: ({ message: e }) => {
|
|
716
|
+
t("Failed to convert some HTML to Word as is, leaving it out or changing it.\n" + e);
|
|
717
|
+
}
|
|
718
|
+
}, Le = ({ value: e }, t, n) => {
|
|
719
|
+
let { style: r, rtl: i } = t;
|
|
720
|
+
r.bold && (e = `<b>${e}</b>`), r.italic && (e = `<i>${e}</i>`), r.strike && (e = `<s>${e}</s>`), r.link && (e = `<span class="${B}">${e}</span>`), i && (e = `<div dir="rtl">${e}</div>`);
|
|
721
|
+
let a = !n && (t.quote != null || !!t.list), o = {
|
|
722
|
+
...V,
|
|
723
|
+
maxImageWidth: I(t).width
|
|
724
|
+
}, s = n || a ? b(e, o) : y(e, o);
|
|
725
|
+
return s.length ? a ? k({ children: s }, t) : s : null;
|
|
726
|
+
}, H = () => null, Re = (e, n) => (t(`${e.type} node is not supported without plugins, falling back to text.`), k({ children: e.value.split(/\r?\n/).map((e, t) => new _({
|
|
460
727
|
text: e,
|
|
461
728
|
break: t === 0 ? void 0 : 1
|
|
462
|
-
})) }, n)),
|
|
463
|
-
|
|
729
|
+
})) }, n)), U = function(e) {
|
|
730
|
+
let t = /* @__PURE__ */ new Map();
|
|
731
|
+
return this.compiler = (e, t) => (t.path && (t.extname = ".docx"), t.data.docx), async (n, r) => (r.data.docx = await M(n, e, t, r), n);
|
|
464
732
|
};
|
|
465
|
-
|
|
466
|
-
export { z as default };
|
|
733
|
+
export { n as browserToPng, U as default };
|
|
467
734
|
|
|
468
735
|
//# sourceMappingURL=index.js.map
|