@langeditor/plugin-docx 1.0.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.
@@ -0,0 +1,1591 @@
1
+ import { getWordExportFallbacks as e } from "../index.es.js";
2
+ import { AlignmentType as t, Bookmark as n, BorderStyle as r, CommentRangeEnd as i, CommentRangeStart as a, CommentReference as o, Document as s, ExternalHyperlink as c, Footer as l, FootnoteReferenceRun as u, Header as d, HeadingLevel as f, ImageRun as p, InternalHyperlink as m, LevelFormat as h, Math as g, MathRun as _, Paragraph as v, SectionType as y, SequentialIdentifier as ee, ShadingType as b, SimpleField as x, TabStopPosition as S, TabStopType as C, Table as w, TableCell as T, TableLayoutType as E, TableRow as D, TextRun as O, VerticalAlignTable as k, WidthType as A, convertInchesToTwip as te } from "./dist-CCgJdXY1.js";
3
+ //#region ../../node_modules/.pnpm/image-dimensions@2.5.1/node_modules/image-dimensions/utilities.js
4
+ function j(e, t, n) {
5
+ return e.byteLength >= t + n;
6
+ }
7
+ function M(e, t, n = !1) {
8
+ if (j(e, t, 4)) return e.getUint32(t, n);
9
+ }
10
+ function N(e, t, n = !1) {
11
+ if (j(e, t, 2)) return e.getUint16(t, n);
12
+ }
13
+ function P(e) {
14
+ if (e.length < 16 || e[4] !== 102 || e[5] !== 116 || e[6] !== 121 || e[7] !== 112) return;
15
+ let t = M(new DataView(e.buffer, e.byteOffset, e.byteLength), 0);
16
+ if (t === void 0 || t < 16 || t > e.length) return;
17
+ let n = [];
18
+ n.push(String.fromCodePoint(...e.slice(8, 12)));
19
+ for (let r = 16; r + 4 <= t; r += 4) n.push(String.fromCodePoint(...e.slice(r, r + 4)));
20
+ return n;
21
+ }
22
+ function F(e, t) {
23
+ let n = M(new DataView(e.buffer, e.byteOffset, e.byteLength), t);
24
+ if (n !== void 0 && !(e.length < n + t || n < 8)) return {
25
+ type: String.fromCodePoint(...e.slice(t + 4, t + 8)),
26
+ data: e.slice(t + 8, t + n),
27
+ tail: t + n
28
+ };
29
+ }
30
+ function ne(e) {
31
+ let t = [], n = 0;
32
+ for (; n < e.length;) {
33
+ let r = F(e, n);
34
+ if (!r) break;
35
+ r.type === "meta" && re(r.data, t), n = r.tail;
36
+ }
37
+ return t;
38
+ }
39
+ function re(e, t) {
40
+ let n = 4;
41
+ for (; n < e.length;) {
42
+ let r = F(e, n);
43
+ if (!r) break;
44
+ r.type === "iprp" && ie(r.data, t), n = r.tail;
45
+ }
46
+ return t;
47
+ }
48
+ function ie(e, t) {
49
+ let n = 0;
50
+ for (; n < e.length;) {
51
+ let r = F(e, n);
52
+ if (!r) break;
53
+ r.type === "ipco" && ae(r.data, t), n = r.tail;
54
+ }
55
+ }
56
+ function ae(e, t) {
57
+ let n = 0;
58
+ for (; n < e.length;) {
59
+ let r = F(e, n);
60
+ if (!r) break;
61
+ if (r.type === "ispe") {
62
+ let e = new DataView(r.data.buffer, r.data.byteOffset, r.data.byteLength), n = M(e, 4), i = M(e, 8);
63
+ if (n === void 0 || i === void 0) return;
64
+ t.push({
65
+ width: n,
66
+ height: i
67
+ });
68
+ }
69
+ n = r.tail;
70
+ }
71
+ }
72
+ function oe(e) {
73
+ let t = e[0];
74
+ for (let n of e) n.width * n.height > t.width * t.height && (t = n);
75
+ return t;
76
+ }
77
+ //#endregion
78
+ //#region ../../node_modules/.pnpm/image-dimensions@2.5.1/node_modules/image-dimensions/types/png.js
79
+ var se = (e) => e[0] === 137 && e[1] === 80 && e[2] === 78 && e[3] === 71 && e[4] === 13 && e[5] === 10 && e[6] === 26 && e[7] === 10, ce = (e) => e[12] === 67 && e[13] === 103 && e[14] === 66 && e[15] === 73;
80
+ function le(e) {
81
+ if (!se(e)) return;
82
+ let t = new DataView(e.buffer), n = ce(e), r = M(t, n ? 32 : 16, !1), i = M(t, n ? 36 : 20, !1);
83
+ if (r !== void 0 && i !== void 0) return {
84
+ width: r,
85
+ height: i,
86
+ type: "png"
87
+ };
88
+ }
89
+ //#endregion
90
+ //#region ../../node_modules/.pnpm/image-dimensions@2.5.1/node_modules/image-dimensions/types/jpeg.js
91
+ var ue = 65472, de = 65475, fe = (e) => e[0] === 255 && e[1] === 216 && e[2] === 255;
92
+ function pe(e) {
93
+ if (!fe(e)) return;
94
+ let t = new DataView(e.buffer), n = 2;
95
+ for (; j(t, n, 2);) {
96
+ let e = t.getUint16(n);
97
+ if (n += 2, e >= ue && e <= de) {
98
+ let e = N(t, n + 3, !1), r = N(t, n + 5, !1);
99
+ return e === void 0 || r === void 0 ? void 0 : {
100
+ height: e,
101
+ width: r,
102
+ type: "jpeg"
103
+ };
104
+ }
105
+ let r = N(t, n);
106
+ if (r === void 0 || (n += r, n > t.byteLength)) return;
107
+ }
108
+ }
109
+ //#endregion
110
+ //#region ../../node_modules/.pnpm/image-dimensions@2.5.1/node_modules/image-dimensions/types/gif.js
111
+ var me = (e) => e[0] === 71 && e[1] === 73 && e[2] === 70 && e[3] === 56 && (e[4] === 55 || e[4] === 57) && e[5] === 97;
112
+ function he(e) {
113
+ if (!me(e)) return;
114
+ let t = new DataView(e.buffer), n = N(t, 6, !0), r = N(t, 8, !0);
115
+ if (n !== void 0 && r !== void 0) return {
116
+ width: n,
117
+ height: r,
118
+ type: "gif"
119
+ };
120
+ }
121
+ //#endregion
122
+ //#region ../../node_modules/.pnpm/image-dimensions@2.5.1/node_modules/image-dimensions/types/webp.js
123
+ var ge = (e) => e[0] === 82 && e[1] === 73 && e[2] === 70 && e[3] === 70 && e[8] === 87 && e[9] === 69 && e[10] === 66 && e[11] === 80, _e = (e) => e[12] === 86 && e[13] === 80 && e[14] === 56 && e[15] === 32, ve = (e) => e[12] === 86 && e[13] === 80 && e[14] === 56 && e[15] === 76, ye = (e) => e[12] === 86 && e[13] === 80 && e[14] === 56 && e[15] === 88;
124
+ function be(e, t) {
125
+ let n = e.getUint8(t), r = e.getUint8(t + 1);
126
+ return e.getUint8(t + 2) << 16 | r << 8 | n;
127
+ }
128
+ function xe(e) {
129
+ if (!ge(e)) return;
130
+ let t = new DataView(e.buffer), n = 16383;
131
+ if (_e(e)) return j(t, 28, 2) ? {
132
+ width: t.getUint16(26, !0) & n,
133
+ height: t.getUint16(28, !0) & n,
134
+ type: "webp"
135
+ } : void 0;
136
+ if (ve(e)) {
137
+ let e = M(t, 21, !0);
138
+ return e === void 0 ? void 0 : {
139
+ width: (e & n) + 1,
140
+ height: (e >> 14 & n) + 1,
141
+ type: "webp"
142
+ };
143
+ }
144
+ if (ye(e)) return j(t, 27, 3) ? {
145
+ width: be(t, 24) + 1,
146
+ height: be(t, 27) + 1,
147
+ type: "webp"
148
+ } : void 0;
149
+ }
150
+ //#endregion
151
+ //#region ../../node_modules/.pnpm/image-dimensions@2.5.1/node_modules/image-dimensions/types/avif.js
152
+ var Se = /* @__PURE__ */ new Set([
153
+ "avif",
154
+ "avis",
155
+ "avio"
156
+ ]), Ce = (e) => {
157
+ let t = P(e);
158
+ return t ? t.some((e) => Se.has(e)) : !1;
159
+ };
160
+ function we(e) {
161
+ if (!Ce(e)) return;
162
+ let t = ne(e);
163
+ if (t.length !== 0) return {
164
+ ...oe(t),
165
+ type: "avif"
166
+ };
167
+ }
168
+ //#endregion
169
+ //#region ../../node_modules/.pnpm/image-dimensions@2.5.1/node_modules/image-dimensions/types/heic.js
170
+ var Te = /* @__PURE__ */ new Set([
171
+ "mif1",
172
+ "msf1",
173
+ "heic",
174
+ "heix",
175
+ "hevc",
176
+ "hevx",
177
+ "heim",
178
+ "heis",
179
+ "hevm",
180
+ "hevs"
181
+ ]), Ee = (e) => {
182
+ let t = P(e);
183
+ return t ? t.some((e) => Te.has(e)) : !1;
184
+ };
185
+ function De(e) {
186
+ if (!Ee(e)) return;
187
+ let t = ne(e);
188
+ if (t.length !== 0) return {
189
+ ...oe(t),
190
+ type: "heic"
191
+ };
192
+ }
193
+ //#endregion
194
+ //#region ../../node_modules/.pnpm/image-dimensions@2.5.1/node_modules/image-dimensions/index.js
195
+ function Oe(e) {
196
+ if (!(e.length < 3)) return e = new Uint8Array(e), le(e) ?? he(e) ?? pe(e) ?? xe(e) ?? we(e) ?? De(e);
197
+ }
198
+ //#endregion
199
+ //#region ../../node_modules/.pnpm/prosemirror-docx@0.6.1_docx@9.7.1/node_modules/prosemirror-docx/dist/esm/numbering.js
200
+ function ke(e) {
201
+ return {
202
+ alignment: t.START,
203
+ style: { paragraph: { indent: {
204
+ left: te(e),
205
+ hanging: te(.18)
206
+ } } }
207
+ };
208
+ }
209
+ var Ae = {
210
+ numbered: [
211
+ ,
212
+ ,
213
+ ,
214
+ ].fill([
215
+ h.DECIMAL,
216
+ h.LOWER_LETTER,
217
+ h.LOWER_ROMAN
218
+ ]).flat().map((e, t) => Object.assign({
219
+ level: t,
220
+ format: e,
221
+ text: `%${t + 1}.`
222
+ }, ke((t + 1) / 2))),
223
+ bullets: [
224
+ ,
225
+ ,
226
+ ,
227
+ ].fill([
228
+ "●",
229
+ "○",
230
+ "■"
231
+ ]).flat().map((e, t) => Object.assign({
232
+ level: t,
233
+ format: h.BULLET,
234
+ text: e
235
+ }, ke((t + 1) / 2)))
236
+ };
237
+ function je(e, t) {
238
+ return {
239
+ reference: e,
240
+ levels: Ae[t]
241
+ };
242
+ }
243
+ function I() {
244
+ return Math.random().toString(36).slice(2, 11);
245
+ }
246
+ function Me(e, t) {
247
+ let n = (e?.sections)?.map((e) => ({
248
+ properties: e.config.properties || { type: y.CONTINUOUS },
249
+ headers: e.config.headers,
250
+ footers: e.config.footers,
251
+ children: e.children
252
+ }));
253
+ return n ||= [{
254
+ headers: void 0,
255
+ footers: void 0,
256
+ properties: { type: y.CONTINUOUS },
257
+ children: e?.children || []
258
+ }], new s(Object.assign({
259
+ footnotes: e.footnotes,
260
+ numbering: { config: e.numbering },
261
+ sections: n
262
+ }, t || {}));
263
+ }
264
+ function L(e) {
265
+ let t = "";
266
+ return e.forEach((e) => {
267
+ e.isText && (t += e.text);
268
+ }), t;
269
+ }
270
+ //#endregion
271
+ //#region ../../node_modules/.pnpm/prosemirror-docx@0.6.1_docx@9.7.1/node_modules/prosemirror-docx/dist/esm/serializer.js
272
+ var R = function(e, t, n, r) {
273
+ function i(e) {
274
+ return e instanceof n ? e : new n(function(t) {
275
+ t(e);
276
+ });
277
+ }
278
+ return new (n ||= Promise)(function(n, a) {
279
+ function o(e) {
280
+ try {
281
+ c(r.next(e));
282
+ } catch (e) {
283
+ a(e);
284
+ }
285
+ }
286
+ function s(e) {
287
+ try {
288
+ c(r.throw(e));
289
+ } catch (e) {
290
+ a(e);
291
+ }
292
+ }
293
+ function c(e) {
294
+ e.done ? n(e.value) : i(e.value).then(o, s);
295
+ }
296
+ c((r = r.apply(e, t || [])).next());
297
+ });
298
+ };
299
+ function z(e, t, r, i) {
300
+ let a = r ? [new O(r)] : [], o = i ? [new O(i)] : [];
301
+ return new n({
302
+ id: e,
303
+ children: [
304
+ ...a,
305
+ new ee(t),
306
+ ...o
307
+ ]
308
+ });
309
+ }
310
+ var Ne = class {
311
+ constructor(e, t, n) {
312
+ this.currentSectionIndex = 0, this.footnotes = {}, this.current = [], this.maxImageWidth = 600, this.$footnoteCounter = 0, this.nodes = e, this.marks = t, this.options = n ?? {}, this.children = [], this.numbering = [], n.sections && n.sections.length > 0 ? (this.sections = n.sections.map((e) => ({
313
+ config: e,
314
+ children: []
315
+ })), this.children = this.sections[0].children) : this.sections = [];
316
+ }
317
+ renderContent(e, t) {
318
+ e.forEach((n, r, i) => {
319
+ t && this.addParagraphOptions(t), this.render(n, e, i);
320
+ });
321
+ }
322
+ render(e, t, n) {
323
+ if (typeof t == "number") throw Error("!");
324
+ if (!this.nodes[e.type.name]) throw Error(`Token type \`${e.type.name}\` not supported by Word renderer`);
325
+ this.nodes[e.type.name](this, e, t, n);
326
+ }
327
+ renderMarks(e, t) {
328
+ return t.map((t) => {
329
+ var n;
330
+ return (n = this.marks)[t.type.name]?.call(n, this, e, t);
331
+ }).reduce((e, t) => Object.assign(Object.assign({}, e), t), {});
332
+ }
333
+ renderInline(e) {
334
+ let t, n = () => {
335
+ if (!t) return;
336
+ let e = new c({
337
+ link: t.link,
338
+ children: this.current
339
+ });
340
+ this.current = [...t.stack, e], t = void 0;
341
+ }, r = (e) => {
342
+ let r = e === t?.link;
343
+ this.addRunOptions({ style: "Hyperlink" }), !(t && r) && (t && !r && n(), t = {
344
+ link: e,
345
+ stack: this.current
346
+ }, this.current = []);
347
+ };
348
+ e.forEach((i, a, o) => {
349
+ let s = i.marks.filter((e) => e.type.name === "link"), c = s.length > 0;
350
+ c ? r(s[0].attrs.href) : !c && t && n(), i.isText ? this.text(i.text, this.renderMarks(i, [...i.marks])) : this.render(i, e, o);
351
+ }), n();
352
+ }
353
+ renderList(e, t) {
354
+ if (this.currentNumbering) {
355
+ let { reference: e, level: t } = this.currentNumbering;
356
+ this.currentNumbering = {
357
+ reference: e,
358
+ level: t + 1
359
+ };
360
+ } else {
361
+ let e = I();
362
+ this.numbering.push(je(e, t)), this.currentNumbering = {
363
+ reference: e,
364
+ level: 0
365
+ };
366
+ }
367
+ if (this.renderContent(e), this.currentNumbering.level === 0) delete this.currentNumbering;
368
+ else {
369
+ let { reference: e, level: t } = this.currentNumbering;
370
+ this.currentNumbering = {
371
+ reference: e,
372
+ level: t - 1
373
+ };
374
+ }
375
+ }
376
+ renderListItem(e) {
377
+ if (!this.currentNumbering) throw Error("Trying to create a list item without a list?");
378
+ this.addParagraphOptions({ numbering: this.currentNumbering }), this.renderContent(e);
379
+ }
380
+ addParagraphOptions(e) {
381
+ this.nextParentParagraphOpts = Object.assign(Object.assign({}, this.nextParentParagraphOpts), e);
382
+ }
383
+ addRunOptions(e) {
384
+ this.nextRunOpts = Object.assign(Object.assign({}, this.nextRunOpts), e);
385
+ }
386
+ text(e, t) {
387
+ e && (this.current.push(new O(Object.assign(Object.assign({ text: e }, this.nextRunOpts), t))), delete this.nextRunOpts);
388
+ }
389
+ math(e, t = { inline: !0 }) {
390
+ if (t.inline || !t.numbered) {
391
+ this.current.push(new g({ children: [new _(e)] }));
392
+ return;
393
+ }
394
+ let n = t.id ?? I();
395
+ this.current = [
396
+ new O(" "),
397
+ new g({ children: [new _(e)] }),
398
+ new O(" ("),
399
+ z(n, "Equation"),
400
+ new O(")")
401
+ ], this.addParagraphOptions({ tabStops: [{
402
+ type: C.CENTER,
403
+ position: S.MAX / 2
404
+ }, {
405
+ type: C.RIGHT,
406
+ position: S.MAX
407
+ }] });
408
+ }
409
+ image(e, n = 70, r = "center", i, a) {
410
+ let o = this.options.getImageBuffer(e), s = Oe(o);
411
+ if (!s) return;
412
+ let c = s.height / s.width, l = this.maxImageWidth * (n / 100), u;
413
+ try {
414
+ u = a || e.replace(/.*\./, "").toLowerCase();
415
+ } catch {
416
+ u = "png";
417
+ }
418
+ this.current.push(new p(Object.assign(Object.assign({ data: o }, i), {
419
+ type: u,
420
+ transformation: Object.assign(Object.assign({}, i?.transformation || {}), {
421
+ width: l,
422
+ height: l * c
423
+ })
424
+ })));
425
+ let d;
426
+ switch (r) {
427
+ case "right":
428
+ d = t.RIGHT;
429
+ break;
430
+ case "left":
431
+ d = t.LEFT;
432
+ break;
433
+ default: d = t.CENTER;
434
+ }
435
+ this.addParagraphOptions({ alignment: d });
436
+ }
437
+ table(e, t = {}) {
438
+ let { getCellOptions: n, getRowOptions: r, tableOptions: i } = t, a = this.children, o = [];
439
+ e.content.forEach((e) => {
440
+ let t = [], i = !0;
441
+ e.content.forEach((e) => {
442
+ e.type.name !== "table_header" && (i = !1);
443
+ }), this.maxImageWidth = 600 / e.content.childCount, e.content.forEach((e) => {
444
+ this.children = [], this.renderContent(e);
445
+ let r = { children: this.children }, i = e.attrs.colspan ?? 1, a = e.attrs.rowspan ?? 1;
446
+ i > 1 && (r.columnSpan = i), a > 1 && (r.rowSpan = a), t.push(new T(Object.assign(Object.assign({}, r), n?.(e) || {})));
447
+ }), o.push(new D(Object.assign(Object.assign({}, r?.(e) || {}), {
448
+ children: t,
449
+ tableHeader: i
450
+ })));
451
+ }), this.maxImageWidth = 600;
452
+ let s = new w(Object.assign(Object.assign({}, i), { rows: o }));
453
+ a.push(s), a.push(new v("")), this.children = a;
454
+ }
455
+ captionLabel(e, t, { suffix: n } = { suffix: ": " }) {
456
+ this.current.push(z(e, t, `${t} `), new O(n));
457
+ }
458
+ footnote(e) {
459
+ let { current: t, nextRunOpts: n } = this;
460
+ this.current = [], delete this.nextRunOpts, this.$footnoteCounter += 1, this.renderInline(e), this.footnotes[this.$footnoteCounter] = { children: [new v({ children: this.current })] }, this.current = t, this.nextRunOpts = n, this.current.push(new u(this.$footnoteCounter));
461
+ }
462
+ closeBlock(e, t) {
463
+ let n = new v(Object.assign(Object.assign({ children: this.current }, this.nextParentParagraphOpts), t));
464
+ this.current = [], delete this.nextParentParagraphOpts, this.children.push(n);
465
+ }
466
+ nextSection() {
467
+ this.currentSectionIndex < this.sections.length - 1 && (this.currentSectionIndex += 1, this.children = this.sections[this.currentSectionIndex].children);
468
+ }
469
+ setSectionConfig(e) {
470
+ this.sections[this.currentSectionIndex].config = Object.assign(Object.assign({}, this.sections[this.currentSectionIndex].config), e);
471
+ }
472
+ addSection(e = {}) {
473
+ this.sections.push({
474
+ config: e,
475
+ children: []
476
+ }), this.currentSectionIndex = this.sections.length - 1, this.children = this.sections[this.currentSectionIndex].children;
477
+ }
478
+ getCurrentSectionIndex() {
479
+ return this.currentSectionIndex;
480
+ }
481
+ getCurrentSectionConfig() {
482
+ return this.sections[this.currentSectionIndex].config;
483
+ }
484
+ getSerializationState() {
485
+ return {
486
+ numbering: this.numbering,
487
+ sections: this.sections,
488
+ footnotes: this.footnotes
489
+ };
490
+ }
491
+ createReference(e, t, n) {
492
+ let r = [];
493
+ t && r.push(new O(t)), r.push(new x(`REF ${e} \\h`)), n && r.push(new O(n));
494
+ let i = new m({
495
+ anchor: e,
496
+ children: r
497
+ });
498
+ this.current.push(i);
499
+ }
500
+ }, Pe = class {
501
+ constructor(e, t) {
502
+ this.nodes = e, this.marks = t;
503
+ }
504
+ serialize(e, t, n) {
505
+ let r = new Ne(this.nodes, this.marks, t);
506
+ return r.renderContent(e), Me(r, n?.(r));
507
+ }
508
+ }, Fe = class {
509
+ constructor(e, t, n) {
510
+ this.currentSectionIndex = 0, this.footnotes = {}, this.current = [], this.maxImageWidth = 600, this.$footnoteCounter = 0, this.nodes = e, this.marks = t, this.options = n ?? {}, this.children = [], this.numbering = [], n.sections && n.sections.length > 0 ? (this.sections = n.sections.map((e) => ({
511
+ config: e,
512
+ children: []
513
+ })), this.children = this.sections[0].children) : this.sections = [];
514
+ }
515
+ renderContent(e, t) {
516
+ return R(this, void 0, void 0, function* () {
517
+ for (let n = 0; n < e.childCount; n += 1) {
518
+ let r = e.child(n);
519
+ t && this.addParagraphOptions(t), yield this.render(r, e, n);
520
+ }
521
+ });
522
+ }
523
+ render(e, t, n) {
524
+ return R(this, void 0, void 0, function* () {
525
+ if (typeof t == "number") throw Error("!");
526
+ if (!this.nodes[e.type.name]) throw Error(`Token type \`${e.type.name}\` not supported by Word renderer`);
527
+ yield Promise.resolve(this.nodes[e.type.name](this, e, t, n));
528
+ });
529
+ }
530
+ renderMarks(e, t) {
531
+ return t.map((t) => {
532
+ var n;
533
+ return (n = this.marks)[t.type.name]?.call(n, this, e, t);
534
+ }).reduce((e, t) => Object.assign(Object.assign({}, e), t), {});
535
+ }
536
+ renderInline(e) {
537
+ return R(this, void 0, void 0, function* () {
538
+ let t, n = () => {
539
+ if (!t) return;
540
+ let e = new c({
541
+ link: t.link,
542
+ children: this.current
543
+ });
544
+ this.current = [...t.stack, e], t = void 0;
545
+ }, r = (e) => {
546
+ let r = e === t?.link;
547
+ this.addRunOptions({ style: "Hyperlink" }), !(t && r) && (t && !r && n(), t = {
548
+ link: e,
549
+ stack: this.current
550
+ }, this.current = []);
551
+ }, i = (i, a, o) => R(this, void 0, void 0, function* () {
552
+ let a = i.marks.filter((e) => e.type.name === "link"), s = a.length > 0;
553
+ s ? r(a[0].attrs.href) : !s && t && n(), i.isText ? this.text(i.text, this.renderMarks(i, [...i.marks])) : yield this.render(i, e, o);
554
+ });
555
+ for (let t = 0; t < e.childCount; t += 1) yield i(e.child(t), 0, t);
556
+ n();
557
+ });
558
+ }
559
+ renderList(e, t) {
560
+ return R(this, void 0, void 0, function* () {
561
+ if (this.currentNumbering) {
562
+ let { reference: e, level: t } = this.currentNumbering;
563
+ this.currentNumbering = {
564
+ reference: e,
565
+ level: t + 1
566
+ };
567
+ } else {
568
+ let e = I();
569
+ this.numbering.push(je(e, t)), this.currentNumbering = {
570
+ reference: e,
571
+ level: 0
572
+ };
573
+ }
574
+ if (yield this.renderContent(e), this.currentNumbering.level === 0) delete this.currentNumbering;
575
+ else {
576
+ let { reference: e, level: t } = this.currentNumbering;
577
+ this.currentNumbering = {
578
+ reference: e,
579
+ level: t - 1
580
+ };
581
+ }
582
+ });
583
+ }
584
+ renderListItem(e) {
585
+ return R(this, void 0, void 0, function* () {
586
+ if (!this.currentNumbering) throw Error("Trying to create a list item without a list?");
587
+ this.addParagraphOptions({ numbering: this.currentNumbering }), yield this.renderContent(e);
588
+ });
589
+ }
590
+ addParagraphOptions(e) {
591
+ this.nextParentParagraphOpts = Object.assign(Object.assign({}, this.nextParentParagraphOpts), e);
592
+ }
593
+ addRunOptions(e) {
594
+ this.nextRunOpts = Object.assign(Object.assign({}, this.nextRunOpts), e);
595
+ }
596
+ text(e, t) {
597
+ e && (this.current.push(new O(Object.assign(Object.assign({ text: e }, this.nextRunOpts), t))), delete this.nextRunOpts);
598
+ }
599
+ math(e, t = { inline: !0 }) {
600
+ if (t.inline || !t.numbered) {
601
+ this.current.push(new g({ children: [new _(e)] }));
602
+ return;
603
+ }
604
+ let n = t.id ?? I();
605
+ this.current = [
606
+ new O(" "),
607
+ new g({ children: [new _(e)] }),
608
+ new O(" ("),
609
+ z(n, "Equation"),
610
+ new O(")")
611
+ ], this.addParagraphOptions({ tabStops: [{
612
+ type: C.CENTER,
613
+ position: S.MAX / 2
614
+ }, {
615
+ type: C.RIGHT,
616
+ position: S.MAX
617
+ }] });
618
+ }
619
+ image(e, n = 70, r = "center", i, a) {
620
+ return R(this, void 0, void 0, function* () {
621
+ let o = yield Promise.resolve(this.options.getImageBuffer(e)), s = Oe(o);
622
+ if (!s) return;
623
+ let c = s.height / s.width, l = this.maxImageWidth * (n / 100), u;
624
+ try {
625
+ u = a || e.replace(/.*\./, "").toLowerCase();
626
+ } catch {
627
+ u = "png";
628
+ }
629
+ this.current.push(new p(Object.assign(Object.assign({ data: o }, i), {
630
+ type: u,
631
+ transformation: Object.assign(Object.assign({}, i?.transformation || {}), {
632
+ width: l,
633
+ height: l * c
634
+ })
635
+ })));
636
+ let d;
637
+ switch (r) {
638
+ case "right":
639
+ d = t.RIGHT;
640
+ break;
641
+ case "left":
642
+ d = t.LEFT;
643
+ break;
644
+ default: d = t.CENTER;
645
+ }
646
+ this.addParagraphOptions({ alignment: d });
647
+ });
648
+ }
649
+ table(e, t = {}) {
650
+ return R(this, void 0, void 0, function* () {
651
+ let { getCellOptions: n, getRowOptions: r, tableOptions: i } = t, a = this.children, o = [];
652
+ for (let t = 0; t < e.content.childCount; t += 1) {
653
+ let i = e.content.child(t), a = [], s = !0;
654
+ for (let e = 0; e < i.content.childCount; e += 1) i.content.child(e).type.name !== "table_header" && (s = !1);
655
+ this.maxImageWidth = 600 / i.content.childCount;
656
+ for (let e = 0; e < i.content.childCount; e += 1) {
657
+ let t = i.content.child(e);
658
+ this.children = [], yield this.renderContent(t);
659
+ let r = { children: this.children }, o = t.attrs.colspan ?? 1, s = t.attrs.rowspan ?? 1;
660
+ o > 1 && (r.columnSpan = o), s > 1 && (r.rowSpan = s), a.push(new T(Object.assign(Object.assign({}, r), n?.(t) || {})));
661
+ }
662
+ o.push(new D(Object.assign(Object.assign({}, r?.(i) || {}), {
663
+ children: a,
664
+ tableHeader: s
665
+ })));
666
+ }
667
+ this.maxImageWidth = 600;
668
+ let s = new w(Object.assign(Object.assign({}, i), { rows: o }));
669
+ a.push(s), a.push(new v("")), this.children = a;
670
+ });
671
+ }
672
+ captionLabel(e, t, { suffix: n } = { suffix: ": " }) {
673
+ this.current.push(z(e, t, `${t} `), new O(n));
674
+ }
675
+ footnote(e) {
676
+ return R(this, void 0, void 0, function* () {
677
+ let { current: t, nextRunOpts: n } = this;
678
+ this.current = [], delete this.nextRunOpts, this.$footnoteCounter += 1, yield this.renderInline(e), this.footnotes[this.$footnoteCounter] = { children: [new v({ children: this.current })] }, this.current = t, this.nextRunOpts = n, this.current.push(new u(this.$footnoteCounter));
679
+ });
680
+ }
681
+ closeBlock(e, t) {
682
+ let n = new v(Object.assign(Object.assign({ children: this.current }, this.nextParentParagraphOpts), t));
683
+ this.current = [], delete this.nextParentParagraphOpts, this.children.push(n);
684
+ }
685
+ nextSection() {
686
+ this.currentSectionIndex < this.sections.length - 1 && (this.currentSectionIndex += 1, this.children = this.sections[this.currentSectionIndex].children);
687
+ }
688
+ setSectionConfig(e) {
689
+ this.sections[this.currentSectionIndex].config = Object.assign(Object.assign({}, this.sections[this.currentSectionIndex].config), e);
690
+ }
691
+ addSection(e = {}) {
692
+ this.sections.push({
693
+ config: e,
694
+ children: []
695
+ }), this.currentSectionIndex = this.sections.length - 1, this.children = this.sections[this.currentSectionIndex].children;
696
+ }
697
+ getCurrentSectionIndex() {
698
+ return this.currentSectionIndex;
699
+ }
700
+ getCurrentSectionConfig() {
701
+ return this.sections[this.currentSectionIndex].config;
702
+ }
703
+ getSerializationState() {
704
+ return {
705
+ numbering: this.numbering,
706
+ sections: this.sections,
707
+ footnotes: this.footnotes
708
+ };
709
+ }
710
+ createReference(e, t, n) {
711
+ let r = [];
712
+ t && r.push(new O(t)), r.push(new x(`REF ${e} \\h`)), n && r.push(new O(n));
713
+ let i = new m({
714
+ anchor: e,
715
+ children: r
716
+ });
717
+ this.current.push(i);
718
+ }
719
+ }, B = class {
720
+ constructor(e, t) {
721
+ this.nodes = e, this.marks = t;
722
+ }
723
+ serializeAsync(e, t, n) {
724
+ return R(this, void 0, void 0, function* () {
725
+ let r = new Fe(this.nodes, this.marks, t);
726
+ return yield r.renderContent(e), Me(r, n?.(r));
727
+ });
728
+ }
729
+ }, V = function(e, t, n, r) {
730
+ function i(e) {
731
+ return e instanceof n ? e : new n(function(t) {
732
+ t(e);
733
+ });
734
+ }
735
+ return new (n ||= Promise)(function(n, a) {
736
+ function o(e) {
737
+ try {
738
+ c(r.next(e));
739
+ } catch (e) {
740
+ a(e);
741
+ }
742
+ }
743
+ function s(e) {
744
+ try {
745
+ c(r.throw(e));
746
+ } catch (e) {
747
+ a(e);
748
+ }
749
+ }
750
+ function c(e) {
751
+ e.done ? n(e.value) : i(e.value).then(o, s);
752
+ }
753
+ c((r = r.apply(e, t || [])).next());
754
+ });
755
+ }, Ie = {
756
+ text(e, t) {
757
+ e.text(t.text ?? "");
758
+ },
759
+ paragraph(e, t) {
760
+ e.renderInline(t), e.closeBlock(t);
761
+ },
762
+ heading(e, t) {
763
+ e.renderInline(t);
764
+ let n = [
765
+ f.HEADING_1,
766
+ f.HEADING_2,
767
+ f.HEADING_3,
768
+ f.HEADING_4,
769
+ f.HEADING_5,
770
+ f.HEADING_6
771
+ ][t.attrs.level - 1];
772
+ e.closeBlock(t, { heading: n });
773
+ },
774
+ blockquote(e, t) {
775
+ e.renderContent(t, { style: "IntenseQuote" });
776
+ },
777
+ code_block(e, t) {
778
+ e.renderContent(t), e.closeBlock(t);
779
+ },
780
+ horizontal_rule(e, t) {
781
+ e.closeBlock(t, { thematicBreak: !0 }), e.closeBlock(t);
782
+ },
783
+ hard_break(e) {
784
+ e.addRunOptions({ break: 1 });
785
+ },
786
+ ordered_list(e, t) {
787
+ e.renderList(t, "numbered");
788
+ },
789
+ bullet_list(e, t) {
790
+ e.renderList(t, "bullets");
791
+ },
792
+ list_item(e, t) {
793
+ e.renderListItem(t);
794
+ },
795
+ image(e, t) {
796
+ let { src: n } = t.attrs;
797
+ e.image(n), e.closeBlock(t);
798
+ },
799
+ math(e, t) {
800
+ e.math(L(t), { inline: !0 });
801
+ },
802
+ equation(e, t) {
803
+ let { id: n, numbered: r } = t.attrs;
804
+ e.math(L(t), {
805
+ inline: !1,
806
+ numbered: r,
807
+ id: n
808
+ }), e.closeBlock(t);
809
+ },
810
+ table(e, t) {
811
+ e.table(t);
812
+ }
813
+ }, H = {
814
+ text(e, t) {
815
+ e.text(t.text ?? "");
816
+ },
817
+ paragraph(e, t) {
818
+ return V(this, void 0, void 0, function* () {
819
+ yield e.renderInline(t), e.closeBlock(t);
820
+ });
821
+ },
822
+ heading(e, t) {
823
+ return V(this, void 0, void 0, function* () {
824
+ yield e.renderInline(t);
825
+ let n = [
826
+ f.HEADING_1,
827
+ f.HEADING_2,
828
+ f.HEADING_3,
829
+ f.HEADING_4,
830
+ f.HEADING_5,
831
+ f.HEADING_6
832
+ ][t.attrs.level - 1];
833
+ e.closeBlock(t, { heading: n });
834
+ });
835
+ },
836
+ blockquote(e, t) {
837
+ e.renderContent(t, { style: "IntenseQuote" });
838
+ },
839
+ code_block(e, t) {
840
+ e.renderContent(t), e.closeBlock(t);
841
+ },
842
+ horizontal_rule(e, t) {
843
+ e.closeBlock(t, { thematicBreak: !0 }), e.closeBlock(t);
844
+ },
845
+ hard_break(e) {
846
+ e.addRunOptions({ break: 1 });
847
+ },
848
+ ordered_list(e, t) {
849
+ return V(this, void 0, void 0, function* () {
850
+ yield e.renderList(t, "numbered");
851
+ });
852
+ },
853
+ bullet_list(e, t) {
854
+ return V(this, void 0, void 0, function* () {
855
+ yield e.renderList(t, "bullets");
856
+ });
857
+ },
858
+ list_item(e, t) {
859
+ return V(this, void 0, void 0, function* () {
860
+ yield e.renderListItem(t);
861
+ });
862
+ },
863
+ image(e, t) {
864
+ return V(this, void 0, void 0, function* () {
865
+ let { src: n } = t.attrs;
866
+ yield e.image(n), e.closeBlock(t);
867
+ });
868
+ },
869
+ math(e, t) {
870
+ e.math(L(t), { inline: !0 });
871
+ },
872
+ equation(e, t) {
873
+ let { id: n, numbered: r } = t.attrs;
874
+ e.math(L(t), {
875
+ inline: !1,
876
+ numbered: r,
877
+ id: n
878
+ }), e.closeBlock(t);
879
+ },
880
+ table(e, t) {
881
+ return V(this, void 0, void 0, function* () {
882
+ yield e.table(t);
883
+ });
884
+ }
885
+ }, U = {
886
+ em() {
887
+ return { italics: !0 };
888
+ },
889
+ strong() {
890
+ return { bold: !0 };
891
+ },
892
+ italic() {
893
+ return { italics: !0 };
894
+ },
895
+ bold() {
896
+ return { bold: !0 };
897
+ },
898
+ link() {
899
+ return {};
900
+ },
901
+ code() {
902
+ return {
903
+ font: { name: "Monospace" },
904
+ color: "000000",
905
+ shading: {
906
+ type: b.SOLID,
907
+ color: "D2D3D2",
908
+ fill: "D2D3D2"
909
+ }
910
+ };
911
+ },
912
+ abbr() {
913
+ return {};
914
+ },
915
+ subscript() {
916
+ return { subScript: !0 };
917
+ },
918
+ superscript() {
919
+ return { superScript: !0 };
920
+ },
921
+ strikethrough() {
922
+ return { strike: !0 };
923
+ },
924
+ underline() {
925
+ return { underline: {} };
926
+ },
927
+ smallcaps() {
928
+ return { smallCaps: !0 };
929
+ },
930
+ allcaps() {
931
+ return { allCaps: !0 };
932
+ }
933
+ };
934
+ new Pe(Ie, U), new B(H, U);
935
+ //#endregion
936
+ //#region src/extensions/ExportWord/docx.ts
937
+ var W = {
938
+ width: 11906,
939
+ height: 16838,
940
+ margin: {
941
+ top: 1020,
942
+ right: 1134,
943
+ bottom: 1020,
944
+ left: 1134,
945
+ header: 567,
946
+ footer: 567,
947
+ gutter: 0
948
+ }
949
+ }, G = W.width - W.margin.left - W.margin.right, K = {
950
+ font: {
951
+ ascii: "Arial",
952
+ hAnsi: "Arial",
953
+ eastAsia: "Microsoft YaHei",
954
+ cs: "Arial"
955
+ },
956
+ size: 23
957
+ }, Le = {
958
+ after: 160,
959
+ line: 400
960
+ }, q = {
961
+ top: 100,
962
+ bottom: 100,
963
+ left: 140,
964
+ right: 140
965
+ }, J = {
966
+ style: r.SINGLE,
967
+ size: 4,
968
+ color: "D7D9DC"
969
+ };
970
+ function Y(e) {
971
+ if (!e) return;
972
+ let t = e.trim(), n = t.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i), r = n ? n.slice(1, 4).map((e) => Math.min(255, Number(e)).toString(16).padStart(2, "0")).join("") : t.replace("#", "");
973
+ return /^[0-9a-f]{6}$/i.test(r) ? r.toUpperCase() : void 0;
974
+ }
975
+ function Re(e) {
976
+ if (!e) return;
977
+ let t = Number.parseFloat(e);
978
+ if (!Number.isFinite(t)) return;
979
+ let n = e.toLowerCase().endsWith("px") ? t * 72 / 96 : t;
980
+ return Math.max(1, Math.round(n * 2));
981
+ }
982
+ function X(e) {
983
+ let n = e.attrs ?? {}, r = {
984
+ autoSpaceEastAsianText: !0,
985
+ widowControl: !0,
986
+ wordWrap: !0,
987
+ spacing: { ...Le },
988
+ run: { ...K }
989
+ }, i = n.textAlign;
990
+ if (i === "center" && (r.alignment = t.CENTER), i === "right" && (r.alignment = t.RIGHT), i === "justify" && (r.alignment = t.JUSTIFIED), n.lineHeight) {
991
+ let e = Number.parseFloat(String(n.lineHeight));
992
+ Number.isFinite(e) && (r.spacing = {
993
+ ...Le,
994
+ line: Math.round(e / 100 * 240)
995
+ });
996
+ }
997
+ return r;
998
+ }
999
+ function ze(e, t, n) {
1000
+ let r = n.attrs ?? {};
1001
+ return {
1002
+ color: Y(r.color),
1003
+ size: Re(r.fontSize),
1004
+ font: r.fontFamily ? String(r.fontFamily).split(",")[0].trim().replace(/["']/g, "") : void 0
1005
+ };
1006
+ }
1007
+ function Be(e, t, n) {
1008
+ let r = Y(n.attrs?.color);
1009
+ return r ? { shading: {
1010
+ type: b.SOLID,
1011
+ color: r,
1012
+ fill: r
1013
+ } } : {};
1014
+ }
1015
+ function Ve(e) {
1016
+ let t = e.match(/^data:image\/([a-z0-9.+-]+);/i)?.[1]?.toLowerCase();
1017
+ if (t === "jpeg") return "jpg";
1018
+ if (t === "png" || t === "jpg" || t === "gif" || t === "bmp") return t;
1019
+ let n = e.split("?")[0].split(".").pop()?.toLowerCase();
1020
+ return n === "jpeg" ? "jpg" : n === "png" || n === "jpg" || n === "gif" || n === "bmp" ? n : void 0;
1021
+ }
1022
+ function He(e) {
1023
+ let t = e.attrs?.width;
1024
+ if (typeof t == "string" && t.trim().endsWith("%")) {
1025
+ let e = Number.parseFloat(t);
1026
+ return Number.isFinite(e) ? Math.min(100, Math.max(1, e)) : 70;
1027
+ }
1028
+ return typeof t == "number" && Number.isFinite(t) ? Math.min(100, Math.max(1, t / 600 * 100)) : 70;
1029
+ }
1030
+ function Ue(e) {
1031
+ return e.attrs?.textAlign === "left" || e.attrs?.textAlign === "right" ? e.attrs.textAlign : "center";
1032
+ }
1033
+ function Z(e) {
1034
+ return typeof e == "string" || typeof e == "number" ? String(e) : "";
1035
+ }
1036
+ function Q(e) {
1037
+ return Z(e).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
1038
+ }
1039
+ function We(e, t) {
1040
+ let n = Z(e).trim();
1041
+ return /^#[0-9a-f]{6}$/i.test(n) || /^#[0-9a-f]{3}$/i.test(n) ? n : t;
1042
+ }
1043
+ function Ge(e) {
1044
+ let t = Array.isArray(e.labels) ? e.labels.map(Z) : [], n = [
1045
+ "#4f7ff0",
1046
+ "#2bbd8b",
1047
+ "#f4a321",
1048
+ "#9a6df0",
1049
+ "#e65f73",
1050
+ "#31a6b8"
1051
+ ], r = Array.isArray(e.datasets) ? e.datasets.filter((e) => e && Array.isArray(e.values)).map((e, r) => ({
1052
+ label: Z(e.label) || `Series ${r + 1}`,
1053
+ color: We(e.color, n[r % n.length]),
1054
+ values: t.map((t, n) => {
1055
+ let r = Number(e.values[n]);
1056
+ return Number.isFinite(r) ? r : 0;
1057
+ })
1058
+ })) : [];
1059
+ return {
1060
+ type: e.type === "line" ? "line" : "bar",
1061
+ labels: t,
1062
+ datasets: r,
1063
+ height: Math.min(520, Math.max(220, Number(e.height) || 300))
1064
+ };
1065
+ }
1066
+ function Ke(e) {
1067
+ let t = Ge(e), n = 1100, r = t.height + 112, i = {
1068
+ top: 24,
1069
+ right: 30,
1070
+ bottom: 70,
1071
+ left: 78
1072
+ }, a = n - i.left - i.right, o = r - i.top - i.bottom, s = t.datasets.flatMap((e) => e.values), c = Math.max(1, ...s, 0), l = Math.min(0, ...s, 0), u = c - l || 1, d = (e) => i.top + (c - e) / u * o, f = (e) => t.labels.length <= 1 ? i.left + a / 2 : i.left + e / (t.labels.length - 1) * a, p = Array.from({ length: 5 }, (e, t) => {
1073
+ let r = l + (c - l) * t / 4, a = d(r);
1074
+ return `<line x1="${i.left}" y1="${a.toFixed(2)}" x2="${n - i.right}" y2="${a.toFixed(2)}" stroke="#e5e7eb" stroke-width="1"/><text x="${i.left - 12}" y="${(a + 4).toFixed(2)}" text-anchor="end" fill="#6b7280" font-size="18" font-family="Arial, sans-serif">${Q(Math.round(r * 100) / 100)}</text>`;
1075
+ }).join(""), m = t.labels.map((e, t) => `<text x="${f(t).toFixed(2)}" y="${r - 34}" text-anchor="middle" fill="#4b5563" font-size="18" font-family="Arial, sans-serif">${Q(e)}</text>`).join(""), h = t.type === "line" ? t.datasets.map((e) => {
1076
+ let t = e.values.map((e, t) => `${f(t).toFixed(2)},${d(e).toFixed(2)}`).join(" "), n = e.values.map((t, n) => `<circle cx="${f(n).toFixed(2)}" cy="${d(t).toFixed(2)}" r="5" fill="#ffffff" stroke="${e.color}" stroke-width="3"/>`).join("");
1077
+ return `<polyline points="${t}" fill="none" stroke="${e.color}" stroke-width="4" stroke-linejoin="round" stroke-linecap="round"/>${n}`;
1078
+ }).join("") : (() => {
1079
+ let e = t.labels.length ? a / t.labels.length : a, n = Math.max(8, e * .72 / Math.max(1, t.datasets.length));
1080
+ return t.datasets.map((t, r) => t.values.map((a, o) => {
1081
+ let s = d(Math.max(0, l)), c = d(Math.max(l, a)), u = Math.max(1, Math.abs(s - c));
1082
+ return `<rect x="${(i.left + o * e + e * .14 + r * n).toFixed(2)}" y="${Math.min(s, c).toFixed(2)}" width="${Math.max(2, n - 4).toFixed(2)}" height="${u.toFixed(2)}" rx="3" fill="${t.color}"/>`;
1083
+ }).join("")).join("");
1084
+ })(), g = t.datasets.map((e, n) => {
1085
+ let o = i.left + n * Math.max(150, (a - 20) / Math.max(1, t.datasets.length));
1086
+ return `<rect x="${o}" y="${r - 18}" width="14" height="14" rx="3" fill="${e.color}"/><text x="${o + 22}" y="${r - 5}" fill="#4b5563" font-size="18" font-family="Arial, sans-serif">${Q(e.label)}</text>`;
1087
+ }).join("");
1088
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${n}" height="${r}" viewBox="0 0 ${n} ${r}"><rect width="100%" height="100%" fill="#ffffff"/><line x1="${i.left}" y1="${i.top}" x2="${i.left}" y2="${r - i.bottom}" stroke="#d1d5db"/><line x1="${i.left}" y1="${r - i.bottom}" x2="${n - i.right}" y2="${r - i.bottom}" stroke="#d1d5db"/>${p}${h}${m}${g}</svg>`;
1089
+ }
1090
+ async function qe(e) {
1091
+ if (typeof document > "u" || typeof Image > "u") throw Error("Chart image export requires a browser canvas");
1092
+ let t = Ke(e), n = new Blob([t], { type: "image/svg+xml;charset=utf-8" }), r = URL.createObjectURL(n);
1093
+ try {
1094
+ let e = await new Promise((e, t) => {
1095
+ let n = new Image();
1096
+ n.onload = () => e(n), n.onerror = () => t(/* @__PURE__ */ Error("Failed to render chart image")), n.src = r;
1097
+ }), t = document.createElement("canvas");
1098
+ t.width = e.naturalWidth || 1100, t.height = e.naturalHeight || 412;
1099
+ let n = t.getContext("2d");
1100
+ if (!n) throw Error("Browser canvas is unavailable");
1101
+ return n.fillStyle = "#ffffff", n.fillRect(0, 0, t.width, t.height), n.drawImage(e, 0, 0), t.toDataURL("image/png");
1102
+ } finally {
1103
+ URL.revokeObjectURL(r);
1104
+ }
1105
+ }
1106
+ function $(e, t = !1) {
1107
+ return new T({
1108
+ children: [new v({ children: [new O({
1109
+ ...K,
1110
+ text: Z(e),
1111
+ bold: t
1112
+ })] })],
1113
+ margins: q,
1114
+ verticalAlign: k.CENTER,
1115
+ shading: t ? {
1116
+ type: b.SOLID,
1117
+ color: "F4F5F6",
1118
+ fill: "F4F5F6"
1119
+ } : void 0,
1120
+ borders: {
1121
+ top: J,
1122
+ bottom: J,
1123
+ left: J,
1124
+ right: J
1125
+ }
1126
+ });
1127
+ }
1128
+ async function Je(e, t) {
1129
+ let n = t.attrs ?? {}, r = Array.isArray(n.labels) ? n.labels.map(Z) : [], i = Array.isArray(n.datasets) ? n.datasets : [], a = Z(n.title), o = Z(n.description), s = Z(n.note);
1130
+ if (r.length && i.length && typeof document < "u" && typeof Image < "u") {
1131
+ e.nextParentParagraphOpts = void 0, e.nextRunOpts = void 0, a && e.children.push(new v({ children: [new O({
1132
+ ...K,
1133
+ text: a,
1134
+ bold: !0
1135
+ })] })), o && e.children.push(new v({ children: [new O({
1136
+ ...K,
1137
+ text: o
1138
+ })] })), await e.image(await qe(n), 100, "center", void 0, "png"), e.closeBlock(t), s && e.children.push(new v({ children: [new O({
1139
+ ...K,
1140
+ text: s,
1141
+ italics: !0
1142
+ })] }));
1143
+ return;
1144
+ }
1145
+ a && e.children.push(new v({ children: [new O({
1146
+ ...K,
1147
+ text: a,
1148
+ bold: !0
1149
+ })] })), o && e.children.push(new v({ children: [new O({
1150
+ ...K,
1151
+ text: o
1152
+ })] }));
1153
+ let c = [new D({
1154
+ children: [$("", !0), ...r.map((e) => $(e, !0))],
1155
+ tableHeader: !0
1156
+ }), ...i.map((e) => {
1157
+ let t = Array.isArray(e?.values) ? e.values : [];
1158
+ return new D({ children: [$(Z(e?.label)), ...r.map((e, n) => $(t[n] ?? ""))] });
1159
+ })];
1160
+ if (c.length > 1) {
1161
+ let t = r.length + 1, n = Math.floor(G / t), i = Array.from({ length: t }, () => n);
1162
+ i[i.length - 1] += G - n * t, e.children.push(new w({
1163
+ rows: c,
1164
+ width: {
1165
+ size: G,
1166
+ type: A.DXA
1167
+ },
1168
+ columnWidths: i,
1169
+ layout: E.FIXED,
1170
+ margins: q,
1171
+ borders: {
1172
+ top: J,
1173
+ bottom: J,
1174
+ left: J,
1175
+ right: J,
1176
+ insideHorizontal: J,
1177
+ insideVertical: J
1178
+ },
1179
+ tableLook: {
1180
+ firstRow: !0,
1181
+ noHBand: !1,
1182
+ noVBand: !0
1183
+ }
1184
+ }));
1185
+ } else !a && !o && e.children.push(new v(""));
1186
+ s && e.children.push(new v({ children: [new O({
1187
+ text: s,
1188
+ italics: !0
1189
+ })] }));
1190
+ }
1191
+ async function Ye(e, t, n) {
1192
+ let r = !1;
1193
+ for (let i = 0; i < t.childCount; i += 1) {
1194
+ let a = t.child(i);
1195
+ a.type.name === "paragraph" && !r ? (e.addRunOptions({ ...K }), e.text(t.attrs?.checked ? "[x] " : "[ ] ", { bold: !0 }), e.addRunOptions({ ...K }), n ? await $e(e, a, n) : await e.renderInline(a), e.closeBlock(a, X(a)), r = !0) : await e.render(a, t, i);
1196
+ }
1197
+ r || e.closeBlock(t);
1198
+ }
1199
+ function Xe(e) {
1200
+ let t = 0;
1201
+ if (e.forEach((e) => {
1202
+ let n = 0;
1203
+ e.forEach((e) => {
1204
+ n += Math.max(1, Number(e.attrs?.colspan) || 1);
1205
+ }), t = Math.max(t, n);
1206
+ }), !t) return [];
1207
+ let n = Array.from({ length: t }, () => 0);
1208
+ e.forEach((e) => {
1209
+ let t = 0;
1210
+ e.forEach((e) => {
1211
+ let r = Math.max(1, Number(e.attrs?.colspan) || 1), i = Array.isArray(e.attrs?.colwidth) ? e.attrs.colwidth.map((e) => Number(e) || 0) : [Number(e.attrs?.colwidth) || 0];
1212
+ for (let e = 0; e < r; e += 1) {
1213
+ let r = i[e] || i[0] || 0;
1214
+ r > 0 && (n[t + e] = Math.max(n[t + e], r * 15));
1215
+ }
1216
+ t += r;
1217
+ });
1218
+ });
1219
+ let r = G / t, i = n.map((e) => e > 0 ? e : r), a = G / i.reduce((e, t) => e + t, 0), o = Math.min(720, Math.floor(G / t)), s = i.map((e) => Math.max(o, Math.round(e * a))), c = G - s.reduce((e, t) => e + t, 0);
1220
+ return s[s.length - 1] += c, s;
1221
+ }
1222
+ async function Ze(e, t) {
1223
+ let n = e.children, r = [], i = Xe(t);
1224
+ for (let n = 0; n < t.childCount; n += 1) {
1225
+ let a = t.child(n), o = [], s = 0;
1226
+ for (let t = 0; t < a.childCount; t += 1) {
1227
+ let n = a.child(t);
1228
+ e.children = [], n.type.name === "tableHeader" && e.addRunOptions({ bold: !0 }), await e.renderContent(n);
1229
+ let r = Y(n.attrs?.backgroundColor), c = { children: e.children }, l = Math.max(1, Number(n.attrs?.colspan) || 1);
1230
+ l > 1 && (c.columnSpan = l), n.attrs?.rowspan > 1 && (c.rowSpan = n.attrs.rowspan);
1231
+ let u = i.slice(s, s + l).reduce((e, t) => e + t, 0);
1232
+ u > 0 && (c.width = {
1233
+ size: u,
1234
+ type: A.DXA
1235
+ }), c.margins = q, c.verticalAlign = k.CENTER, r && (c.shading = {
1236
+ type: b.SOLID,
1237
+ color: r,
1238
+ fill: r
1239
+ }), o.push(new T(c)), s += l;
1240
+ }
1241
+ let c = a.childCount > 0 && Array.from({ length: a.childCount }).every((e, t) => a.child(t).type.name === "tableHeader");
1242
+ r.push(new D({
1243
+ children: o,
1244
+ tableHeader: c
1245
+ }));
1246
+ }
1247
+ e.children = n, n.push(new w({
1248
+ rows: r,
1249
+ width: {
1250
+ size: G,
1251
+ type: A.DXA
1252
+ },
1253
+ columnWidths: i,
1254
+ layout: E.FIXED,
1255
+ margins: q,
1256
+ borders: {
1257
+ top: J,
1258
+ bottom: J,
1259
+ left: J,
1260
+ right: J,
1261
+ insideHorizontal: J,
1262
+ insideVertical: J
1263
+ },
1264
+ tableLook: {
1265
+ firstRow: !0,
1266
+ noHBand: !1,
1267
+ noVBand: !0
1268
+ }
1269
+ })), n.push(new v(""));
1270
+ }
1271
+ function Qe(e, t) {
1272
+ let n = e.positions.get(t);
1273
+ if (n === void 0) return [];
1274
+ let r = n + 1, i = r + t.content.size;
1275
+ return e.comments.flatMap((t) => {
1276
+ let n = e.ids.get(t.id);
1277
+ if (n === void 0) return [];
1278
+ let a = [];
1279
+ return t.from >= r && t.from <= i && a.push({
1280
+ offset: t.from - r,
1281
+ kind: "start",
1282
+ id: n
1283
+ }), t.to >= r && t.to <= i && a.push({
1284
+ offset: t.to - r,
1285
+ kind: "end",
1286
+ id: n
1287
+ }), a;
1288
+ });
1289
+ }
1290
+ async function $e(e, t, n) {
1291
+ let r = Qe(n, t);
1292
+ if (!r.length) {
1293
+ await e.renderInline(t);
1294
+ return;
1295
+ }
1296
+ let s = (t) => {
1297
+ let n = r.filter((e) => e.offset === t);
1298
+ for (let t of n.filter((e) => e.kind === "end")) e.current.push(new i(t.id), new o(t.id));
1299
+ for (let t of n.filter((e) => e.kind === "start")) e.current.push(new a(t.id));
1300
+ }, l, u = () => {
1301
+ l &&= (e.current = [...l.stack, new c({
1302
+ link: l.link,
1303
+ children: e.current
1304
+ })], void 0);
1305
+ }, d = (t) => {
1306
+ l?.link !== t && (l && u(), e.addRunOptions({ style: "Hyperlink" }), l = {
1307
+ link: t,
1308
+ stack: e.current
1309
+ }, e.current = []);
1310
+ }, f = 0;
1311
+ s(0);
1312
+ for (let n = 0; n < t.childCount; n += 1) {
1313
+ let i = t.child(n), a = i.marks.find((e) => e.type.name === "link");
1314
+ if (a?.attrs?.href ? d(a.attrs.href) : l && u(), i.isText) {
1315
+ let t = i.text ?? "", n = 0, a = r.map((e) => e.offset - f).filter((e) => e > 0 && e < t.length).sort((e, t) => e - t);
1316
+ for (let r of [...a, t.length]) {
1317
+ let a = t.slice(n, r);
1318
+ a && e.text(a, e.renderMarks(i, [...i.marks])), f += r - n, s(f), n = r;
1319
+ }
1320
+ } else await e.render(i, t, n), f += 1, s(f);
1321
+ }
1322
+ u();
1323
+ }
1324
+ function et(n) {
1325
+ let i = {
1326
+ ...H,
1327
+ paragraph: async (e, t) => {
1328
+ e.addRunOptions({ ...K }), n ? await $e(e, t, n) : await e.renderInline(t), e.closeBlock(t, X(t));
1329
+ },
1330
+ blockquote: async (e, t) => {
1331
+ await e.renderContent(t, { style: "IntenseQuote" }), e.children.push(new v({
1332
+ spacing: {
1333
+ before: 0,
1334
+ after: 120,
1335
+ line: 240
1336
+ },
1337
+ children: []
1338
+ }));
1339
+ },
1340
+ heading: async (e, t) => {
1341
+ let n = [
1342
+ 48,
1343
+ 36,
1344
+ 29,
1345
+ 25,
1346
+ 23,
1347
+ 23
1348
+ ], r = Math.min(6, Math.max(1, Number(t.attrs?.level ?? 1)));
1349
+ e.addRunOptions({
1350
+ ...K,
1351
+ size: n[r - 1],
1352
+ bold: !0,
1353
+ color: "171717"
1354
+ }), await e.renderInline(t), e.closeBlock(t, {
1355
+ ...X(t),
1356
+ spacing: {
1357
+ before: r === 1 ? 0 : r === 2 ? 240 : 180,
1358
+ after: r === 1 ? 180 : 120,
1359
+ line: r === 1 ? 300 : 320
1360
+ },
1361
+ run: {
1362
+ ...K,
1363
+ size: n[r - 1],
1364
+ bold: !0,
1365
+ color: "171717"
1366
+ },
1367
+ heading: [
1368
+ f.HEADING_1,
1369
+ f.HEADING_2,
1370
+ f.HEADING_3,
1371
+ f.HEADING_4,
1372
+ f.HEADING_5,
1373
+ f.HEADING_6
1374
+ ][r - 1]
1375
+ });
1376
+ },
1377
+ bulletList: (e, t, n, r) => H.bullet_list(e, t, n, r),
1378
+ orderedList: (e, t, n, r) => H.ordered_list(e, t, n, r),
1379
+ listItem: (e, t, n, r) => H.list_item(e, t, n, r),
1380
+ taskList: async (e, t) => e.renderContent(t),
1381
+ taskItem: (e, t) => Ye(e, t, n),
1382
+ codeBlock: async (e, n) => {
1383
+ let i = typeof n.attrs?.code == "string" ? n.attrs.code : "", a = String(i.length > 0 ? i : n.textContent ?? "").replace(/\r\n?/g, "\n"), o = {
1384
+ font: {
1385
+ ascii: "Consolas",
1386
+ hAnsi: "Consolas",
1387
+ eastAsia: "Microsoft YaHei",
1388
+ cs: "Consolas"
1389
+ },
1390
+ size: 20,
1391
+ color: "334155"
1392
+ };
1393
+ e.nextParentParagraphOpts = void 0, e.nextRunOpts = void 0, e.current = [], a.split("\n").forEach((t, n) => {
1394
+ e.text(t, {
1395
+ ...o,
1396
+ break: n > 0 ? 1 : void 0
1397
+ });
1398
+ });
1399
+ let s = new v({
1400
+ children: e.current,
1401
+ alignment: t.LEFT,
1402
+ wordWrap: !0,
1403
+ widowControl: !1,
1404
+ autoSpaceEastAsianText: !1,
1405
+ indent: {
1406
+ left: 180,
1407
+ right: 180
1408
+ },
1409
+ spacing: {
1410
+ before: 160,
1411
+ after: 180,
1412
+ line: 300
1413
+ },
1414
+ shading: {
1415
+ type: b.SOLID,
1416
+ color: "F4F6F8",
1417
+ fill: "F4F6F8"
1418
+ },
1419
+ border: {
1420
+ top: J,
1421
+ bottom: J,
1422
+ left: {
1423
+ style: r.SINGLE,
1424
+ size: 12,
1425
+ color: "B7C0CC",
1426
+ space: 6
1427
+ },
1428
+ right: J
1429
+ },
1430
+ run: o
1431
+ });
1432
+ e.current = [], e.children.push(s);
1433
+ },
1434
+ image: async (e, t) => {
1435
+ await e.image(t.attrs?.src, He(t), Ue(t), void 0, Ve(t.attrs?.src || "")), e.closeBlock(t);
1436
+ },
1437
+ chart: Je,
1438
+ table: Ze,
1439
+ hardBreak: (e, t, n, r) => H.hard_break(e, t, n, r),
1440
+ horizontalRule: (e, t, n, r) => H.horizontal_rule(e, t, n, r),
1441
+ wordPage: async (e, t, n, r) => {
1442
+ await e.renderContent(t), r < n.childCount - 1 && e.nextSection();
1443
+ }
1444
+ };
1445
+ for (let t of e()) i[t.nodeType] = async (e, n) => {
1446
+ let r = t.resolve(n);
1447
+ r && tt(e, r);
1448
+ };
1449
+ return i;
1450
+ }
1451
+ function tt(e, t) {
1452
+ let n = t.title.trim(), r = t.description?.trim(), i = t.href?.trim(), a = t.actionLabel?.trim(), o = [];
1453
+ n && o.push(new O({
1454
+ ...K,
1455
+ text: n,
1456
+ bold: !0
1457
+ })), r && (o.length && o.push(new O({
1458
+ ...K,
1459
+ text: "\n",
1460
+ break: 1
1461
+ })), o.push(new O({
1462
+ ...K,
1463
+ text: r,
1464
+ color: "5F6773"
1465
+ }))), i && (o.length && o.push(new O({
1466
+ ...K,
1467
+ text: "\n",
1468
+ break: 1
1469
+ })), o.push(new c({
1470
+ link: i,
1471
+ children: [new O({
1472
+ ...K,
1473
+ text: a || i,
1474
+ style: "Hyperlink"
1475
+ })]
1476
+ }))), e.current = [], e.nextParentParagraphOpts = void 0, e.nextRunOpts = void 0, e.children.push(new v({
1477
+ children: o.length ? o : [new O({
1478
+ ...K,
1479
+ text: ""
1480
+ })],
1481
+ spacing: {
1482
+ before: 140,
1483
+ after: 180,
1484
+ line: 320
1485
+ },
1486
+ indent: {
1487
+ left: 180,
1488
+ right: 180
1489
+ },
1490
+ shading: {
1491
+ type: b.SOLID,
1492
+ color: "F4F6F8",
1493
+ fill: "F4F6F8"
1494
+ },
1495
+ border: {
1496
+ top: J,
1497
+ bottom: J,
1498
+ left: J,
1499
+ right: J
1500
+ }
1501
+ }));
1502
+ }
1503
+ function nt(e, t) {
1504
+ return (typeof e == "string" ? e.trim() : "") || t;
1505
+ }
1506
+ function rt(e) {
1507
+ let n = e.attrs?.header, r = e.attrs?.footer, i = !!n?.enabled, a = !!r?.enabled, o = i && n?.showOnFirstPage === !1 || a && r?.showOnFirstPage === !1, s = (e, n = !1) => {
1508
+ let r = nt(e?.leftContent || e?.content, ""), i = nt(e?.rightContent, ""), a = [];
1509
+ return r && a.push(new O(r)), (i || n && e?.showPageNumber) && a.push(new O(" ")), i && a.push(new O(i)), n && e?.showPageNumber && (i && a.push(new O(" ")), a.push(new x("PAGE"), new O(" / "), new x("NUMPAGES"))), new v({
1510
+ alignment: e?.alignment === "center" ? t.CENTER : e?.alignment === "right" ? t.RIGHT : t.LEFT,
1511
+ tabStops: i || n && e?.showPageNumber ? [{
1512
+ type: C.RIGHT,
1513
+ position: S.MAX
1514
+ }] : void 0,
1515
+ children: a.length ? a : [new O("")]
1516
+ });
1517
+ }, c = i ? new d({ children: [s(n)] }) : void 0, u = a ? new l({ children: [s(r, !0)] }) : void 0;
1518
+ return {
1519
+ properties: {
1520
+ type: y.NEXT_PAGE,
1521
+ titlePage: o,
1522
+ page: W
1523
+ },
1524
+ headers: i ? {
1525
+ default: c,
1526
+ ...o && n?.showOnFirstPage !== !1 ? { first: c } : {}
1527
+ } : void 0,
1528
+ footers: a ? {
1529
+ default: u,
1530
+ ...o && r?.showOnFirstPage !== !1 ? { first: u } : {}
1531
+ } : void 0
1532
+ };
1533
+ }
1534
+ function it(e) {
1535
+ return new B(et(e), {
1536
+ ...U,
1537
+ strike: U.strikethrough,
1538
+ strikethrough: U.strikethrough,
1539
+ textStyle: ze,
1540
+ highlight: Be
1541
+ });
1542
+ }
1543
+ async function at(e) {
1544
+ let t = await fetch(e);
1545
+ if (!t.ok) throw Error(`Failed to fetch image for DOCX export: ${t.status}`);
1546
+ return new Uint8Array(await t.arrayBuffer());
1547
+ }
1548
+ function ot(e) {
1549
+ return e.state.doc.firstChild?.type.name === "wordPage";
1550
+ }
1551
+ function st(e, t) {
1552
+ let n = t.resolveImage || at;
1553
+ return ot(e) ? {
1554
+ getImageBuffer: n,
1555
+ sections: e.state.doc.content.content.filter((e) => e.type.name === "wordPage").map(rt)
1556
+ } : {
1557
+ getImageBuffer: n,
1558
+ sections: [{ properties: {
1559
+ type: y.CONTINUOUS,
1560
+ page: W
1561
+ } }]
1562
+ };
1563
+ }
1564
+ function ct(e, t) {
1565
+ return t.comments ?? e.storage.wordComments?.comments ?? [];
1566
+ }
1567
+ async function lt(e, t = {}) {
1568
+ let n = ct(e, t);
1569
+ if (!n.length) return it().serializeAsync(e.state.doc, st(e, t));
1570
+ let r = /* @__PURE__ */ new WeakMap();
1571
+ e.state.doc.descendants((e, t) => {
1572
+ r.set(e, t);
1573
+ });
1574
+ let i = {
1575
+ comments: n,
1576
+ positions: r,
1577
+ ids: new Map(n.map((e, t) => [e.id, t]))
1578
+ }, a = { comments: { children: n.map((e, t) => {
1579
+ let n = e.author || "LangEditor", r = e.initials || n.split(/\s+/).map((e) => e[0]).join("").slice(0, 3).toUpperCase(), i = e.createdAt ? new Date(e.createdAt) : void 0;
1580
+ return {
1581
+ id: t,
1582
+ author: n,
1583
+ initials: r,
1584
+ date: i && Number.isFinite(i.getTime()) ? i : void 0,
1585
+ children: [new v({ children: [new O(e.content || "")] })]
1586
+ };
1587
+ }) } };
1588
+ return it(i).serializeAsync(e.state.doc, st(e, t), () => a);
1589
+ }
1590
+ //#endregion
1591
+ export { lt as createDocxDocument };