@pretextbook/import 0.11.0 → 0.13.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/dist/index.js CHANGED
@@ -1,15 +1,15 @@
1
- import { i as W, P as H, d as U, r as G, a as V, f as C, b as R, w as v, s as k, e as q, c as Z, p as Y, g as $, h as J, j as Q } from "./upload-H_OCZBBn.js";
2
- import { C as Xe, D as ze, L as Be, k as Ke, l as We, M as He, m as Ue, n as Ge, o as Ve, q as qe, t as Ze, u as Ye, v as Je, x as Qe, y as et, z as tt, A as nt, B as rt, E as ot, F as st, G as at, H as it, I as ct, J as lt, K as ut, N as pt, O as dt, Q as mt, R as ft, S as ht, T as gt, U as wt, V as Tt, W as xt, X as Pt, Y as Et, Z as vt, _ as St, $ as bt, a0 as It, a1 as _t, a2 as $t, a3 as At, a4 as Ft, a5 as Lt, a6 as yt, a7 as Ct, a8 as Rt, a9 as kt, aa as Dt, ab as Mt, ac as Ot, ad as Nt, ae as jt, af as Xt, ag as zt, ah as Bt, ai as Kt, aj as Wt, ak as Ht, al as Ut, am as Gt } from "./upload-H_OCZBBn.js";
3
- import { D as qt, a as Zt, d as Yt, b as Jt, c as Qt, f as en, e as tn, g as nn, h as rn, p as on, r as sn } from "./import-mode-DQ8g5P8P.js";
4
- const ee = /\$(?![\s$])([^$\n]{1,200})\$/;
5
- function te(e) {
6
- const t = ee.exec(e);
1
+ import { i as Z, P as Y, f as M, d as J, r as Q, a as ee, b as N, c as O, w as b, s as j, e as te, g as ne, p as re, h as $, j as se, k as ae } from "./upload-DJuIYze6.js";
2
+ import { C as Ze, D as Ye, L as Je, l as Qe, m as et, M as tt, n as nt, o as rt, q as st, t as at, u as ot, v as it, x as ct, y as lt, z as ut, A as dt, B as pt, E as mt, F as ft, G as ht, H as gt, I as xt, J as wt, K as Tt, N as Pt, O as Et, Q as bt, R as vt, S as St, T as It, U as At, V as _t, W as $t, X as kt, Y as yt, Z as Lt, _ as Ft, $ as Ct, a0 as Rt, a1 as Dt, a2 as Mt, a3 as Nt, a4 as Ot, a5 as jt, a6 as Xt, a7 as zt, a8 as qt, a9 as Bt, aa as Kt, ab as Wt, ac as Gt, ad as Ht, ae as Ut, af as Vt, ag as Zt, ah as Yt, ai as Jt, aj as Qt, ak as en, al as tn, am as nn, an as rn } from "./upload-DJuIYze6.js";
3
+ import { D as an, a as on, b as cn, c as ln, d as un, e as dn, f as pn, g as mn, h as fn, i as hn, j as gn, k as xn, l as wn, m as Tn, n as Pn, o as En, p as bn, r as vn, q as Sn, u as In } from "./engine-routing-UEp8JP8x.js";
4
+ const oe = /\$(?![\s$])([^$\n]{1,200})\$/;
5
+ function ie(e) {
6
+ const t = oe.exec(e);
7
7
  if (!t)
8
8
  return !1;
9
- const n = t[1];
10
- return /[\\^_{}]/.test(n) || /^[A-Za-z]'?$/.test(n.trim());
9
+ const r = t[1];
10
+ return /[\\^_{}]/.test(r) || /^[A-Za-z]'?$/.test(r.trim());
11
11
  }
12
- const ne = [
12
+ const ce = [
13
13
  // \begin{...} / \end{...} — unambiguous.
14
14
  { pattern: /\\(?:begin|end)\{[a-zA-Z*]+\}/, weight: 3 },
15
15
  // Display math, either delimiter style.
@@ -22,7 +22,7 @@ const ne = [
22
22
  { pattern: /\\[a-zA-Z]+\b/, weight: 1 },
23
23
  // Label/ref machinery is a strong hint even without braces nearby.
24
24
  { pattern: /\\(?:label|ref|eqref|cite)\b/, weight: 2 }
25
- ], re = [
25
+ ], le = [
26
26
  // ATX heading.
27
27
  { pattern: /^#{1,6}\s+\S/m, weight: 3 },
28
28
  // Fenced code block.
@@ -41,25 +41,25 @@ const ne = [
41
41
  { pattern: /(?:^|\s)_[^_\s][^_\n]*_(?:\s|[.,;:!?]|$)/, weight: 1 },
42
42
  // Inline code span.
43
43
  { pattern: /`[^`\n]+`/, weight: 1 }
44
- ], oe = 2;
45
- function A(e, t) {
44
+ ], ue = 2;
45
+ function k(e, t) {
46
46
  return t.reduce(
47
- (n, { pattern: r, weight: o }) => n + (r.test(e) ? o : 0),
47
+ (r, { pattern: n, weight: s }) => r + (n.test(e) ? s : 0),
48
48
  0
49
49
  );
50
50
  }
51
- function se(e) {
52
- return { latex: A(e, ne) + (te(e) ? 2 : 0), markdown: A(e, re) };
51
+ function de(e) {
52
+ return { latex: k(e, ce) + (ie(e) ? 2 : 0), markdown: k(e, le) };
53
53
  }
54
- function Fe(e) {
54
+ function Oe(e) {
55
55
  const t = e.trim();
56
56
  if (!t || t.startsWith("<"))
57
57
  return;
58
- const { latex: n, markdown: r } = se(t);
59
- if (!(Math.max(n, r) < oe))
60
- return n >= r ? "latex" : "markdown";
58
+ const { latex: r, markdown: n } = de(t);
59
+ if (!(Math.max(r, n) < ue))
60
+ return r >= n ? "latex" : "markdown";
61
61
  }
62
- const ae = {
62
+ const pe = {
63
63
  png: "image/png",
64
64
  jpg: "image/jpeg",
65
65
  jpeg: "image/jpeg",
@@ -73,28 +73,28 @@ const ae = {
73
73
  webp: "image/webp",
74
74
  ico: "image/vnd.microsoft.icon"
75
75
  };
76
- function ie(e) {
76
+ function me(e) {
77
77
  const t = e.split(".").pop()?.toLowerCase() ?? "";
78
- return ae[t] ?? "application/octet-stream";
78
+ return pe[t] ?? "application/octet-stream";
79
79
  }
80
80
  const P = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
81
- function ce(e) {
82
- const t = e.length, n = [];
83
- for (let r = 0; r < t; r += 3) {
84
- const o = e[r], a = r + 1 < t, s = r + 2 < t, i = a ? e[r + 1] : 0, c = s ? e[r + 2] : 0;
85
- n.push(P[o >> 2]), n.push(P[(o & 3) << 4 | i >> 4]), n.push(a ? P[(i & 15) << 2 | c >> 6] : "="), n.push(s ? P[c & 63] : "=");
81
+ function fe(e) {
82
+ const t = e.length, r = [];
83
+ for (let n = 0; n < t; n += 3) {
84
+ const s = e[n], o = n + 1 < t, a = n + 2 < t, i = o ? e[n + 1] : 0, c = a ? e[n + 2] : 0;
85
+ r.push(P[s >> 2]), r.push(P[(s & 3) << 4 | i >> 4]), r.push(o ? P[(i & 15) << 2 | c >> 6] : "="), r.push(a ? P[c & 63] : "=");
86
86
  }
87
- return n.join("");
87
+ return r.join("");
88
88
  }
89
- function D(e) {
89
+ function X(e) {
90
90
  return {
91
91
  ref: e.ref,
92
92
  fileName: e.fileName,
93
- contentType: ie(e.fileName),
94
- data: ce(e.data)
93
+ contentType: me(e.fileName),
94
+ data: fe(e.data)
95
95
  };
96
96
  }
97
- function M(e) {
97
+ function z(e) {
98
98
  return {
99
99
  ref: e.xmlId,
100
100
  source: e.content,
@@ -102,16 +102,16 @@ function M(e) {
102
102
  isRoot: e.isRoot
103
103
  };
104
104
  }
105
- function le(e) {
105
+ function he(e) {
106
106
  return {
107
107
  title: e.title,
108
108
  docinfo: e.docinfo,
109
109
  documentKind: e.documentKind,
110
- divisions: e.divisions.map(M),
111
- assets: e.assets.map(D)
110
+ divisions: e.divisions.map(z),
111
+ assets: e.assets.map(X)
112
112
  };
113
113
  }
114
- function ue(e) {
114
+ function ge(e) {
115
115
  return {
116
116
  ref: e.ref,
117
117
  kind: "file",
@@ -124,7 +124,7 @@ function ue(e) {
124
124
  }
125
125
  };
126
126
  }
127
- function pe(e) {
127
+ function xe(e) {
128
128
  return {
129
129
  title: e.title,
130
130
  docinfo: e.docinfo,
@@ -135,55 +135,124 @@ function pe(e) {
135
135
  source_format: t.sourceFormat,
136
136
  is_root: t.isRoot
137
137
  })),
138
- assets_attributes: e.assets.map(ue)
138
+ assets_attributes: e.assets.map(ge)
139
139
  };
140
140
  }
141
- function Le(e) {
142
- return pe(le(e));
141
+ function je(e) {
142
+ return xe(he(e));
143
143
  }
144
- function ye(e, t) {
145
- const { root: n, entries: r } = W(e, t), o = new Set(r.map((s) => s.xmlId)), a = e.divisions.filter(
146
- (s) => !o.has(s.xmlId) && !(t.unwrapRoot && s.xmlId === n.xmlId)
144
+ function Xe(e, t) {
145
+ const { root: r, entries: n } = Z(e, t), s = new Set(n.map((a) => a.xmlId)), o = e.divisions.filter(
146
+ (a) => !s.has(a.xmlId) && !(t.unwrapRoot && a.xmlId === r.xmlId)
147
147
  );
148
148
  return {
149
- divisions: [...r, ...a].map(M),
150
- assets: e.assets.map(D),
151
- placeholders: r.map(
152
- (s) => `<plus:${s.type} ref="${s.xmlId}"/>`
149
+ divisions: [...n, ...o].map(z),
150
+ assets: e.assets.map(X),
151
+ placeholders: n.map(
152
+ (a) => `<plus:${a.type} ref="${a.xmlId}"/>`
153
153
  )
154
154
  };
155
155
  }
156
- const F = /<(\/?)p(?=[\s>/])/g;
157
- function Ce(e) {
156
+ const y = /<(\/?)p(?=[\s>/])/g;
157
+ function ze(e) {
158
158
  let t = 0;
159
- F.lastIndex = 0;
160
- let n;
161
- for (; (n = F.exec(e)) !== null; )
162
- t += n[1] ? -1 : 1;
159
+ y.lastIndex = 0;
160
+ let r;
161
+ for (; (r = y.exec(e)) !== null; )
162
+ t += r[1] ? -1 : 1;
163
163
  return t > 0;
164
164
  }
165
- const de = new RegExp(
166
- `<(${H.join("|")})(?=[\\s>/])`
165
+ const we = new RegExp(
166
+ `<(${Y.join("|")})(?=[\\s>/])`
167
167
  );
168
- function me(e) {
169
- return de.exec(e)?.[1];
168
+ function qe(e) {
169
+ return we.exec(e)?.[1];
170
170
  }
171
- function fe(e, t, n) {
171
+ function Te(e, t, r) {
172
172
  return e.split(`
173
173
  `).map(
174
- (r, o) => o === 0 && n ? r : r && t + r
174
+ (n, s) => s === 0 && r ? n : n && t + n
175
175
  ).join(`
176
176
  `);
177
177
  }
178
- function Re(e, t) {
179
- let n = e.trim(), r;
180
- if (t.inline) {
181
- const o = n.replace(/^<p>\s*([\s\S]*?)\s*<\/p>$/, "$1");
182
- n = o !== n ? o : n.replace(/^<p>/, "");
183
- const a = me(n);
184
- a && (r = `Pasted content produced a <${a}>, which cannot sit inside a <p>. It was inserted as-is — move it out of the paragraph to make the document valid.`);
185
- }
186
- return t.baseIndent && (n = fe(n, t.baseIndent, t.midLine)), { markup: n, warning: r };
178
+ const q = new Set(
179
+ `abbr acro ad alert am angles articletitle attr bc c ca cd chord copyleft
180
+ copyright custom dataurl dblbrackets dblprime degree delete dl doubleflat
181
+ doublesharp eg ellipsis em email etal etc fillin flat fn foreign icon idx
182
+ ie init insert kbd langle latex ldblbracket line lq lsq m md mdash midpoint
183
+ minus n natural nb nbsp ndash obelus ol permille pf phonomark pilcrow
184
+ plusminus pm prime ps pubtitle q quantity rangle rdblbracket registered rq
185
+ rsq scaledeg section-mark servicemark sharp solidus sq stale swungdash tag
186
+ tage taxon term tex timeofday times timesignature today trademark ul url
187
+ var viz vs xelatex xetex xref`.trim().split(/\s+/)
188
+ ), L = /<!--[\s\S]*?-->/g;
189
+ function F(e, t) {
190
+ L.lastIndex = 0;
191
+ let r = 0, n;
192
+ for (; (n = L.exec(t)) !== null; )
193
+ n.index > r && C(e, t.slice(r, n.index)), e.push({ kind: "comment", text: n[0] }), r = n.index + n[0].length;
194
+ r < t.length && C(e, t.slice(r));
195
+ }
196
+ function C(e, t) {
197
+ e.push({ kind: "text", text: t, meaningful: /\S/.test(t) });
198
+ }
199
+ function Pe(e) {
200
+ const t = [];
201
+ let r = 0;
202
+ for (const n of M(e, () => !0))
203
+ n.start > r && F(t, e.slice(r, n.start)), t.push({
204
+ kind: "element",
205
+ text: n.outer,
206
+ paragraphContent: q.has(n.name)
207
+ }), r = n.end;
208
+ return r < e.length && F(t, e.slice(r)), t;
209
+ }
210
+ function v(e) {
211
+ return e.kind === "comment" || e.kind === "text" && !e.meaningful;
212
+ }
213
+ function Ee(e) {
214
+ const t = e.map((u) => u.text).join("");
215
+ if (!e.some((u) => !v(u)))
216
+ return t;
217
+ let r = 0, n = e.length;
218
+ for (; r < n && v(e[r]); ) r += 1;
219
+ for (; n > r && v(e[n - 1]); ) n -= 1;
220
+ const s = e.slice(0, r).map((u) => u.text).join(""), o = e.slice(r, n).map((u) => u.text).join(""), a = e.slice(n).map((u) => u.text).join(""), i = /^\s*/.exec(o)[0], c = /\s*$/.exec(o)[0], l = o.slice(i.length, o.length - c.length);
221
+ return `${s}${i}<p>${l}</p>${c}${a}`;
222
+ }
223
+ function be(e) {
224
+ const t = [];
225
+ let r = [];
226
+ const n = () => {
227
+ r.length > 0 && (t.push(Ee(r)), r = []);
228
+ };
229
+ for (const s of Pe(e))
230
+ s.kind === "element" && !s.paragraphContent ? (n(), t.push(s.text)) : r.push(s);
231
+ return n(), t.join("");
232
+ }
233
+ function ve(e) {
234
+ const t = M(e, () => !0), [r] = t;
235
+ if (t.length === 1 && r.name === "p" && r.start === 0 && r.end === e.length)
236
+ return { markup: r.inner.trim() };
237
+ const n = t.filter(
238
+ (a) => !q.has(a.name)
239
+ ), s = n.find((a) => a.name !== "p"), o = [];
240
+ return s && o.push(
241
+ `Pasted content produced a <${s.name}>, which cannot sit inside a <p>. It was inserted as-is — move it out of the paragraph to make the document valid.`
242
+ ), n.some((a) => a.name === "p") && o.push(
243
+ "Pasted content produced more than one paragraph, which cannot sit inside a <p>. It was inserted as-is — split the surrounding paragraph to make the document valid."
244
+ ), {
245
+ markup: e,
246
+ warning: o.length > 0 ? o.join(" ") : void 0
247
+ };
248
+ }
249
+ function Be(e, t) {
250
+ const r = e.trim(), n = t.inline ? ve(r) : { markup: be(r) };
251
+ return t.baseIndent && (n.markup = Te(
252
+ n.markup,
253
+ t.baseIndent,
254
+ t.midLine
255
+ )), n;
187
256
  }
188
257
  const E = {
189
258
  mainSourcePath: "source/main.ptx",
@@ -191,57 +260,57 @@ const E = {
191
260
  projectFilePath: "project.ptx",
192
261
  docinfoPath: "source/docinfo.ptx"
193
262
  };
194
- function O(e) {
195
- return C(e, "pretext") ? e : `<pretext>
263
+ function B(e) {
264
+ return N(e, "pretext") ? e : `<pretext>
196
265
  ${e}
197
266
  </pretext>`;
198
267
  }
199
- function N(e, t, n) {
200
- const r = /* @__PURE__ */ new Map(), o = [], a = `${t}-`;
201
- return e.forEach((s, i) => {
202
- const c = s.attributes["xml:id"];
268
+ function K(e, t, r) {
269
+ const n = /* @__PURE__ */ new Map(), s = [], o = `${t}-`;
270
+ return e.forEach((a, i) => {
271
+ const c = a.attributes["xml:id"];
203
272
  let l;
204
273
  if (c) {
205
- const m = Z(c);
206
- l = m.startsWith(a) ? m : `${a}${m}`;
274
+ const m = ne(c);
275
+ l = m.startsWith(o) ? m : `${o}${m}`;
207
276
  } else
208
- l = `${a}${Y(i + 1, e.length)}`, n.push({
277
+ l = `${o}${re(i + 1, e.length)}`, r.push({
209
278
  action: "anomaly",
210
279
  severity: "info",
211
280
  kind: "structure",
212
281
  category: "missing_xml_id",
213
- macro: s.name,
282
+ macro: a.name,
214
283
  occurrences: 1,
215
- message: `<${s.name}> at position ${i + 1} has no xml:id; using \`${l}\` as filename.`
284
+ message: `<${a.name}> at position ${i + 1} has no xml:id; using \`${l}\` as filename.`
216
285
  });
217
- const p = r.get(l) ?? 0;
218
- r.set(l, p + 1);
219
- const u = p === 0 ? l : `${l}-${p + 1}`;
220
- o.push({
221
- span: s,
222
- slug: u,
223
- filename: `${u}.ptx`
286
+ const u = n.get(l) ?? 0;
287
+ n.set(l, u + 1);
288
+ const d = u === 0 ? l : `${l}-${u + 1}`;
289
+ s.push({
290
+ span: a,
291
+ slug: d,
292
+ filename: `${d}.ptx`
224
293
  });
225
- }), o;
294
+ }), s;
226
295
  }
227
- function he(e, t, n, r) {
228
- const o = R(e, "section");
229
- if (o.length === 0)
296
+ function Se(e, t, r, n) {
297
+ const s = O(e, "section");
298
+ if (s.length === 0)
230
299
  return e;
231
- const s = N(o, "sec", r).map((i) => {
300
+ const a = K(s, "sec", n).map((i) => {
232
301
  const c = `source/${t}/${i.filename}`;
233
- return n[c] = v(i.span.outer), {
302
+ return r[c] = b(i.span.outer), {
234
303
  start: i.span.start,
235
304
  end: i.span.end,
236
305
  replacement: `<xi:include href="${t}/${i.filename}"/>`
237
306
  };
238
307
  });
239
- return k(e, s);
308
+ return j(e, a);
240
309
  }
241
- function ge(e, t, n) {
242
- const r = C(e, "book");
243
- if (!r)
244
- return n.push({
310
+ function Ie(e, t, r) {
311
+ const n = N(e, "book");
312
+ if (!n)
313
+ return r.push({
245
314
  action: "anomaly",
246
315
  severity: "warning",
247
316
  kind: "structure",
@@ -249,136 +318,136 @@ function ge(e, t, n) {
249
318
  macro: "book",
250
319
  occurrences: 1,
251
320
  message: "Document was treated as a book but no <book> element found; emitting as a single file."
252
- }), j(e, t);
253
- const o = {}, a = R(r.inner, "chapter");
254
- let s = r.inner;
255
- if (t.splitChapters && a.length > 0) {
256
- const p = N(a, "ch", n).map((u) => {
257
- let m = u.span.outer;
321
+ }), W(e, t);
322
+ const s = {}, o = O(n.inner, "chapter");
323
+ let a = n.inner;
324
+ if (t.splitChapters && o.length > 0) {
325
+ const u = K(o, "ch", r).map((d) => {
326
+ let m = d.span.outer;
258
327
  if (t.splitSections) {
259
- const d = u.span.inner, f = he(
260
- d,
261
- u.slug,
262
- o,
263
- n
328
+ const p = d.span.inner, f = Se(
329
+ p,
330
+ d.slug,
331
+ s,
332
+ r
264
333
  );
265
- m = u.span.outer.slice(0, u.span.startTagEnd - u.span.start) + f + u.span.outer.slice(u.span.contentEnd - u.span.start);
334
+ m = d.span.outer.slice(0, d.span.startTagEnd - d.span.start) + f + d.span.outer.slice(d.span.contentEnd - d.span.start);
266
335
  }
267
- const h = `source/${u.filename}`;
268
- return o[h] = v(m), {
269
- start: u.span.start,
270
- end: u.span.end,
271
- replacement: `<xi:include href="${u.filename}"/>`
336
+ const h = `source/${d.filename}`;
337
+ return s[h] = b(m), {
338
+ start: d.span.start,
339
+ end: d.span.end,
340
+ replacement: `<xi:include href="${d.filename}"/>`
272
341
  };
273
342
  });
274
- s = k(r.inner, p);
343
+ a = j(n.inner, u);
275
344
  }
276
- const i = e.slice(r.start, r.startTagEnd) + s + e.slice(r.contentEnd, r.end), c = e.slice(0, r.start) + i + e.slice(r.end);
277
- return o[t.mainSourcePath] = v(
278
- q(O(c.trim()))
279
- ), o;
280
- }
281
- function j(e, t, n) {
282
- const r = {};
283
- return r[t.mainSourcePath] = v(
284
- O(e.trim())
285
- ), r;
286
- }
287
- function ke(e, t = {}) {
288
- const n = [], r = t.documentKind ?? U(e), o = {
289
- splitChapters: t.splitChapters ?? r === "book",
345
+ const i = e.slice(n.start, n.startTagEnd) + a + e.slice(n.contentEnd, n.end), c = e.slice(0, n.start) + i + e.slice(n.end);
346
+ return s[t.mainSourcePath] = b(
347
+ te(B(c.trim()))
348
+ ), s;
349
+ }
350
+ function W(e, t, r) {
351
+ const n = {};
352
+ return n[t.mainSourcePath] = b(
353
+ B(e.trim())
354
+ ), n;
355
+ }
356
+ function Ke(e, t = {}) {
357
+ const r = [], n = t.documentKind ?? J(e), s = {
358
+ splitChapters: t.splitChapters ?? n === "book",
290
359
  splitSections: t.splitSections ?? !1,
291
360
  mainSourcePath: t.mainSourcePath ?? E.mainSourcePath,
292
361
  publicationPath: t.publicationPath ?? E.publicationPath,
293
362
  projectFilePath: t.projectFilePath ?? E.projectFilePath,
294
363
  docinfoPath: t.docinfoPath ?? E.docinfoPath
295
- }, a = r === "book" ? ge(e, o, n) : j(e, o);
296
- return a[o.projectFilePath] = G({
297
- mainSource: o.mainSourcePath,
298
- publication: o.publicationPath
299
- }), a[o.publicationPath] = V(), { files: a, documentKind: r, warnings: n };
364
+ }, o = n === "book" ? Ie(e, s, r) : W(e, s);
365
+ return o[s.projectFilePath] = Q({
366
+ mainSource: s.mainSourcePath,
367
+ publication: s.publicationPath
368
+ }), o[s.publicationPath] = ee(), { files: o, documentKind: n, warnings: r };
300
369
  }
301
- class we extends Error {
370
+ class Ae extends Error {
302
371
  constructor() {
303
372
  super("Import cancelled."), this.name = "ConversionCancelledError";
304
373
  }
305
374
  }
306
- let Te = 0;
307
- function xe(e, t, n = {}) {
308
- const r = `convert-${Te++}`, o = e(), { assets: a = {}, ...s } = n;
375
+ let _e = 0;
376
+ function $e(e, t, r = {}) {
377
+ const n = `convert-${_e++}`, s = e(), { assets: o = {}, ...a } = r;
309
378
  let i;
310
- const c = new Promise((p, u) => {
379
+ const c = new Promise((u, d) => {
311
380
  let m = !1;
312
- const h = (d) => {
313
- m || (m = !0, o.terminate(), d());
381
+ const h = (p) => {
382
+ m || (m = !0, s.terminate(), p());
314
383
  };
315
- i = () => h(() => u(new we())), o.addEventListener("message", (d) => {
316
- const f = d.data;
317
- if (!(!f || f.requestId !== r)) {
384
+ i = () => h(() => d(new Ae())), s.addEventListener("message", (p) => {
385
+ const f = p.data;
386
+ if (!(!f || f.requestId !== n)) {
318
387
  if (f.type === "result") {
319
- h(() => p(f.result));
388
+ h(() => u(f.result));
320
389
  return;
321
390
  }
322
- h(() => u(new Error(f.message)));
391
+ h(() => d(new Error(f.message)));
323
392
  }
324
- }), o.addEventListener("error", (d) => {
325
- const f = typeof d == "object" && d && "message" in d ? String(d.message) : "The import worker failed to start.";
326
- h(() => u(new Error(f)));
393
+ }), s.addEventListener("error", (p) => {
394
+ const f = typeof p == "object" && p && "message" in p ? String(p.message) : "The import worker failed to start.";
395
+ h(() => d(new Error(f)));
327
396
  });
328
397
  }), l = [
329
398
  ...new Set(
330
- Object.values(a).map((p) => p.buffer).filter(
331
- (p) => p instanceof ArrayBuffer
399
+ Object.values(o).map((u) => u.buffer).filter(
400
+ (u) => u instanceof ArrayBuffer
332
401
  )
333
402
  )
334
403
  ];
335
- return o.postMessage(
336
- { type: "convert", requestId: r, files: t, assets: a, options: s },
404
+ return s.postMessage(
405
+ { type: "convert", requestId: n, files: t, assets: o, options: a },
337
406
  l
338
407
  ), { result: c, cancel: () => i?.() };
339
408
  }
340
- function De(e) {
409
+ function We(e) {
341
410
  const {
342
411
  createWorker: t,
343
- id: n = "worker",
344
- label: r = "Built-in converter",
345
- description: o = "Create a new project starting with LaTeX, Markdown, or PreTeXt files.",
346
- acceptExtensions: a
412
+ id: r = "worker",
413
+ label: n = "Built-in converter",
414
+ description: s = "Create a new project starting with LaTeX, Markdown, or PreTeXt files.",
415
+ acceptExtensions: o
347
416
  } = e;
348
- let s = null;
417
+ let a = null;
349
418
  const i = async (c, l) => {
350
- s?.cancel(), s = xe(t, c, l);
419
+ a?.cancel(), a = $e(t, c, l);
351
420
  try {
352
- return await s.result;
421
+ return await a.result;
353
422
  } finally {
354
- s = null;
423
+ a = null;
355
424
  }
356
425
  };
357
426
  return {
358
- id: n,
359
- label: r,
360
- description: o,
361
- acceptExtensions: a,
427
+ id: r,
428
+ label: n,
429
+ description: s,
430
+ acceptExtensions: o,
362
431
  prepare: async (c) => {
363
- const { files: l, assets: p } = await $(c);
432
+ const { files: l, assets: u } = await $(c);
364
433
  return {
365
434
  fileName: c.name,
366
435
  files: l,
367
- assets: p,
368
- analysis: J(l)
436
+ assets: u,
437
+ analysis: se(l)
369
438
  };
370
439
  },
371
440
  convertPrepared: (c, l) => i(c.files, { ...l, assets: c.assets }),
372
441
  convertFile: async (c, l) => {
373
- const { files: p, assets: u } = await $(c);
374
- return i(p, { ...l, assets: u });
442
+ const { files: u, assets: d } = await $(c);
443
+ return i(u, { ...l, assets: d });
375
444
  },
376
445
  cancel: () => {
377
- s?.cancel(), s = null;
446
+ a?.cancel(), a = null;
378
447
  }
379
448
  };
380
449
  }
381
- const Pe = {
450
+ const ke = {
382
451
  ".docx": "docx",
383
452
  ".odt": "odt",
384
453
  ".epub": "epub",
@@ -394,7 +463,7 @@ const Pe = {
394
463
  ".typ": "typst",
395
464
  ".xml": "docbook",
396
465
  ".textile": "textile"
397
- }, Me = /* @__PURE__ */ new Set(["docx", "odt", "epub"]), X = [
466
+ }, Ge = /* @__PURE__ */ new Set(["docx", "odt", "epub"]), G = [
398
467
  ".docx",
399
468
  ".odt",
400
469
  ".epub",
@@ -410,33 +479,33 @@ const Pe = {
410
479
  ".md",
411
480
  ".markdown"
412
481
  ];
413
- function z(e) {
482
+ function H(e) {
414
483
  const t = e.lastIndexOf(".");
415
484
  return t <= 0 ? "" : e.slice(t).toLowerCase();
416
485
  }
417
- function Ee(e) {
418
- return Pe[z(e)];
486
+ function ye(e) {
487
+ return ke[H(e)];
419
488
  }
420
- function ve(e) {
489
+ function Le(e) {
421
490
  const {
422
491
  convertToPretext: t,
423
- id: n = "pandoc",
424
- label: r = "Pandoc",
425
- description: o = "Convert Word, OpenOffice, EPUB, HTML, reStructuredText, and more.",
426
- acceptExtensions: a = X
492
+ id: r = "pandoc",
493
+ label: n = "Pandoc",
494
+ description: s = "Convert Word, OpenOffice, EPUB, HTML, reStructuredText, and more.",
495
+ acceptExtensions: o = G
427
496
  } = e;
428
497
  return {
429
- id: n,
430
- label: r,
431
- description: o,
432
- acceptExtensions: a,
433
- convertFile: async (s, i) => {
434
- const c = await t(s, i);
498
+ id: r,
499
+ label: n,
500
+ description: s,
501
+ acceptExtensions: o,
502
+ convertFile: async (a, i) => {
503
+ const c = await t(a, i);
435
504
  if (!c.trim())
436
505
  throw new Error(
437
- `Pandoc produced no output for ${s.name}. The file may be empty or in an unexpected format.`
506
+ `Pandoc produced no output for ${a.name}. The file may be empty or in an unexpected format.`
438
507
  );
439
- const l = Q(
508
+ const l = ae(
440
509
  { "source.ptx": c },
441
510
  {
442
511
  documentKind: i.documentKind,
@@ -445,220 +514,230 @@ function ve(e) {
445
514
  splitLevel: i.splitLevel
446
515
  }
447
516
  );
448
- return "pretextError" in l || (l.sourceName = s.name, l.sourcePath = s.name), l;
517
+ return "pretextError" in l || (l.sourceName = a.name, l.sourcePath = a.name), l;
449
518
  }
450
519
  };
451
520
  }
452
- const Se = 3e4;
453
- function be(e) {
521
+ const Fe = 3e4;
522
+ function Ce(e) {
454
523
  const t = /<pre>([\s\S]*?)<\/pre>/i.exec(e);
455
524
  return (t ? t[1] : e).replace(/<[^>]+>/g, "").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&amp;/g, "&").trim();
456
525
  }
457
- function Ie(e, t, n) {
458
- const r = _e(be(t)), o = r ? ` (${y(r)})` : "";
526
+ function Re(e, t, r) {
527
+ const n = De(Ce(t)), s = n ? ` (${D(n)})` : "";
459
528
  switch (e) {
460
529
  case 400:
461
- return `The pandoc server will not convert ${n}${o}.${T(n)}`;
530
+ return `The pandoc server will not convert ${r}${s}.${w(r)}`;
462
531
  case 401:
463
532
  case 403:
464
- return `The pandoc server rejected this site's credentials, so ${n} was never converted. Nothing is wrong with your file — this is a configuration problem with the service, and worth reporting.${T(n)}`;
533
+ return `The pandoc server rejected this site's credentials, so ${r} was never converted. Nothing is wrong with your file — this is a configuration problem with the service, and worth reporting.${w(r)}`;
465
534
  case 404:
466
- return `The pandoc conversion service could not be found at the address this site is configured to use. Nothing is wrong with your file — this is a configuration problem worth reporting.${T(n)}`;
535
+ return `The pandoc conversion service could not be found at the address this site is configured to use. Nothing is wrong with your file — this is a configuration problem worth reporting.${w(r)}`;
467
536
  case 413:
468
- return `${n} is too large for the pandoc server to accept. Splitting it into chapters and importing them one at a time should get through.`;
537
+ return `${r} is too large for the pandoc server to accept. Splitting it into chapters and importing them one at a time should get through.`;
469
538
  case 422:
470
- return `Pandoc could not read ${n}${o}. The file may be damaged, or may use features pandoc does not support.`;
539
+ return `Pandoc could not read ${r}${s}. The file may be damaged, or may use features pandoc does not support.`;
471
540
  case 503:
472
- return `The pandoc server is running without its PreTeXt writer, so it cannot convert anything right now. Nothing is wrong with your file — this is a problem with the service, and worth reporting.${T(n)}`;
541
+ return `The pandoc server is running without its PreTeXt writer, so it cannot convert anything right now. Nothing is wrong with your file — this is a problem with the service, and worth reporting.${w(r)}`;
473
542
  case 504:
474
- return `Converting ${n} took longer than the pandoc server allows. Splitting it into chapters and importing them one at a time usually works.`;
543
+ return `Converting ${r} took longer than the pandoc server allows. Splitting it into chapters and importing them one at a time usually works.`;
475
544
  default: {
476
- const a = r ? `(HTTP ${e}: ${y(r)})` : `(HTTP ${e})`;
477
- return `The pandoc server could not convert ${n} ${a}.${T(n)}`;
545
+ const o = n ? `(HTTP ${e}: ${D(n)})` : `(HTTP ${e})`;
546
+ return `The pandoc server could not convert ${r} ${o}.${w(r)}`;
478
547
  }
479
548
  }
480
549
  }
481
- const L = 300;
482
- function _e(e) {
550
+ const R = 300;
551
+ function De(e) {
483
552
  return e.replace(/\s+/g, " ").trim();
484
553
  }
485
- function y(e) {
486
- return e.length <= L ? e : `${e.slice(0, L).trimEnd()}…`;
554
+ function D(e) {
555
+ return e.length <= R ? e : `${e.slice(0, R).trimEnd()}…`;
487
556
  }
488
- const $e = /* @__PURE__ */ new Set([
557
+ const Me = /* @__PURE__ */ new Set([
489
558
  ".tex",
490
559
  ".ltx",
491
560
  ".md",
492
561
  ".markdown"
493
562
  ]);
494
- function T(e) {
495
- return $e.has(z(e)) ? " You can import this file with the built-in converter instead." : "";
563
+ function w(e) {
564
+ return Me.has(H(e)) ? " You can import this file with the built-in converter instead." : "";
496
565
  }
497
- function Oe(e) {
566
+ function He(e) {
498
567
  const {
499
568
  url: t,
500
- token: n,
501
- headers: r,
502
- credentials: o,
503
- standalone: a = !0,
504
- from: s,
505
- timeoutMs: i = Se,
569
+ token: r,
570
+ headers: n,
571
+ credentials: s,
572
+ standalone: o = !0,
573
+ from: a,
574
+ timeoutMs: i = Fe,
506
575
  fetchImpl: c,
507
576
  id: l = "pandoc-remote",
508
- label: p = "Pandoc (server)",
509
- description: u = "Convert Word, OpenOffice, EPUB, HTML, reStructuredText, and more — no local install needed.",
510
- acceptExtensions: m = X
577
+ label: u = "Pandoc (server)",
578
+ description: d = "Convert Word, OpenOffice, EPUB, HTML, reStructuredText, and more — no local install needed.",
579
+ acceptExtensions: m = G
511
580
  } = e;
512
- return ve({
513
- convertToPretext: async (d, f) => {
581
+ return Le({
582
+ convertToPretext: async (p, f) => {
514
583
  const S = c ?? globalThis.fetch;
515
584
  if (typeof S != "function")
516
585
  throw new Error(
517
586
  "This environment has no fetch; pass fetchImpl to createRemotePandocEngine."
518
587
  );
519
- const b = s ?? Ee(d.name);
520
- if (!b)
588
+ const I = a ?? ye(p.name);
589
+ if (!I)
521
590
  throw new Error(
522
- `Pandoc cannot determine a format for ${d.name}. Supported extensions: ${m.join(", ")}.`
591
+ `Pandoc cannot determine a format for ${p.name}. Supported extensions: ${m.join(", ")}.`
523
592
  );
524
593
  const g = new FormData();
525
- n && g.set("token", n), g.set("file", d, d.name), g.set("from", b), a && g.set("standalone", "yes");
526
- const I = new AbortController(), B = setTimeout(() => I.abort(), i);
527
- let x;
594
+ r && g.set("token", r), g.set("file", p, p.name), g.set("from", I), o && g.set("standalone", "yes");
595
+ const A = new AbortController(), U = setTimeout(() => A.abort(), i);
596
+ let T;
528
597
  try {
529
- x = await S(t, {
598
+ T = await S(t, {
530
599
  method: "POST",
531
600
  body: g,
532
- headers: r,
533
- credentials: o,
534
- signal: I.signal
601
+ headers: n,
602
+ credentials: s,
603
+ signal: A.signal
535
604
  });
536
- } catch (w) {
537
- if (w instanceof Error && w.name === "AbortError")
605
+ } catch (x) {
606
+ if (x instanceof Error && x.name === "AbortError")
538
607
  throw new Error(
539
- `Pandoc conversion of ${d.name} timed out after ${Math.round(i / 1e3)}s.`
608
+ `Pandoc conversion of ${p.name} timed out after ${Math.round(i / 1e3)}s.`
540
609
  );
541
- const K = w instanceof Error ? w.message : String(w);
542
- throw new Error(`Could not reach the pandoc server: ${K}`);
610
+ const V = x instanceof Error ? x.message : String(x);
611
+ throw new Error(`Could not reach the pandoc server: ${V}`);
543
612
  } finally {
544
- clearTimeout(B);
613
+ clearTimeout(U);
545
614
  }
546
- const _ = await x.text();
547
- if (!x.ok)
615
+ const _ = await T.text();
616
+ if (!T.ok)
548
617
  throw new Error(
549
- Ie(x.status, _, d.name)
618
+ Re(T.status, _, p.name)
550
619
  );
551
620
  return _;
552
621
  },
553
622
  id: l,
554
- label: p,
555
- description: u,
623
+ label: u,
624
+ description: d,
556
625
  acceptExtensions: m
557
626
  });
558
627
  }
559
628
  export {
560
- Xe as CLEAN_RULES,
561
- we as ConversionCancelledError,
562
- qt as DEFAULT_IMPORT_MODE,
563
- Se as DEFAULT_REMOTE_PANDOC_TIMEOUT_MS,
564
- ze as DIVISION_LADDER,
565
- Be as LADDER_OVERFLOW_TAG,
566
- Ke as LATEX_DIVISION_COMMANDS,
567
- We as LATEX_FORMAT_MARKERS,
568
- He as MARKDOWN_FORMAT_MARKERS,
569
- Ue as MAX_SUGGESTED_SPLIT_LEVEL,
570
- X as PANDOC_ACCEPT_EXTENSIONS,
571
- Me as PANDOC_BINARY_FORMATS,
572
- Pe as PANDOC_EXTENSION_FORMATS,
573
- H as PRETEXT_DIVISION_TAGS,
574
- Ge as PRETEXT_ROOT_TAGS,
575
- Ve as PROJECT_DESTINATION,
576
- J as analyzeImportSources,
577
- qe as applyLatexFixes,
578
- Zt as assetsForImportMode,
579
- Ze as attachLatexRoots,
580
- Ye as attachMarkdownRoots,
581
- Je as buildDivisionPool,
582
- Qe as buildNativeDivisionPool,
583
- ke as buildPretextProjectFiles,
584
- et as carryOverProjectFiles,
585
- tt as cleanLatex,
586
- nt as cleanLatexInChunks,
587
- rt as cleanLatexText,
588
- ot as convertLatexToPretext,
589
- st as convertMarkdownToPretext,
590
- at as convertSourceToPretext,
591
- ve as createPandocEngine,
592
- Oe as createRemotePandocEngine,
593
- De as createWorkerEngine,
594
- it as dedupeXmlIds,
595
- ct as defaultAttachLevel,
596
- lt as defaultManifestTarget,
597
- Ie as describeRemotePandocFailure,
598
- U as detectDocumentKind,
599
- Fe as detectSnippetFormat,
600
- ut as detectSourceFormat,
601
- Yt as diffHunks,
602
- Jt as diffLines,
603
- Qt as diffStats,
604
- pt as divisionChildRefs,
605
- dt as divisionsAtLevel,
606
- mt as expandPretextIncludes,
607
- be as extractPandocErrorDetail,
629
+ Ze as CLEAN_RULES,
630
+ Ae as ConversionCancelledError,
631
+ an as DEFAULT_ACCEPT_EXTENSIONS,
632
+ on as DEFAULT_IMPORT_MODE,
633
+ Fe as DEFAULT_REMOTE_PANDOC_TIMEOUT_MS,
634
+ Ye as DIVISION_LADDER,
635
+ Je as LADDER_OVERFLOW_TAG,
636
+ Qe as LATEX_DIVISION_COMMANDS,
637
+ et as LATEX_FORMAT_MARKERS,
638
+ tt as MARKDOWN_FORMAT_MARKERS,
639
+ nt as MAX_SUGGESTED_SPLIT_LEVEL,
640
+ G as PANDOC_ACCEPT_EXTENSIONS,
641
+ Ge as PANDOC_BINARY_FORMATS,
642
+ ke as PANDOC_EXTENSION_FORMATS,
643
+ Y as PRETEXT_DIVISION_TAGS,
644
+ rt as PRETEXT_ROOT_TAGS,
645
+ st as PROJECT_DESTINATION,
646
+ cn as allAcceptExtensions,
647
+ ln as alternateEngine,
648
+ un as alternateFor,
649
+ se as analyzeImportSources,
650
+ at as applyLatexFixes,
651
+ dn as assetsForImportMode,
652
+ ot as attachLatexRoots,
653
+ it as attachMarkdownRoots,
654
+ ct as buildDivisionPool,
655
+ lt as buildNativeDivisionPool,
656
+ Ke as buildPretextProjectFiles,
657
+ ut as carryOverProjectFiles,
658
+ dt as cleanLatex,
659
+ pt as cleanLatexInChunks,
660
+ mt as cleanLatexText,
661
+ ft as convertLatexToPretext,
662
+ ht as convertMarkdownToPretext,
663
+ gt as convertSourceToPretext,
664
+ Le as createPandocEngine,
665
+ He as createRemotePandocEngine,
666
+ We as createWorkerEngine,
667
+ xt as dedupeXmlIds,
668
+ wt as defaultAttachLevel,
669
+ Tt as defaultManifestTarget,
670
+ Re as describeRemotePandocFailure,
671
+ J as detectDocumentKind,
672
+ Oe as detectSnippetFormat,
673
+ Pt as detectSourceFormat,
674
+ pn as diffHunks,
675
+ mn as diffLines,
676
+ fn as diffStats,
677
+ Et as divisionChildRefs,
678
+ bt as divisionsAtLevel,
679
+ hn as engineAccepts,
680
+ gn as engineExtensions,
681
+ vt as expandPretextIncludes,
682
+ Ce as extractPandocErrorDetail,
608
683
  $ as extractUpload,
609
- en as fileChangesForImport,
610
- z as fileExtension,
611
- ft as filePrefixForDivision,
612
- tn as filesForImportMode,
613
- ht as findLatexFixes,
614
- gt as findLatexHeaders,
615
- wt as findProjectManifest,
616
- me as firstDivisionTag,
617
- Tt as fixesToWarnings,
618
- nn as formatWarningLine,
619
- xt as getConversionErrorMessage,
620
- Pt as getLatexCleanDiagnostics,
621
- Et as handleImportUploadFile,
622
- rn as hasNativeImportMode,
623
- Q as importProjectFromFiles,
624
- vt as isDivisionTag,
625
- Ce as isInlineContext,
626
- St as ladderDepth,
627
- bt as latexDivisionHierarchy,
628
- It as latexFixesToCodeActions,
629
- _t as mergeChunksAtLevel,
630
- $t as normalizePretextSource,
631
- At as outlineDivisions,
632
- Ee as pandocFormatForFileName,
633
- Ft as parseLatexDivisions,
634
- Lt as parseProjectManifest,
635
- Re as placeConvertedMarkup,
636
- yt as prepareInsertSource,
637
- on as projectForImportMode,
638
- Ct as pruneDivisions,
639
- Rt as rebuildImport,
640
- pe as recordsToPlusPayload,
641
- fe as reindentForContext,
642
- kt as relayoutImport,
643
- G as renderProjectPtx,
644
- Dt as renderProjectPtxFromManifest,
645
- V as renderPublicationPtx,
646
- Mt as reselectImport,
647
- sn as resolveImportMode,
648
- Ot as resolveImportSplitLevel,
649
- Nt as resolveSplitLevel,
650
- jt as retargetFragment,
651
- Xt as retargetFragmentToDepth,
652
- zt as retargetImport,
653
- xe as runConversionInWorker,
654
- Bt as sanitizeRef,
655
- se as scoreSnippetFormats,
656
- Kt as serializeForDestination,
657
- Wt as serializeInsertFiles,
658
- ye as serializeInsertToRecords,
659
- Ht as serializeProjectToFiles,
660
- Le as serializeProjectToPlusPayload,
661
- le as serializeProjectToRecords,
662
- Ut as shiftLadderTag,
663
- Gt as suggestSplitLevel
684
+ xn as fileChangesForImport,
685
+ H as fileExtension,
686
+ St as filePrefixForDivision,
687
+ wn as filesForImportMode,
688
+ It as findLatexFixes,
689
+ At as findLatexHeaders,
690
+ _t as findProjectManifest,
691
+ qe as firstDivisionTag,
692
+ $t as fixesToWarnings,
693
+ Tn as formatWarningLine,
694
+ kt as getConversionErrorMessage,
695
+ yt as getLatexCleanDiagnostics,
696
+ Lt as handleImportUploadFile,
697
+ Pn as hasNativeImportMode,
698
+ ae as importProjectFromFiles,
699
+ Ft as isDivisionTag,
700
+ ze as isInlineContext,
701
+ Ct as ladderDepth,
702
+ Rt as latexDivisionHierarchy,
703
+ Dt as latexFixesToCodeActions,
704
+ En as matchesExtension,
705
+ Mt as mergeChunksAtLevel,
706
+ Nt as normalizePretextSource,
707
+ Ot as outlineDivisions,
708
+ ye as pandocFormatForFileName,
709
+ jt as parseLatexDivisions,
710
+ Xt as parseProjectManifest,
711
+ Be as placeConvertedMarkup,
712
+ zt as prepareInsertSource,
713
+ bn as projectForImportMode,
714
+ qt as pruneDivisions,
715
+ Bt as rebuildImport,
716
+ xe as recordsToPlusPayload,
717
+ Te as reindentForContext,
718
+ Kt as relayoutImport,
719
+ Q as renderProjectPtx,
720
+ Wt as renderProjectPtxFromManifest,
721
+ ee as renderPublicationPtx,
722
+ Gt as reselectImport,
723
+ vn as resolveImportMode,
724
+ Ht as resolveImportSplitLevel,
725
+ Ut as resolveSplitLevel,
726
+ Vt as retargetFragment,
727
+ Zt as retargetFragmentToDepth,
728
+ Yt as retargetImport,
729
+ Sn as routeEngine,
730
+ $e as runConversionInWorker,
731
+ Jt as sanitizeRef,
732
+ de as scoreSnippetFormats,
733
+ Qt as serializeForDestination,
734
+ en as serializeInsertFiles,
735
+ Xe as serializeInsertToRecords,
736
+ tn as serializeProjectToFiles,
737
+ je as serializeProjectToPlusPayload,
738
+ he as serializeProjectToRecords,
739
+ nn as shiftLadderTag,
740
+ rn as suggestSplitLevel,
741
+ In as unsupportedFileMessage,
742
+ be as wrapLooseParagraphs
664
743
  };