@pretextbook/pretext-html 0.7.0 → 0.8.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.
@@ -1,26 +1,26 @@
1
- import { readFile as A, writeFile as U } from "node:fs/promises";
2
- import * as b from "node:process";
1
+ import { readFile as M, writeFile as W } from "node:fs/promises";
2
+ import * as v from "node:process";
3
3
  import * as l from "node:path";
4
- import { fileURLToPath as he } from "node:url";
4
+ import { fileURLToPath as we } from "node:url";
5
5
  import { fromXml as y } from "xast-util-from-xml";
6
- import { toXml as $ } from "xast-util-to-xml";
7
- import { injectRevealBridge as we } from "./reveal.js";
8
- import { injectThemeBridge as be } from "./theme.js";
9
- const ge = "ptxPreviewBannerDismissed", ve = "About live preview";
10
- function N(e) {
6
+ import { toXml as S } from "xast-util-to-xml";
7
+ import { injectRevealBridge as be } from "./reveal.js";
8
+ import { injectThemeBridge as ve } from "./theme.js";
9
+ const ge = "ptxPreviewBannerDismissed", xe = "About live preview";
10
+ function H(e) {
11
11
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
12
12
  }
13
- function xe(e) {
13
+ function ye(e) {
14
14
  return [
15
15
  '<div id="ptx-preview-banner" class="ptx-preview-banner" role="note">',
16
- ` <span class="ptx-preview-banner-text">${N(e)}</span>`,
16
+ ` <span class="ptx-preview-banner-text">${H(e)}</span>`,
17
17
  ' <button type="button" class="ptx-preview-banner-dismiss" aria-label="Dismiss">&times;</button>',
18
18
  "</div>",
19
- `<button type="button" id="ptx-preview-banner-restore" class="ptx-preview-banner-restore" hidden>${N(ve)}</button>`
19
+ `<button type="button" id="ptx-preview-banner-restore" class="ptx-preview-banner-restore" hidden>${H(xe)}</button>`
20
20
  ].join(`
21
21
  `);
22
22
  }
23
- function ye() {
23
+ function Ee() {
24
24
  return [
25
25
  "<style>",
26
26
  ".ptx-preview-banner {",
@@ -81,7 +81,7 @@ function ye() {
81
81
  ].join(`
82
82
  `);
83
83
  }
84
- function Ee() {
84
+ function Te() {
85
85
  return [
86
86
  "<script>",
87
87
  "(function () {",
@@ -122,16 +122,16 @@ function Ee() {
122
122
  ].join(`
123
123
  `);
124
124
  }
125
- const Te = "<!--ptx-preview-banner-->", $e = "<!--/ptx-preview-banner-->", Se = /\n?<!--ptx-preview-banner-->[\s\S]*?<!--\/ptx-preview-banner-->/;
126
- function ke(e, r) {
127
- const t = Se.exec(e), n = t ? e.slice(0, t.index) + e.slice(t.index + t[0].length) : e;
125
+ const Se = "<!--ptx-preview-banner-->", $e = "<!--/ptx-preview-banner-->", ke = /\n?<!--ptx-preview-banner-->[\s\S]*?<!--\/ptx-preview-banner-->/;
126
+ function Pe(e, r) {
127
+ const t = ke.exec(e), n = t ? e.slice(0, t.index) + e.slice(t.index + t[0].length) : e;
128
128
  if (!/<body[^>]*>/i.test(n))
129
129
  return n;
130
130
  const o = `
131
- ${Te}
132
- ${ye()}
133
- ${xe(r.message)}
131
+ ${Se}
134
132
  ${Ee()}
133
+ ${ye(r.message)}
134
+ ${Te()}
135
135
  ${$e}`;
136
136
  return n.replace(/<body([^>]*)>/i, `<body$1>${o}`);
137
137
  }
@@ -144,57 +144,64 @@ async function ee(e, r) {
144
144
  return;
145
145
  }
146
146
  try {
147
- return new Uint8Array(await A(n));
147
+ return new Uint8Array(await M(n));
148
148
  } catch {
149
149
  return;
150
150
  }
151
151
  }
152
- async function j(e) {
152
+ async function B(e) {
153
153
  try {
154
- return await A(e, "utf8");
154
+ return await M(e, "utf8");
155
155
  } catch {
156
156
  return;
157
157
  }
158
158
  }
159
159
  let te;
160
- function yt(e) {
160
+ function kt(e) {
161
161
  te = e;
162
162
  }
163
- function I() {
164
- return te ?? process.env.PRETEXT_HTML_ASSETS ?? l.resolve(l.dirname(he(import.meta.url)), "..", "assets");
163
+ function j() {
164
+ return te ?? process.env.PRETEXT_HTML_ASSETS ?? l.resolve(l.dirname(we(import.meta.url)), "..", "assets");
165
165
  }
166
- function Pe(e, r) {
166
+ function Ie(e, r) {
167
167
  return l.join(e, r);
168
168
  }
169
- const De = "born-hidden-knowl", Ie = /<details\b([^>]*)>(\s*)(?:<summary\b([^>]*)>)?/g;
170
- function Le(e) {
169
+ const re = "2.46.0", De = "8.2.1", Re = [
170
+ "prefix-runtime.ed2cce180827a7ad.bundle.js",
171
+ "prefix-926.5c7038c8ef173faf.bundle.js",
172
+ "prefix-runestone.1f660864c47fc762.bundle.js"
173
+ ], je = [
174
+ "prefix-926.229729d09512acc9.css",
175
+ "prefix-runestone.8086b62682b271d1.css"
176
+ ], Le = "born-hidden-knowl", Ae = /<details\b([^>]*)>(\s*)(?:<summary\b([^>]*)>)?/g;
177
+ function Me(e) {
171
178
  const r = /\bclass="([^"]*)"/.exec(e);
172
179
  return r ? r[1].trim().split(/\s+/) : [];
173
180
  }
174
- function Re(e) {
181
+ function Be(e) {
175
182
  return /(^|\s)open(\s|=|$)/.test(e);
176
183
  }
177
- function H(e) {
178
- return Re(e) ? e : ` open${e}`;
184
+ function J(e) {
185
+ return Be(e) ? e : ` open${e}`;
179
186
  }
180
- function Ae(e) {
187
+ function _e(e) {
181
188
  return e.replace(
182
- Ie,
189
+ Ae,
183
190
  (r, t, n, o) => {
184
- if (!Le(t).includes(De))
191
+ if (!Me(t).includes(Le))
185
192
  return r;
186
- const s = `<details${H(t)}>`;
187
- return o === void 0 ? `${s}${n}` : `${s}${n}<summary${H(o)}>`;
193
+ const s = `<details${J(t)}>`;
194
+ return o === void 0 ? `${s}${n}` : `${s}${n}<summary${J(o)}>`;
188
195
  }
189
196
  );
190
197
  }
191
- const B = /* @__PURE__ */ new Map(), re = /* @__PURE__ */ new Map();
192
- let L, je = 0, ne = ee;
193
- function Et(e) {
194
- ne = e;
198
+ const _ = /* @__PURE__ */ new Map(), ne = /* @__PURE__ */ new Map();
199
+ let L, Ce = 0, oe = ee;
200
+ function Pt(e) {
201
+ oe = e;
195
202
  }
196
- function Be(e, r) {
197
- const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, n = re.get(t);
203
+ function Oe(e, r) {
204
+ const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, n = ne.get(t);
198
205
  if (n !== void 0)
199
206
  return Promise.resolve(new Response(n, { status: 200 }));
200
207
  let o;
@@ -203,32 +210,32 @@ function Be(e, r) {
203
210
  } catch {
204
211
  o = "";
205
212
  }
206
- const s = B.get(o);
207
- return s !== void 0 ? Ce(s, t) : L(e, r);
213
+ const s = _.get(o);
214
+ return s !== void 0 ? Ne(s, t) : L(e, r);
208
215
  }
209
- const Me = '<?xml version="1.0"?><pretext-preview-missing-file/>';
210
- async function Ce(e, r) {
211
- const t = decodeURIComponent(new URL(r).pathname), n = await ne(e, t);
216
+ const Xe = '<?xml version="1.0"?><pretext-preview-missing-file/>';
217
+ async function Ne(e, r) {
218
+ const t = decodeURIComponent(new URL(r).pathname), n = await oe(e, t);
212
219
  if (n === void 0)
213
- return new Response(Me, { status: 200 });
220
+ return new Response(Xe, { status: 200 });
214
221
  const o = typeof n == "string" ? n : new Uint8Array(n);
215
222
  return new Response(o, { status: 200 });
216
223
  }
217
- function oe() {
218
- L || (L = globalThis.fetch, globalThis.fetch = Be);
224
+ function se() {
225
+ L || (L = globalThis.fetch, globalThis.fetch = Oe);
219
226
  }
220
- function se(e) {
221
- oe();
222
- const r = `mnt${++je}.ptx.invalid`;
223
- return B.set(r, e), `http://${r}`;
227
+ function ie(e) {
228
+ se();
229
+ const r = `mnt${++Ce}.ptx.invalid`;
230
+ return _.set(r, e), `http://${r}`;
224
231
  }
225
- function Xe(e) {
226
- B.delete(new URL(e).host);
232
+ function Fe(e) {
233
+ _.delete(new URL(e).host);
227
234
  }
228
- function Fe(e, r) {
229
- oe(), re.set(e, r);
235
+ function Ue(e, r) {
236
+ se(), ne.set(e, r);
230
237
  }
231
- const R = `<?xml version="1.0" encoding="UTF-8"?>
238
+ const A = `<?xml version="1.0" encoding="UTF-8"?>
232
239
  <publication>
233
240
  <source>
234
241
  <directories external="../assets" generated="../generated-assets" />
@@ -237,31 +244,31 @@ const R = `<?xml version="1.0" encoding="UTF-8"?>
237
244
  <platform portable="yes"/>
238
245
  </html>
239
246
  </publication>
240
- `, _e = ["theme", "style", "shell"];
241
- function w(e, r) {
247
+ `, We = ["theme", "style", "shell"];
248
+ function b(e, r) {
242
249
  for (const t of e.children)
243
250
  if (t.type === "element" && t.name === r)
244
251
  return t;
245
252
  }
246
253
  function g(e, r) {
247
- let t = w(e, r);
254
+ let t = b(e, r);
248
255
  return t || (t = { type: "element", name: r, attributes: {}, children: [] }, e.children.push(t)), t;
249
256
  }
250
- function Oe(e, r) {
251
- const t = w(e, "css");
252
- if (t && _e.some((o) => t.attributes?.[o]))
257
+ function He(e, r) {
258
+ const t = b(e, "css");
259
+ if (t && We.some((o) => t.attributes?.[o]))
253
260
  return;
254
261
  const n = t ?? g(e, "css");
255
262
  n.attributes = { ...n.attributes, theme: r };
256
263
  }
257
- function We(e, r) {
258
- const t = w(e, "appearance");
264
+ function Je(e, r) {
265
+ const t = b(e, "appearance");
259
266
  if (t?.attributes?.theme)
260
267
  return;
261
268
  const n = t ?? g(e, "appearance");
262
269
  n.attributes = { ...n.attributes, theme: r };
263
270
  }
264
- function Ue(e) {
271
+ function Ke(e) {
265
272
  const r = g(e, "resources");
266
273
  r.attributes = {
267
274
  ...r.attributes,
@@ -269,30 +276,30 @@ function Ue(e) {
269
276
  math: "online"
270
277
  };
271
278
  }
272
- function Ne(e, r = {}) {
279
+ function ze(e, r = {}) {
273
280
  const t = r.cssTheme?.trim(), n = r.revealTheme?.trim(), o = r.target === "slides";
274
281
  if (!e && !t && !o)
275
- return R;
276
- const s = y(e ?? R), a = w(s, "publication");
282
+ return A;
283
+ const s = y(e ?? A), a = b(s, "publication");
277
284
  if (!a)
278
285
  throw new Error(
279
286
  "Invalid publication file: no root <publication> element found"
280
287
  );
281
288
  const i = g(a, "html"), u = g(i, "platform");
282
- if (u.attributes = { ...u.attributes, portable: "yes" }, t && Oe(i, t), o) {
289
+ if (u.attributes = { ...u.attributes, portable: "yes" }, t && He(i, t), o) {
283
290
  const c = g(a, "revealjs");
284
- Ue(c), n && We(c, n);
291
+ Ke(c), n && Je(c, n);
285
292
  }
286
- return $(s);
293
+ return S(s);
287
294
  }
288
- function J(e) {
295
+ function K(e) {
289
296
  if (!(e === void 0 || e === "" || e.startsWith("/")))
290
297
  return e.endsWith("/") ? e : `${e}/`;
291
298
  }
292
- function He(e) {
293
- const r = y(e ?? R), t = w(r, "publication"), n = t && w(t, "source"), o = n && w(n, "directories"), s = J(
299
+ function Ye(e) {
300
+ const r = y(e ?? A), t = b(r, "publication"), n = t && b(t, "source"), o = n && b(n, "directories"), s = K(
294
301
  o?.attributes?.external ?? void 0
295
- ), a = J(
302
+ ), a = K(
296
303
  o?.attributes?.generated ?? void 0
297
304
  );
298
305
  return {
@@ -301,11 +308,11 @@ function He(e) {
301
308
  managed: s !== void 0 && a !== void 0
302
309
  };
303
310
  }
304
- const ie = "http://www.w3.org/2001/XInclude", K = 64;
305
- async function Je(e, r, t) {
306
- return e.includes("include") ? (await ae(e, r, t)).content : e;
311
+ const ae = "http://www.w3.org/2001/XInclude", z = 64;
312
+ async function Ve(e, r, t) {
313
+ return e.includes("include") ? (await ce(e, r, t)).content : e;
307
314
  }
308
- async function ae(e, r, t) {
315
+ async function ce(e, r, t) {
309
316
  const n = y(e), o = {
310
317
  projectDir: l.resolve(t),
311
318
  stack: [l.resolve(r)]
@@ -315,24 +322,24 @@ async function ae(e, r, t) {
315
322
  { "": "" },
316
323
  o
317
324
  );
318
- return { tree: n, content: s ? $(n) : e };
325
+ return { tree: n, content: s ? S(n) : e };
319
326
  }
320
- function Ke(e) {
327
+ function Ge(e) {
321
328
  return e.data?.ptxIncludedFile;
322
329
  }
323
- function ze(e, r) {
330
+ function qe(e, r) {
324
331
  const t = e.data ?? (e.data = {});
325
332
  t.ptxIncludedFile = r;
326
333
  }
327
- function S(e, r) {
334
+ function $(e, r) {
328
335
  let t = e;
329
336
  for (const [n, o] of Object.entries(r.attributes))
330
337
  (n === "xmlns" || n.startsWith("xmlns:")) && (t === e && (t = { ...e }), t[n === "xmlns" ? "" : n.slice(6)] = o ?? "");
331
338
  return t;
332
339
  }
333
- function ce(e, r) {
340
+ function le(e, r) {
334
341
  const t = e.name.indexOf(":"), n = t === -1 ? "" : e.name.slice(0, t);
335
- return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && r[n] === ie;
342
+ return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && r[n] === ae;
336
343
  }
337
344
  async function x(e, r, t, n) {
338
345
  let o = !1;
@@ -340,9 +347,9 @@ async function x(e, r, t, n) {
340
347
  const a = e.children[s];
341
348
  if (a.type !== "element")
342
349
  continue;
343
- const i = S(t, a);
344
- if (ce(a, i)) {
345
- const u = await le(
350
+ const i = $(t, a);
351
+ if (le(a, i)) {
352
+ const u = await ue(
346
353
  a,
347
354
  r,
348
355
  i,
@@ -353,7 +360,7 @@ async function x(e, r, t, n) {
353
360
  }
354
361
  return o;
355
362
  }
356
- async function le(e, r, t, n) {
363
+ async function ue(e, r, t, n) {
357
364
  const o = n.stack[n.stack.length - 1];
358
365
  if (e.attributes.xpointer)
359
366
  throw new Error(
@@ -376,11 +383,11 @@ async function le(e, r, t, n) {
376
383
  throw new Error(
377
384
  `Circular xi:include: ${[...n.stack, i].join(" -> ")}`
378
385
  );
379
- if (n.stack.length >= K)
380
- throw new Error(`xi:include nesting exceeds ${K} levels`);
381
- const u = await j(i);
386
+ if (n.stack.length >= z)
387
+ throw new Error(`xi:include nesting exceeds ${z} levels`);
388
+ const u = await B(i);
382
389
  if (u === void 0) {
383
- const p = qe(e, t);
390
+ const p = Qe(e, t);
384
391
  if (p)
385
392
  return await x(p, r, t, n), p.children;
386
393
  throw new Error(`xi:include target not found: ${s} (in ${o})`);
@@ -405,13 +412,13 @@ async function le(e, r, t, n) {
405
412
  (p) => p.type === "element"
406
413
  );
407
414
  for (const p of f)
408
- ze(p, i);
415
+ qe(p, i);
409
416
  return f;
410
417
  }
411
- function z(e) {
418
+ function Y(e) {
412
419
  return e.name === "docinfo";
413
420
  }
414
- async function Ye(e, r, t) {
421
+ async function Ze(e, r, t) {
415
422
  try {
416
423
  const o = y(e).children.find(
417
424
  (c) => c.type === "element"
@@ -421,24 +428,24 @@ async function Ye(e, r, t) {
421
428
  const s = l.resolve(r), a = l.dirname(s), i = {
422
429
  projectDir: l.resolve(t),
423
430
  stack: [s]
424
- }, u = S({ "": "" }, o);
431
+ }, u = $({ "": "" }, o);
425
432
  for (const c of o.children) {
426
433
  if (c.type !== "element")
427
434
  continue;
428
- const f = S(u, c);
429
- if (z(c))
430
- return await x(c, a, f, i), $(c);
431
- if (ce(c, f)) {
432
- const m = (await le(
435
+ const f = $(u, c);
436
+ if (Y(c))
437
+ return await x(c, a, f, i), S(c);
438
+ if (le(c, f)) {
439
+ const m = (await ue(
433
440
  c,
434
441
  a,
435
442
  f,
436
443
  i
437
444
  )).find(
438
- (h) => h.type === "element" && z(h)
445
+ (h) => h.type === "element" && Y(h)
439
446
  );
440
447
  if (m)
441
- return $(m);
448
+ return S(m);
442
449
  continue;
443
450
  }
444
451
  break;
@@ -448,33 +455,33 @@ async function Ye(e, r, t) {
448
455
  return;
449
456
  }
450
457
  }
451
- function qe(e, r) {
458
+ function Qe(e, r) {
452
459
  for (const t of e.children) {
453
460
  if (t.type !== "element")
454
461
  continue;
455
- const n = S(r, t), o = t.name.indexOf(":"), s = o === -1 ? "" : t.name.slice(0, o);
456
- if ((o === -1 ? t.name : t.name.slice(o + 1)) === "fallback" && n[s] === ie)
462
+ const n = $(r, t), o = t.name.indexOf(":"), s = o === -1 ? "" : t.name.slice(0, o);
463
+ if ((o === -1 ? t.name : t.name.slice(o + 1)) === "fallback" && n[s] === ae)
457
464
  return t;
458
465
  }
459
466
  }
460
- function ue(e) {
467
+ function de(e) {
461
468
  return typeof e == "object" && e !== null && e.type === "element";
462
469
  }
463
- function Ge(e) {
470
+ function et(e) {
464
471
  return /^(pf|xhtml):/.test(e.name);
465
472
  }
466
- function Ve(e, r, t) {
467
- const n = [], o = e.children.find(ue);
473
+ function tt(e, r, t) {
474
+ const n = [], o = e.children.find(de);
468
475
  if (o) {
469
476
  const s = t?.parentId ?? "root";
470
- de(o, s, t?.position ?? 1, r, s, n);
477
+ fe(o, s, t?.position ?? 1, r, s, n);
471
478
  }
472
479
  return n;
473
480
  }
474
- function de(e, r, t, n, o, s) {
475
- const a = Ke(e) ?? n;
481
+ function fe(e, r, t, n, o, s) {
482
+ const a = Ge(e) ?? n;
476
483
  let i, u;
477
- if (Ge(e))
484
+ if (et(e))
478
485
  u = "root";
479
486
  else {
480
487
  const f = e.attributes.label ?? e.attributes["xml:id"];
@@ -489,7 +496,7 @@ function de(e, r, t, n, o, s) {
489
496
  }
490
497
  let c = 0;
491
498
  for (const f of e.children)
492
- ue(f) && (c += 1, de(
499
+ de(f) && (c += 1, fe(
493
500
  f,
494
501
  u,
495
502
  c,
@@ -498,61 +505,67 @@ function de(e, r, t, n, o, s) {
498
505
  s
499
506
  ));
500
507
  }
501
- function Tt(e, r) {
508
+ function It(e, r) {
502
509
  let t;
503
510
  for (const n of e)
504
511
  n.line <= r && (t = n);
505
512
  return t ?? e[0];
506
513
  }
507
- function Ze(e) {
514
+ function rt(e) {
508
515
  const r = e.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!\[CDATA\[[\s\S]*?\]\]>/g, " ");
509
516
  return /<\s*slide(?:show)?[\s/>]/.test(r) ? "slides" : "html";
510
517
  }
511
- function Qe() {
512
- return Pe(I(), "xsl");
518
+ function nt() {
519
+ return Ie(j(), "xsl");
513
520
  }
514
- function et() {
521
+ function ot() {
515
522
  return "Suspending" in WebAssembly;
516
523
  }
517
- function tt() {
518
- if (!et())
524
+ function st() {
525
+ if (!ot())
519
526
  throw new Error(
520
527
  "WebAssembly JSPI is not enabled. Run Node with --experimental-wasm-jspi (or use the pretext-html CLI, which re-launches itself with the flag)."
521
528
  );
522
529
  }
523
- function Y(e) {
530
+ function I(e) {
524
531
  return e.includes("'") ? e.includes('"') ? `concat(${e.split("'").map((t) => `'${t}'`).join(`, "'", `)})` : `"${e}"` : `'${e}'`;
525
532
  }
526
- function rt(e) {
533
+ function it(e) {
527
534
  return e.replace(
528
535
  /from '\.\/(https:\/\/[^']+)'/g,
529
536
  (r, t) => `from '${t}'`
530
537
  );
531
538
  }
532
- const nt = "https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@latest/dist/";
533
- function ot(e) {
539
+ const at = `https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@${re}/dist/`, ct = {
540
+ "cli.version": re,
541
+ // Colon-delimited: pretext-runestone.xsl splits them with str:tokenize.
542
+ "rs-js": Re.join(":"),
543
+ "rs-css": je.join(":"),
544
+ "rs-version": De
545
+ };
546
+ function lt(e) {
534
547
  return e.replace(
535
548
  /(<link\b[^>]*\bhref=["'])_static\//gi,
536
- `$1${nt}_static/`
549
+ `$1${at}_static/`
537
550
  );
538
551
  }
539
- function st(e) {
552
+ function ut(e) {
540
553
  return e.slice(0, 65536).replace(/<\?[\s\S]*?\?>/g, " ").replace(/<!--[\s\S]*?-->/g, " ").replace(/<!DOCTYPE[^>]*>/gi, " ").match(/<\s*([A-Za-z][\w:-]*)/)?.[1];
541
554
  }
542
- async function q(e) {
543
- const r = await j(e);
555
+ async function V(e) {
556
+ const r = await B(e);
544
557
  if (r === void 0)
545
558
  throw new Error(
546
559
  `Could not read ${e}. (In the browser build only absolute URLs are readable — pass sourceContent instead of relying on sourcePath.)`
547
560
  );
548
561
  return r;
549
562
  }
550
- async function it(e, r) {
551
- const t = l.resolve(e), n = await j(t);
563
+ async function dt(e, r) {
564
+ const t = l.resolve(e), n = await B(t);
552
565
  if (n !== void 0)
553
- return Ye(n, t, r);
566
+ return Ze(n, t, r);
554
567
  }
555
- function at(e, r, t, n) {
568
+ function ft(e, r, t, n) {
556
569
  const o = e.replace(/^\uFEFF/, "").replace(/<\?xml[\s\S]*?\?>/, "").replace(/<!DOCTYPE[^>]*>/i, ""), s = t === "slides" ? "slideshow" : r === "chapter" || r === "part" ? "book" : "article";
557
570
  return `<pretext>
558
571
  ${n?.trim() ? `${n.trim()}
@@ -563,75 +576,75 @@ ${o}
563
576
  </pretext>
564
577
  `;
565
578
  }
566
- let fe = !1;
567
- function ct(e) {
579
+ let pe = !1;
580
+ function pt(e) {
568
581
  return e instanceof Error && /\bAborted\(/.test(e.message);
569
582
  }
570
- function lt(e) {
583
+ function mt(e) {
571
584
  return e instanceof Error && /memory access|out of bounds/i.test(e.message);
572
585
  }
573
- function ut() {
574
- if (fe)
586
+ function ht() {
587
+ if (pe)
575
588
  throw new Error(
576
589
  "The WebAssembly renderer aborted earlier in this process and cannot be reused. Restart the process (or reload the page) to render again."
577
590
  );
578
591
  }
579
592
  function G(e) {
580
- if (ct(e))
581
- throw fe = !0, new Error(
593
+ if (pt(e))
594
+ throw pe = !0, new Error(
582
595
  "The WebAssembly renderer aborted and cannot be reused. Restart the process (or reload the page) to render again.",
583
596
  { cause: e }
584
597
  );
585
- if (lt(e))
598
+ if (mt(e))
586
599
  throw new Error(
587
600
  "The WebAssembly renderer hit a memory fault. Most often the document is too large for this build's stack — whole-book builds are a known limitation, so try a smaller document, or see the README about rebuilding libxslt-wasm with a larger stack. The same fault also results from running two renders concurrently against the shared libxslt state.",
588
601
  { cause: e }
589
602
  );
590
603
  }
591
- let P;
592
- async function pe() {
593
- return P || (P = (async () => {
604
+ let D;
605
+ async function me() {
606
+ return D || (D = (async () => {
594
607
  const [e, r] = await Promise.all([
595
608
  import("@pretextbook/libxslt-wasm"),
596
609
  import("@pretextbook/libxslt-wasm/exslt")
597
610
  ]);
598
611
  return r.registerAll(), e;
599
- })()), P;
612
+ })()), D;
600
613
  }
601
- const D = /* @__PURE__ */ new Map(), dt = {
614
+ const R = /* @__PURE__ */ new Map(), wt = {
602
615
  html: "preview-html.xsl",
603
616
  slides: "preview-revealjs.xsl"
604
617
  };
605
- async function ft(e, r) {
606
- const t = dt[r], n = `${r}\0${e}`;
607
- let o = D.get(n);
618
+ async function bt(e, r) {
619
+ const t = wt[r], n = `${r}\0${e}`;
620
+ let o = R.get(n);
608
621
  return o || (o = (async () => {
609
- const { XmlDocument: s, XsltStylesheet: a } = await pe(), i = se(e), u = await ee(I(), `/${t}`);
622
+ const { XmlDocument: s, XsltStylesheet: a } = await me(), i = ie(e), u = await ee(j(), `/${t}`);
610
623
  if (u === void 0)
611
624
  throw new Error(
612
- `Could not read ${t} from ${I()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
625
+ `Could not read ${t} from ${j()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
613
626
  );
614
627
  const c = new TextDecoder().decode(u), f = await s.fromString(c, {
615
628
  url: `${i}/${t}`,
616
629
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
617
630
  });
618
631
  return a.fromXmlDocument(f);
619
- })(), D.set(n, o), o.catch(() => D.delete(n))), o;
632
+ })(), R.set(n, o), o.catch(() => R.delete(n))), o;
620
633
  }
621
- let V = Promise.resolve();
622
- function pt(e) {
623
- const r = V.then(
634
+ let q = Promise.resolve();
635
+ function vt(e) {
636
+ const r = q.then(
624
637
  () => Z(e),
625
638
  () => Z(e)
626
639
  );
627
- return V = r.catch(() => {
640
+ return q = r.catch(() => {
628
641
  }), r;
629
642
  }
630
643
  async function Z(e) {
631
- tt(), ut();
632
- const { XmlDocument: r } = await pe(), t = l.resolve(e.sourcePath), n = l.resolve(
644
+ st(), ht();
645
+ const { XmlDocument: r } = await me(), t = l.resolve(e.sourcePath), n = l.resolve(
633
646
  e.projectDir ?? l.dirname(t)
634
- ), o = e.sourceContent ?? await q(t), s = l.relative(n, t);
647
+ ), o = e.sourceContent ?? await V(t), s = l.relative(n, t);
635
648
  if (s.startsWith(".."))
636
649
  throw new Error(
637
650
  `sourcePath (${t}) must live inside projectDir (${n})`
@@ -639,89 +652,91 @@ async function Z(e) {
639
652
  const a = l.relative(
640
653
  n,
641
654
  l.resolve(e.mainSourcePath ?? t)
642
- ), i = a.startsWith("..") ? s : a, u = se(n);
655
+ ), i = a.startsWith("..") ? s : a, u = ie(n);
643
656
  try {
644
657
  let c, f = `${u}/__pretext-preview-publication.xml`;
645
658
  if (e.publicationPath) {
646
659
  const d = l.resolve(e.publicationPath);
647
- c = await q(d);
648
- const v = l.relative(n, d);
649
- v.startsWith("..") || (f = `${u}/${v.split(l.sep).join("/")}`);
660
+ c = await V(d);
661
+ const w = l.relative(n, d);
662
+ w.startsWith("..") || (f = `${u}/${w.split(l.sep).join("/")}`);
650
663
  }
651
664
  let p, m;
652
665
  if (e.sourceMap) {
653
- const d = await ae(
666
+ const d = await ce(
654
667
  o,
655
668
  t,
656
669
  n
657
670
  );
658
671
  p = d.tree, m = d.content;
659
672
  } else
660
- m = await Je(
673
+ m = await Ve(
661
674
  o,
662
675
  t,
663
676
  n
664
677
  );
665
- const h = e.target ?? Ze(m), me = await ft(e.xslDir ?? Qe(), h), M = Ne(c, {
678
+ const h = e.target ?? rt(m), he = await bt(e.xslDir ?? nt(), h), C = ze(c, {
666
679
  cssTheme: e.cssTheme,
667
680
  revealTheme: e.revealTheme,
668
681
  target: h
669
682
  });
670
- Fe(f, M);
671
- const E = He(M), C = l.dirname(l.resolve(n, i)), X = E.external !== void 0 && E.generated !== void 0 ? {
672
- external: l.resolve(C, E.external),
673
- generated: l.resolve(C, E.generated)
674
- } : void 0, T = st(m);
675
- let F = { parentId: "root", position: 1 };
683
+ Ue(f, C);
684
+ const E = Ye(C), O = l.dirname(l.resolve(n, i)), X = E.external !== void 0 && E.generated !== void 0 ? {
685
+ external: l.resolve(O, E.external),
686
+ generated: l.resolve(O, E.generated)
687
+ } : void 0, T = ut(m);
688
+ let N = { parentId: "root", position: 1 };
676
689
  if (T !== "pretext" && T !== "mathbook")
677
690
  if (e.fragment) {
678
- const d = e.docinfo ?? (e.docinfoSourcePath ? await it(e.docinfoSourcePath, n) : void 0);
679
- m = at(
691
+ const d = e.docinfo ?? (e.docinfoSourcePath ? await dt(e.docinfoSourcePath, n) : void 0);
692
+ m = ft(
680
693
  m,
681
694
  T,
682
695
  h,
683
696
  d
684
- ), F = { parentId: d?.trim() ? "root-1-2" : "root-1-1", position: 2 };
697
+ ), N = { parentId: d?.trim() ? "root-1-2" : "root-1-1", position: 2 };
685
698
  } else
686
699
  throw new Error(
687
700
  `The document root is <${T ?? "?"}>, not <pretext> — this looks like an xi:included fragment. Render the project's main source file instead, or pass the fragment option.`
688
701
  );
689
- const _ = p ? Ve(p, t, F) : void 0, O = await r.fromString(m, {
702
+ const F = p ? tt(p, t, N) : void 0, U = await r.fromString(m, {
690
703
  url: `${u}/${i.split(l.sep).join("/")}`,
691
704
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
692
- }), W = {
693
- publisher: Y(f)
705
+ }), k = {
706
+ publisher: I(f)
694
707
  };
695
- for (const [d, v] of Object.entries(e.stringParams ?? {}))
696
- W[d] = Y(v);
697
- let k;
708
+ for (const [d, w] of Object.entries(ct))
709
+ k[d] = I(w);
710
+ for (const [d, w] of Object.entries(e.stringParams ?? {}))
711
+ k[d] = I(w);
712
+ let P;
698
713
  try {
699
- k = await me.apply(O, W);
714
+ P = await he.apply(U, k);
700
715
  } catch (d) {
701
716
  throw G(d), new Error(
702
717
  "PreTeXt XSLT transform failed; see the PTX:ERROR/PTX:FATAL messages on stderr for details.",
703
718
  { cause: d }
704
719
  );
705
720
  } finally {
706
- O.delete();
721
+ U.delete();
707
722
  }
708
723
  try {
709
- let d = rt(k.toHtmlString());
710
- return (e.openKnowls ?? !0) && (d = Ae(d)), h === "slides" ? (d = ot(d), d = we(d, e.revealView ?? "scroll", {
724
+ let d = it(P.toHtmlString());
725
+ return (e.openKnowls ?? !0) && (d = _e(d)), h === "slides" ? (d = lt(d), d = be(d, e.revealView ?? "scroll", {
711
726
  zoom: e.revealZoom
712
- })) : e.theme && (d = be(d, e.theme)), e.previewBanner && (d = ke(d, e.previewBanner)), {
727
+ })) : e.theme && (d = ve(d, e.theme)), e.previewBanner && (d = Pe(d, e.previewBanner)), {
713
728
  html: d,
714
729
  target: h,
715
- ..._ ? { sourceMap: _ } : {},
730
+ ...F ? { sourceMap: F } : {},
716
731
  ...X ? { assetDirs: X } : {}
717
732
  };
718
733
  } catch (d) {
719
734
  throw G(d), d;
720
735
  } finally {
721
- k.delete();
736
+ P.delete();
722
737
  }
723
738
  } finally {
724
- Xe(u);
739
+ Fe(u);
725
740
  }
726
741
  }
727
742
  const Q = `Usage: pretext-html <source.ptx> [options]
@@ -757,7 +772,7 @@ Options:
757
772
  are previews of work in progress
758
773
  -h, --help Show this help
759
774
  `;
760
- function mt(e) {
775
+ function gt(e) {
761
776
  let r, t, n, o;
762
777
  const s = {}, a = {};
763
778
  for (let i = 0; i < e.length; i++) {
@@ -769,7 +784,7 @@ function mt(e) {
769
784
  switch (u) {
770
785
  case "-h":
771
786
  case "--help":
772
- b.stdout.write(Q), b.exit(0);
787
+ v.stdout.write(Q), v.exit(0);
773
788
  break;
774
789
  case "-o":
775
790
  case "--output":
@@ -828,29 +843,29 @@ function mt(e) {
828
843
  sourceMapPath: o
829
844
  };
830
845
  }
831
- async function $t(e) {
832
- const { options: r, output: t, docinfoPath: n, sourceMapPath: o } = mt(e);
833
- n && (r.docinfo = await A(n, "utf8"));
834
- const s = Date.now(), { html: a, sourceMap: i } = await pt(r);
835
- b.stderr.write(`pretext-html: rendered in ${Date.now() - s}ms
836
- `), o && i && (await U(o, JSON.stringify(i, null, 2)), b.stderr.write(`pretext-html: wrote ${o}
837
- `)), t ? (await U(t, a), b.stderr.write(`pretext-html: wrote ${t}
838
- `)) : b.stdout.write(a);
846
+ async function Dt(e) {
847
+ const { options: r, output: t, docinfoPath: n, sourceMapPath: o } = gt(e);
848
+ n && (r.docinfo = await M(n, "utf8"));
849
+ const s = Date.now(), { html: a, sourceMap: i } = await vt(r);
850
+ v.stderr.write(`pretext-html: rendered in ${Date.now() - s}ms
851
+ `), o && i && (await W(o, JSON.stringify(i, null, 2)), v.stderr.write(`pretext-html: wrote ${o}
852
+ `)), t ? (await W(t, a), v.stderr.write(`pretext-html: wrote ${t}
853
+ `)) : v.stdout.write(a);
839
854
  }
840
855
  export {
841
856
  ge as P,
842
- Ze as a,
843
- Ne as b,
844
- et as c,
845
- Qe as d,
846
- Et as e,
847
- Tt as f,
848
- mt as g,
849
- ke as i,
850
- $t as m,
851
- Ae as o,
852
- Ee as p,
853
- pt as r,
854
- yt as s,
855
- Y as x
857
+ rt as a,
858
+ ze as b,
859
+ ot as c,
860
+ nt as d,
861
+ Pt as e,
862
+ It as f,
863
+ gt as g,
864
+ Pe as i,
865
+ Dt as m,
866
+ _e as o,
867
+ Te as p,
868
+ vt as r,
869
+ kt as s,
870
+ I as x
856
871
  };