@blocknote/xl-odt-exporter 0.42.0 → 0.42.2

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.
@@ -1,33 +1,34 @@
1
1
  var I = Object.defineProperty;
2
2
  var N = (e, t, n) => t in e ? I(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
3
  var b = (e, t, n) => N(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { jsxs as f, Fragment as h, jsx as l } from "react/jsx-runtime";
4
+ import { jsxs as x, Fragment as h, jsx as l } from "react/jsx-runtime";
5
5
  import { mapTableCell as T, Exporter as M, COLORS_DEFAULT as B } from "@blocknote/core";
6
6
  import { ZipWriter as $, BlobWriter as W, TextReader as v, BlobReader as k } from "@zip.js/zip.js";
7
7
  import { renderToString as C } from "react-dom/server";
8
- const L = (e) => Array.from({ length: e }, () => /* @__PURE__ */ l("text:tab", {})), d = (e, t, n = "Standard", s = {}, a = {}, o = {}) => {
8
+ const L = (e) => Array.from({ length: e }, () => /* @__PURE__ */ l("text:tab", {})), g = (e, t, n = "Standard", s = {}, a = {}, o = {}) => {
9
+ var m, p;
9
10
  const y = {
10
11
  ...a
11
12
  }, i = { ...o };
12
13
  if (t.textAlignment && t.textAlignment !== "left") {
13
- const m = {
14
+ const d = {
14
15
  left: "start",
15
16
  center: "center",
16
17
  right: "end",
17
18
  justify: "justify"
18
19
  };
19
- y["fo:text-align"] = m[t.textAlignment];
20
+ y["fo:text-align"] = d[t.textAlignment];
20
21
  }
21
- const r = t.backgroundColor && t.backgroundColor !== "default" ? e.options.colors[t.backgroundColor].background : void 0;
22
+ const r = t.backgroundColor && t.backgroundColor !== "default" ? (m = e.options.colors[t.backgroundColor]) == null ? void 0 : m.background : void 0;
22
23
  if (r && (y["fo:background-color"] = r), t.textColor && t.textColor !== "default") {
23
- const m = e.options.colors[t.textColor].text;
24
- i["fo:color"] = m;
24
+ const d = ((p = e.options.colors[t.textColor]) == null ? void 0 : p.text) ?? t.textColor;
25
+ i["fo:color"] = d;
25
26
  }
26
- return !r && !Object.keys(s).length && !Object.keys(y).length && !Object.keys(i).length ? n || "Standard" : e.registerStyle((m) => /* @__PURE__ */ f(
27
+ return !r && !Object.keys(s).length && !Object.keys(y).length && !Object.keys(i).length ? n || "Standard" : e.registerStyle((d) => /* @__PURE__ */ x(
27
28
  "style:style",
28
29
  {
29
30
  "style:family": "paragraph",
30
- "style:name": m,
31
+ "style:name": d,
31
32
  "style:parent-style-name": n,
32
33
  ...s,
33
34
  children: [
@@ -49,19 +50,22 @@ const L = (e) => Array.from({ length: e }, () => /* @__PURE__ */ l("text:tab", {
49
50
  const s = `${n.props.backgroundColor}-${n.props.textColor}-${n.props.textAlignment}`;
50
51
  if (t.has(s))
51
52
  return t.get(s);
52
- const a = e.registerStyle((o) => /* @__PURE__ */ l("style:style", { "style:family": "table-cell", "style:name": o, children: /* @__PURE__ */ l(
53
- "style:table-cell-properties",
54
- {
55
- "fo:border": "0.5pt solid #000000",
56
- "style:writing-mode": "lr-tb",
57
- "fo:padding-top": "0in",
58
- "fo:padding-left": "0.075in",
59
- "fo:padding-bottom": "0in",
60
- "fo:padding-right": "0.075in",
61
- "fo:background-color": n.props.backgroundColor !== "default" && n.props.backgroundColor ? e.options.colors[n.props.backgroundColor].background : void 0,
62
- "fo:color": n.props.textColor !== "default" && n.props.textColor ? e.options.colors[n.props.textColor].text : void 0
63
- }
64
- ) }));
53
+ const a = e.registerStyle((o) => {
54
+ var y, i, r;
55
+ return /* @__PURE__ */ l("style:style", { "style:family": "table-cell", "style:name": o, children: /* @__PURE__ */ l(
56
+ "style:table-cell-properties",
57
+ {
58
+ "fo:border": "0.5pt solid #000000",
59
+ "style:writing-mode": "lr-tb",
60
+ "fo:padding-top": "0in",
61
+ "fo:padding-left": "0.075in",
62
+ "fo:padding-bottom": "0in",
63
+ "fo:padding-right": "0.075in",
64
+ "fo:background-color": n.props.backgroundColor !== "default" && n.props.backgroundColor ? (i = (y = e.options.colors) == null ? void 0 : y[n.props.backgroundColor]) == null ? void 0 : i.background : void 0,
65
+ "fo:color": n.props.textColor !== "default" && n.props.textColor ? (r = e.options.colors[n.props.textColor]) == null ? void 0 : r.text : void 0
66
+ }
67
+ ) });
68
+ });
65
69
  return t.set(s, a), a;
66
70
  };
67
71
  }, P = (e, t) => e.registerStyle((s) => /* @__PURE__ */ l("style:style", { "style:family": "table", "style:name": s, children: /* @__PURE__ */ l(
@@ -73,22 +77,22 @@ const L = (e) => Array.from({ length: e }, () => /* @__PURE__ */ l("text:tab", {
73
77
  }
74
78
  ) })), S = (e, t) => t <= 0 ? e : /* @__PURE__ */ l("text:list", { children: /* @__PURE__ */ l("text:list-item", { children: S(e, t - 1) }) }), O = {
75
79
  paragraph: (e, t, n) => {
76
- const s = d(
80
+ const s = g(
77
81
  t,
78
82
  e.props
79
83
  );
80
- return /* @__PURE__ */ f("text:p", { "text:style-name": s, children: [
84
+ return /* @__PURE__ */ x("text:p", { "text:style-name": s, children: [
81
85
  L(n),
82
86
  t.transformInlineContent(e.content)
83
87
  ] });
84
88
  },
85
89
  heading: (e, t, n) => {
86
- const a = d(
90
+ const a = g(
87
91
  t,
88
92
  e.props,
89
93
  "Heading_20_" + e.props.level
90
94
  );
91
- return /* @__PURE__ */ f(
95
+ return /* @__PURE__ */ x(
92
96
  "text:h",
93
97
  {
94
98
  "text:outline-level": `${e.props.level}`,
@@ -101,7 +105,7 @@ const L = (e) => Array.from({ length: e }, () => /* @__PURE__ */ l("text:tab", {
101
105
  );
102
106
  },
103
107
  quote: (e, t, n) => {
104
- const a = d(
108
+ const a = g(
105
109
  t,
106
110
  e.props,
107
111
  "Standard",
@@ -114,7 +118,7 @@ const L = (e) => Array.from({ length: e }, () => /* @__PURE__ */ l("text:tab", {
114
118
  "fo:color": "#7D797A"
115
119
  }
116
120
  );
117
- return /* @__PURE__ */ f("text:p", { "text:style-name": a, children: [
121
+ return /* @__PURE__ */ x("text:p", { "text:style-name": a, children: [
118
122
  L(n),
119
123
  t.transformInlineContent(e.content)
120
124
  ] });
@@ -129,12 +133,12 @@ const L = (e) => Array.from({ length: e }, () => /* @__PURE__ */ l("text:tab", {
129
133
  *
130
134
  * (LibreOffice does nicely wrap the list items in the same list element)
131
135
  */
132
- toggleListItem: (e, t) => /* @__PURE__ */ f("text:p", { "text:style-name": "Standard", children: [
136
+ toggleListItem: (e, t) => /* @__PURE__ */ x("text:p", { "text:style-name": "Standard", children: [
133
137
  "> ",
134
138
  t.transformInlineContent(e.content)
135
139
  ] }),
136
140
  bulletListItem: (e, t, n) => {
137
- const s = d(
141
+ const s = g(
138
142
  t,
139
143
  e.props,
140
144
  "Standard",
@@ -146,7 +150,7 @@ const L = (e) => Array.from({ length: e }, () => /* @__PURE__ */ l("text:tab", {
146
150
  ) }) });
147
151
  },
148
152
  numberedListItem: (e, t, n, s) => {
149
- const a = d(
153
+ const a = g(
150
154
  t,
151
155
  e.props
152
156
  ), o = (s || 0) > 1 ? "true" : "false";
@@ -170,13 +174,13 @@ const L = (e) => Array.from({ length: e }, () => /* @__PURE__ */ l("text:tab", {
170
174
  }
171
175
  );
172
176
  },
173
- checkListItem: (e, t) => /* @__PURE__ */ f("text:p", { "text:style-name": "Standard", children: [
177
+ checkListItem: (e, t) => /* @__PURE__ */ x("text:p", { "text:style-name": "Standard", children: [
174
178
  e.props.checked ? "☒ " : "☐ ",
175
179
  t.transformInlineContent(e.content)
176
180
  ] }),
177
181
  pageBreak: async () => /* @__PURE__ */ l("text:p", { "text:style-name": "PageBreak" }),
178
182
  divider: (e, t) => {
179
- const n = d(
183
+ const n = g(
180
184
  t,
181
185
  e.props,
182
186
  "Standard",
@@ -213,24 +217,24 @@ const L = (e) => Array.from({ length: e }, () => /* @__PURE__ */ l("text:tab", {
213
217
  "style:writing-mode": "lr-tb"
214
218
  }
215
219
  ) }));
216
- return /* @__PURE__ */ f("table:table", { "table:name": e.id, "table:style-name": i, children: [
220
+ return /* @__PURE__ */ x("table:table", { "table:name": e.id, "table:style-name": i, children: [
217
221
  (o.children || []).map((r, m) => {
218
- const x = y.registerStyle((g) => /* @__PURE__ */ l("style:style", { "style:name": g, "style:family": "table-column", children: /* @__PURE__ */ l(
222
+ const p = y.registerStyle((d) => /* @__PURE__ */ l("style:style", { "style:name": d, "style:family": "table-column", children: /* @__PURE__ */ l(
219
223
  "style:table-column-properties",
220
224
  {
221
225
  "style:rel-column-width": `${r.props.width * 100}*`
222
226
  }
223
227
  ) }));
224
- return /* @__PURE__ */ l("table:table-column", { "table:style-name": x }, m);
228
+ return /* @__PURE__ */ l("table:table-column", { "table:style-name": p }, m);
225
229
  }),
226
230
  /* @__PURE__ */ l("table:table-row", { children: a })
227
231
  ] });
228
232
  },
229
233
  image: async (e, t) => {
230
- const n = t, { path: s, mimeType: a, ...o } = await n.registerPicture(e.props.url), y = d(
234
+ const n = t, { path: s, mimeType: a, ...o } = await n.registerPicture(e.props.url), y = g(
231
235
  t,
232
236
  e.props
233
- ), i = e.props.previewWidth || o.width, r = o.height / o.width * i, m = 20, x = /* @__PURE__ */ f("text:p", { "text:style-name": e.props.caption ? "Caption" : y, children: [
237
+ ), i = e.props.previewWidth || o.width, r = o.height / o.width * i, m = 20, p = /* @__PURE__ */ x("text:p", { "text:style-name": e.props.caption ? "Caption" : y, children: [
234
238
  /* @__PURE__ */ l(
235
239
  "draw:frame",
236
240
  {
@@ -266,28 +270,28 @@ const L = (e) => Array.from({ length: e }, () => /* @__PURE__ */ l("text:tab", {
266
270
  "svg:width": `${i}px`,
267
271
  "svg:height": `${r + m}px`,
268
272
  "text:anchor-type": "as-char",
269
- children: /* @__PURE__ */ l("draw:text-box", { children: x })
273
+ children: /* @__PURE__ */ l("draw:text-box", { children: p })
270
274
  }
271
- ) }) : x;
275
+ ) }) : p;
272
276
  },
273
277
  table: (e, t) => {
274
278
  var r;
275
279
  const a = (e.content.columnWidths.reduce(
276
- (m, x) => (m || 0) + (x || 120),
280
+ (m, p) => (m || 0) + (p || 120),
277
281
  0
278
282
  ) || 0) * 0.75, o = t, y = A(o), i = P(o, { width: a });
279
- return /* @__PURE__ */ f("table:table", { "table:name": e.id, "table:style-name": i, children: [
280
- (r = e.content.rows[0]) == null ? void 0 : r.cells.map((m, x) => {
281
- const u = (e.content.columnWidths[x] || 120) * 0.75, c = o.registerStyle((_) => /* @__PURE__ */ l("style:style", { "style:name": _, "style:family": "table-column", children: /* @__PURE__ */ l(
283
+ return /* @__PURE__ */ x("table:table", { "table:name": e.id, "table:style-name": i, children: [
284
+ (r = e.content.rows[0]) == null ? void 0 : r.cells.map((m, p) => {
285
+ const u = (e.content.columnWidths[p] || 120) * 0.75, c = o.registerStyle((_) => /* @__PURE__ */ l("style:style", { "style:name": _, "style:family": "table-column", children: /* @__PURE__ */ l(
282
286
  "style:table-column-properties",
283
287
  {
284
288
  "style:column-width": `${u}pt`
285
289
  }
286
290
  ) }));
287
- return /* @__PURE__ */ l("table:table-column", { "table:style-name": c }, x);
291
+ return /* @__PURE__ */ l("table:table-column", { "table:style-name": c }, p);
288
292
  }),
289
- e.content.rows.map((m, x) => /* @__PURE__ */ l("table:table-row", { children: m.cells.map((g, u) => {
290
- const c = T(g);
293
+ e.content.rows.map((m, p) => /* @__PURE__ */ l("table:table-row", { children: m.cells.map((d, u) => {
294
+ const c = T(d);
291
295
  return /* @__PURE__ */ l(
292
296
  "table:table-cell",
293
297
  {
@@ -297,23 +301,23 @@ const L = (e) => Array.from({ length: e }, () => /* @__PURE__ */ l("text:tab", {
297
301
  "style:paragraph-properties-text-align": c.props.textAlignment,
298
302
  children: /* @__PURE__ */ l("text:p", { "text:style-name": "Standard", children: t.transformInlineContent(c.content) })
299
303
  },
300
- `${x}-${u}`
304
+ `${p}-${u}`
301
305
  );
302
- }) }, x))
306
+ }) }, p))
303
307
  ] });
304
308
  },
305
309
  codeBlock: (e) => {
306
310
  var n;
307
311
  const t = ((n = e.content[0]) == null ? void 0 : n.text) || "";
308
- return /* @__PURE__ */ f("text:p", { "text:style-name": "Codeblock", children: [
312
+ return /* @__PURE__ */ x("text:p", { "text:style-name": "Codeblock", children: [
309
313
  ...t.split(`
310
- `).map((s, a) => /* @__PURE__ */ f(h, { children: [
314
+ `).map((s, a) => /* @__PURE__ */ x(h, { children: [
311
315
  a !== 0 && /* @__PURE__ */ l("text:line-break", {}),
312
316
  s
313
317
  ] }))
314
318
  ] });
315
319
  },
316
- file: async (e) => /* @__PURE__ */ f(h, { children: [
320
+ file: async (e) => /* @__PURE__ */ x(h, { children: [
317
321
  /* @__PURE__ */ l("text:p", { "style:style-name": "Standard", children: e.props.url ? /* @__PURE__ */ l(
318
322
  "text:a",
319
323
  {
@@ -327,7 +331,7 @@ const L = (e) => Array.from({ length: e }, () => /* @__PURE__ */ l("text:tab", {
327
331
  ) : "Open file" }),
328
332
  e.props.caption && /* @__PURE__ */ l("text:p", { "text:style-name": "Caption", children: e.props.caption })
329
333
  ] }),
330
- video: (e) => /* @__PURE__ */ f(h, { children: [
334
+ video: (e) => /* @__PURE__ */ x(h, { children: [
331
335
  /* @__PURE__ */ l("text:p", { "style:style-name": "Standard", children: /* @__PURE__ */ l(
332
336
  "text:a",
333
337
  {
@@ -341,7 +345,7 @@ const L = (e) => Array.from({ length: e }, () => /* @__PURE__ */ l("text:tab", {
341
345
  ) }),
342
346
  e.props.caption && /* @__PURE__ */ l("text:p", { "text:style-name": "Caption", children: e.props.caption })
343
347
  ] }),
344
- audio: (e) => /* @__PURE__ */ f(h, { children: [
348
+ audio: (e) => /* @__PURE__ */ x(h, { children: [
345
349
  /* @__PURE__ */ l("text:p", { "style:style-name": "Standard", children: /* @__PURE__ */ l(
346
350
  "text:a",
347
351
  {
@@ -376,8 +380,20 @@ const L = (e) => Array.from({ length: e }, () => /* @__PURE__ */ l("text:tab", {
376
380
  italic: (e) => e ? { "fo:font-style": "italic" } : {},
377
381
  underline: (e) => e ? { "style:text-underline-style": "solid" } : {},
378
382
  strike: (e) => e ? { "style:text-line-through-style": "solid" } : {},
379
- textColor: (e, t) => e ? { "fo:color": t.options.colors[e].text } : {},
380
- backgroundColor: (e, t) => e ? { "fo:background-color": t.options.colors[e].background } : {},
383
+ textColor: (e, t) => {
384
+ var s;
385
+ if (!e)
386
+ return {};
387
+ const n = (s = t.options.colors[e]) == null ? void 0 : s.text;
388
+ return n ? { "fo:color": n } : {};
389
+ },
390
+ backgroundColor: (e, t) => {
391
+ var s;
392
+ if (!e)
393
+ return {};
394
+ const n = (s = t.options.colors[e]) == null ? void 0 : s.background;
395
+ return n ? { "fo:background-color": n } : {};
396
+ },
381
397
  code: (e) => e ? { "style:font-name": "Courier New" } : {}
382
398
  }, J = {
383
399
  blockMapping: O,
@@ -1551,11 +1567,11 @@ class K extends M {
1551
1567
  return a;
1552
1568
  }
1553
1569
  async toODTDocument(n, s) {
1554
- const a = (p) => {
1570
+ const a = (f) => {
1555
1571
  const z = /<([a-zA-Z0-9:]+)\s+?(?:xml)ns(?::[a-zA-Z0-9]+)?=".*"(.*)>/g;
1556
1572
  let w = "";
1557
- return typeof p == "string" ? w = p : w = new XMLSerializer().serializeToString(p), w.replace(z, "<$1$2>");
1558
- }, o = await this.transformBlocks(n), y = Array.from(this.automaticStyles.values()), i = Array.from(this.pictures.values()), r = await this.loadFonts(), m = a((s == null ? void 0 : s.header) || ""), x = a((s == null ? void 0 : s.footer) || ""), g = /* @__PURE__ */ f(
1573
+ return typeof f == "string" ? w = f : w = new XMLSerializer().serializeToString(f), w.replace(z, "<$1$2>");
1574
+ }, o = await this.transformBlocks(n), y = Array.from(this.automaticStyles.values()), i = Array.from(this.pictures.values()), r = await this.loadFonts(), m = a((s == null ? void 0 : s.header) || ""), p = a((s == null ? void 0 : s.footer) || ""), d = /* @__PURE__ */ x(
1559
1575
  "office:document-content",
1560
1576
  {
1561
1577
  "xmlns:office": "urn:oasis:names:tc:opendocument:xmlns:office:1.0",
@@ -1569,16 +1585,16 @@ class K extends M {
1569
1585
  "xmlns:loext": "urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0",
1570
1586
  "office:version": "1.3",
1571
1587
  children: [
1572
- /* @__PURE__ */ l("office:font-face-decls", { children: r.map((p) => /* @__PURE__ */ l(
1588
+ /* @__PURE__ */ l("office:font-face-decls", { children: r.map((f) => /* @__PURE__ */ l(
1573
1589
  "style:font-face",
1574
1590
  {
1575
- "style:name": p.name,
1576
- "svg:font-family": p.name,
1591
+ "style:name": f.name,
1592
+ "svg:font-family": f.name,
1577
1593
  "style:font-pitch": "variable",
1578
1594
  children: /* @__PURE__ */ l("svg:font-face-src", { children: /* @__PURE__ */ l(
1579
1595
  "svg:font-face-uri",
1580
1596
  {
1581
- "xlink:href": `Fonts/${p.fileName}`,
1597
+ "xlink:href": `Fonts/${f.fileName}`,
1582
1598
  "xlink:type": "simple",
1583
1599
  "loext:font-style": "normal",
1584
1600
  "loext:font-weight": "normal",
@@ -1588,7 +1604,7 @@ class K extends M {
1588
1604
  }
1589
1605
  )) }),
1590
1606
  /* @__PURE__ */ l("office:automatic-styles", { children: y }),
1591
- (m || x) && /* @__PURE__ */ l("office:master-styles", { children: /* @__PURE__ */ f(
1607
+ (m || p) && /* @__PURE__ */ l("office:master-styles", { children: /* @__PURE__ */ x(
1592
1608
  "style:master-page",
1593
1609
  {
1594
1610
  "style:name": "Standard",
@@ -1603,11 +1619,11 @@ class K extends M {
1603
1619
  }
1604
1620
  }
1605
1621
  ),
1606
- x && /* @__PURE__ */ l(
1622
+ p && /* @__PURE__ */ l(
1607
1623
  "style:footer",
1608
1624
  {
1609
1625
  dangerouslySetInnerHTML: {
1610
- __html: x
1626
+ __html: p
1611
1627
  }
1612
1628
  }
1613
1629
  )
@@ -1617,7 +1633,7 @@ class K extends M {
1617
1633
  /* @__PURE__ */ l("office:body", { children: /* @__PURE__ */ l("office:text", { children: o }) })
1618
1634
  ]
1619
1635
  }
1620
- ), u = /* @__PURE__ */ f(
1636
+ ), u = /* @__PURE__ */ x(
1621
1637
  "manifest:manifest",
1622
1638
  {
1623
1639
  "xmlns:manifest": "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0",
@@ -1644,18 +1660,18 @@ class K extends M {
1644
1660
  "manifest:full-path": "styles.xml"
1645
1661
  }
1646
1662
  ),
1647
- i.map((p) => /* @__PURE__ */ l(
1663
+ i.map((f) => /* @__PURE__ */ l(
1648
1664
  "manifest:file-entry",
1649
1665
  {
1650
- "manifest:media-type": p.file.type,
1651
- "manifest:full-path": `Pictures/${p.fileName}`
1666
+ "manifest:media-type": f.file.type,
1667
+ "manifest:full-path": `Pictures/${f.fileName}`
1652
1668
  }
1653
1669
  )),
1654
- r.map((p) => /* @__PURE__ */ l(
1670
+ r.map((f) => /* @__PURE__ */ l(
1655
1671
  "manifest:file-entry",
1656
1672
  {
1657
1673
  "manifest:media-type": "application/x-font-ttf",
1658
- "manifest:full-path": `Fonts/${p.fileName}`
1674
+ "manifest:full-path": `Fonts/${f.fileName}`
1659
1675
  }
1660
1676
  ))
1661
1677
  ]
@@ -1673,13 +1689,13 @@ class K extends M {
1673
1689
  extendedTimestamp: !1
1674
1690
  }
1675
1691
  );
1676
- const _ = C(g), F = C(u);
1677
- return c.add("content.xml", new v(_)), c.add("styles.xml", new v(j)), c.add("META-INF/manifest.xml", new v(F)), r.forEach((p) => {
1678
- c.add(`Fonts/${p.fileName}`, new k(p.data));
1679
- }), i.forEach((p) => {
1692
+ const _ = C(d), F = C(u);
1693
+ return c.add("content.xml", new v(_)), c.add("styles.xml", new v(j)), c.add("META-INF/manifest.xml", new v(F)), r.forEach((f) => {
1694
+ c.add(`Fonts/${f.fileName}`, new k(f.data));
1695
+ }), i.forEach((f) => {
1680
1696
  c.add(
1681
- `Pictures/${p.fileName}`,
1682
- new k(p.file)
1697
+ `Pictures/${f.fileName}`,
1698
+ new k(f.file)
1683
1699
  );
1684
1700
  }), c.close();
1685
1701
  }