@pretextbook/pretext-html 0.9.0 → 0.10.1

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,7 +1,7 @@
1
- import { fromXml as y } from "xast-util-from-xml";
2
- import { toXml as $ } from "xast-util-to-xml";
1
+ import { fromXml as T } from "xast-util-from-xml";
2
+ import { toXml as I } from "xast-util-to-xml";
3
3
  const N = "/";
4
- function Oe(e) {
4
+ function ue(e) {
5
5
  if (!e)
6
6
  return ".";
7
7
  const n = e.startsWith("/"), t = e.length > 1 && e.endsWith("/"), r = [];
@@ -25,10 +25,14 @@ function h(...e) {
25
25
  break;
26
26
  }
27
27
  n.startsWith("/") || (n = `/${n}`);
28
- const t = Oe(n);
28
+ const t = ue(n);
29
29
  return t.length > 1 && t.endsWith("/") ? t.slice(0, -1) : t;
30
30
  }
31
- function I(e) {
31
+ function Be(...e) {
32
+ const n = e.filter(Boolean).join("/");
33
+ return n ? ue(n) : ".";
34
+ }
35
+ function E(e) {
32
36
  const n = e.replace(/\/+$/, "");
33
37
  if (!n)
34
38
  return e.startsWith("/") ? "/" : ".";
@@ -42,11 +46,11 @@ function B(e, n) {
42
46
  i += 1;
43
47
  return [...new Array(t.length - i).fill(".."), ...r.slice(i)].join("/");
44
48
  }
45
- const Be = "ptxPreviewBannerDismissed", Ce = "About live preview";
49
+ const je = "ptxPreviewBannerDismissed", Ce = "About live preview";
46
50
  function Q(e) {
47
51
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
48
52
  }
49
- function je(e) {
53
+ function Fe(e) {
50
54
  return [
51
55
  '<div id="ptx-preview-banner" class="ptx-preview-banner" role="note">',
52
56
  ` <span class="ptx-preview-banner-text">${Q(e)}</span>`,
@@ -56,7 +60,7 @@ function je(e) {
56
60
  ].join(`
57
61
  `);
58
62
  }
59
- function Fe() {
63
+ function Ne() {
60
64
  return [
61
65
  "<style>",
62
66
  ".ptx-preview-banner {",
@@ -117,11 +121,11 @@ function Fe() {
117
121
  ].join(`
118
122
  `);
119
123
  }
120
- function Ne() {
124
+ function We() {
121
125
  return [
122
126
  "<script>",
123
127
  "(function () {",
124
- " var KEY = " + JSON.stringify(Be) + ";",
128
+ " var KEY = " + JSON.stringify(je) + ";",
125
129
  ' var banner = document.getElementById("ptx-preview-banner");',
126
130
  ' var restore = document.getElementById("ptx-preview-banner-restore");',
127
131
  " if (!banner || !restore) { return; }",
@@ -158,39 +162,39 @@ function Ne() {
158
162
  ].join(`
159
163
  `);
160
164
  }
161
- const We = "<!--ptx-preview-banner-->", He = "<!--/ptx-preview-banner-->", Ue = /\n?<!--ptx-preview-banner-->[\s\S]*?<!--\/ptx-preview-banner-->/;
162
- function Ve(e, n) {
163
- const t = Ue.exec(e), r = t ? e.slice(0, t.index) + e.slice(t.index + t[0].length) : e;
165
+ const He = "<!--ptx-preview-banner-->", Ue = "<!--/ptx-preview-banner-->", Ve = /\n?<!--ptx-preview-banner-->[\s\S]*?<!--\/ptx-preview-banner-->/;
166
+ function Xe(e, n) {
167
+ const t = Ve.exec(e), r = t ? e.slice(0, t.index) + e.slice(t.index + t[0].length) : e;
164
168
  if (!/<body[^>]*>/i.test(r))
165
169
  return r;
166
170
  const i = `
167
- ${We}
168
- ${Fe()}
169
- ${je(n.message)}
171
+ ${He}
170
172
  ${Ne()}
171
- ${He}`;
173
+ ${Fe(n.message)}
174
+ ${We()}
175
+ ${Ue}`;
172
176
  return r.replace(/<body([^>]*)>/i, `<body$1>${i}`);
173
177
  }
174
- const Xe = "https://cdn.jsdelivr.net/npm/@pretextbook/pretext-html@0.9.0/assets";
175
- let ue;
176
- function mn(e) {
177
- ue = e.replace(/\/+$/, "");
178
+ const ze = "https://cdn.jsdelivr.net/npm/@pretextbook/pretext-html@0.10.1/assets";
179
+ let fe;
180
+ function wn(e) {
181
+ fe = e.replace(/\/+$/, "");
178
182
  }
179
183
  function A() {
180
- return ue ?? Xe;
184
+ return fe ?? ze;
181
185
  }
182
- function fe(e, n) {
186
+ function pe(e, n) {
183
187
  return `${e.replace(/\/+$/, "")}/${n.replace(/^\/+/, "")}`;
184
188
  }
185
189
  const ee = /* @__PURE__ */ new Map();
186
- function ze(e) {
190
+ function Je(e) {
187
191
  return `${e.replace(/\/+$/, "")}-bundle.json`;
188
192
  }
189
- function Je(e) {
193
+ function Ge(e) {
190
194
  let n = ee.get(e);
191
195
  return n || (n = (async () => {
192
196
  try {
193
- const t = await fetch(ze(e));
197
+ const t = await fetch(Je(e));
194
198
  if (!t.ok)
195
199
  return /* @__PURE__ */ new Map();
196
200
  const r = await t.json();
@@ -200,12 +204,12 @@ function Je(e) {
200
204
  }
201
205
  })(), ee.set(e, n)), n;
202
206
  }
203
- function Ge(e) {
204
- return e === fe(A(), "xsl");
207
+ function Ke(e) {
208
+ return e === pe(A(), "xsl");
205
209
  }
206
- async function pe(e, n) {
207
- if (Ge(e)) {
208
- const o = (await Je(e)).get(n.replace(/^\/+/, ""));
210
+ async function he(e, n) {
211
+ if (Ke(e)) {
212
+ const o = (await Ge(e)).get(n.replace(/^\/+/, ""));
209
213
  if (o !== void 0)
210
214
  return new TextEncoder().encode(o);
211
215
  }
@@ -238,42 +242,42 @@ async function P(e) {
238
242
  return;
239
243
  }
240
244
  }
241
- const he = "2.48.1", Ke = "8.2.4", Ye = [
245
+ const me = "2.49.1", Ye = "8.2.4", qe = [
242
246
  "prefix-runtime.40bd1420d3277749.bundle.js",
243
247
  "prefix-926.5c7038c8ef173faf.bundle.js",
244
248
  "prefix-runestone.b388362b5f43738a.bundle.js"
245
- ], qe = [
249
+ ], Ze = [
246
250
  "prefix-926.229729d09512acc9.css",
247
251
  "prefix-runestone.8086b62682b271d1.css"
248
- ], Ze = "born-hidden-knowl", Qe = /<details\b([^>]*)>(\s*)(?:<summary\b([^>]*)>)?/g;
249
- function et(e) {
252
+ ], Qe = "born-hidden-knowl", et = /<details\b([^>]*)>(\s*)(?:<summary\b([^>]*)>)?/g;
253
+ function tt(e) {
250
254
  const n = /\bclass="([^"]*)"/.exec(e);
251
255
  return n ? n[1].trim().split(/\s+/) : [];
252
256
  }
253
- function tt(e) {
257
+ function nt(e) {
254
258
  return /(^|\s)open(\s|=|$)/.test(e);
255
259
  }
256
260
  function te(e) {
257
- return tt(e) ? e : ` open${e}`;
261
+ return nt(e) ? e : ` open${e}`;
258
262
  }
259
- function nt(e) {
263
+ function rt(e) {
260
264
  return e.replace(
261
- Qe,
265
+ et,
262
266
  (n, t, r, i) => {
263
- if (!et(t).includes(Ze))
267
+ if (!tt(t).includes(Qe))
264
268
  return n;
265
269
  const o = `<details${te(t)}>`;
266
270
  return i === void 0 ? `${o}${r}` : `${o}${r}<summary${te(i)}>`;
267
271
  }
268
272
  );
269
273
  }
270
- const X = /* @__PURE__ */ new Map(), me = /* @__PURE__ */ new Map();
271
- let W, rt = 0, we = pe;
272
- function wn(e) {
273
- we = e;
274
+ const X = /* @__PURE__ */ new Map(), we = /* @__PURE__ */ new Map();
275
+ let W, it = 0, ve = he;
276
+ function vn(e) {
277
+ ve = e;
274
278
  }
275
- function it(e, n) {
276
- const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, r = me.get(t);
279
+ function ot(e, n) {
280
+ const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, r = we.get(t);
277
281
  if (r !== void 0)
278
282
  return Promise.resolve(new Response(r, { status: 200 }));
279
283
  let i;
@@ -283,29 +287,29 @@ function it(e, n) {
283
287
  i = "";
284
288
  }
285
289
  const o = X.get(i);
286
- return o !== void 0 ? st(o, t) : W(e, n);
290
+ return o !== void 0 ? ct(o, t) : W(e, n);
287
291
  }
288
- const ot = '<?xml version="1.0"?><pretext-preview-missing-file/>';
289
- async function st(e, n) {
290
- const t = decodeURIComponent(new URL(n).pathname), r = await we(e, t);
292
+ const st = '<?xml version="1.0"?><pretext-preview-missing-file/>';
293
+ async function ct(e, n) {
294
+ const t = decodeURIComponent(new URL(n).pathname), r = await ve(e, t);
291
295
  if (r === void 0)
292
- return new Response(ot, { status: 200 });
296
+ return new Response(st, { status: 200 });
293
297
  const i = typeof r == "string" ? r : new Uint8Array(r);
294
298
  return new Response(i, { status: 200 });
295
299
  }
296
- function ve() {
297
- W || (W = globalThis.fetch, globalThis.fetch = it);
300
+ function ge() {
301
+ W || (W = globalThis.fetch, globalThis.fetch = ot);
298
302
  }
299
- function ge(e) {
300
- ve();
301
- const n = `mnt${++rt}.ptx.invalid`;
303
+ function be(e) {
304
+ ge();
305
+ const n = `mnt${++it}.ptx.invalid`;
302
306
  return X.set(n, e), `http://${n}`;
303
307
  }
304
308
  function at(e) {
305
309
  X.delete(new URL(e).host);
306
310
  }
307
- function ct(e, n) {
308
- ve(), me.set(e, n);
311
+ function lt(e, n) {
312
+ ge(), we.set(e, n);
309
313
  }
310
314
  const H = `<?xml version="1.0" encoding="UTF-8"?>
311
315
  <publication>
@@ -316,60 +320,60 @@ const H = `<?xml version="1.0" encoding="UTF-8"?>
316
320
  <platform portable="yes"/>
317
321
  </html>
318
322
  </publication>
319
- `, lt = ["theme", "style", "shell"];
323
+ `, dt = ["theme", "style", "shell"];
320
324
  function x(e, n) {
321
325
  for (const t of e.children)
322
326
  if (t.type === "element" && t.name === n)
323
327
  return t;
324
328
  }
325
- function E(e, n) {
329
+ function y(e, n) {
326
330
  let t = x(e, n);
327
331
  return t || (t = { type: "element", name: n, attributes: {}, children: [] }, e.children.push(t)), t;
328
332
  }
329
- function dt(e, n) {
333
+ function ut(e, n) {
330
334
  const t = x(e, "css");
331
- if (t && lt.some((i) => t.attributes?.[i]))
335
+ if (t && dt.some((i) => t.attributes?.[i]))
332
336
  return;
333
- const r = t ?? E(e, "css");
337
+ const r = t ?? y(e, "css");
334
338
  r.attributes = { ...r.attributes, theme: n };
335
339
  }
336
- function ut(e, n) {
340
+ function ft(e, n) {
337
341
  const t = x(e, "appearance");
338
342
  if (t?.attributes?.theme)
339
343
  return;
340
- const r = t ?? E(e, "appearance");
344
+ const r = t ?? y(e, "appearance");
341
345
  r.attributes = { ...r.attributes, theme: n };
342
346
  }
343
- function ft(e) {
344
- const n = E(e, "resources");
347
+ function pt(e) {
348
+ const n = y(e, "resources");
345
349
  n.attributes = {
346
350
  ...n.attributes,
347
351
  host: "cdn",
348
352
  math: "online"
349
353
  };
350
354
  }
351
- function pt(e, n = {}) {
355
+ function ht(e, n = {}) {
352
356
  const t = n.cssTheme?.trim(), r = n.revealTheme?.trim(), i = n.target === "slides";
353
357
  if (!e && !t && !i)
354
358
  return H;
355
- const o = y(e ?? H), s = x(o, "publication");
359
+ const o = T(e ?? H), s = x(o, "publication");
356
360
  if (!s)
357
361
  throw new Error(
358
362
  "Invalid publication file: no root <publication> element found"
359
363
  );
360
- const a = E(s, "html"), l = E(a, "platform");
361
- if (l.attributes = { ...l.attributes, portable: "yes" }, t && dt(a, t), i) {
362
- const d = E(s, "revealjs");
363
- ft(d), r && ut(d, r);
364
+ const c = y(s, "html"), a = y(c, "platform");
365
+ if (a.attributes = { ...a.attributes, portable: "yes" }, t && ut(c, t), i) {
366
+ const d = y(s, "revealjs");
367
+ pt(d), r && ft(d, r);
364
368
  }
365
- return $(o);
369
+ return I(o);
366
370
  }
367
371
  function ne(e) {
368
372
  if (!(e === void 0 || e === "" || e.startsWith("/")))
369
373
  return e.endsWith("/") ? e : `${e}/`;
370
374
  }
371
- function ht(e) {
372
- const n = y(e ?? H), t = x(n, "publication"), r = t && x(t, "source"), i = r && x(r, "directories"), o = ne(
375
+ function mt(e) {
376
+ const n = T(e ?? H), t = x(n, "publication"), r = t && x(t, "source"), i = r && x(r, "directories"), o = ne(
373
377
  i?.attributes?.external ?? void 0
374
378
  ), s = ne(
375
379
  i?.attributes?.generated ?? void 0
@@ -380,18 +384,18 @@ function ht(e) {
380
384
  managed: o !== void 0 && s !== void 0
381
385
  };
382
386
  }
383
- function vn(e) {
387
+ function gn(e) {
384
388
  return e === "slides" || e === "scroll";
385
389
  }
386
- const be = 960, xe = 700, mt = 1, wt = 0.04;
387
- function vt(e) {
388
- const n = typeof e == "number" && isFinite(e) ? e : mt, t = Math.min(1, Math.max(0.25, n));
390
+ const xe = 960, Ee = 700, wt = 1, vt = 0.04;
391
+ function gt(e) {
392
+ const n = typeof e == "number" && isFinite(e) ? e : wt, t = Math.min(1, Math.max(0.25, n));
389
393
  return {
390
- width: Math.round(be / t),
391
- height: Math.round(xe / t)
394
+ width: Math.round(xe / t),
395
+ height: Math.round(Ee / t)
392
396
  };
393
397
  }
394
- function gt(e) {
398
+ function bt(e) {
395
399
  return {
396
400
  view: "scroll",
397
401
  scrollLayout: "compact",
@@ -401,11 +405,11 @@ function gt(e) {
401
405
  controls: !1,
402
406
  controlsTutorial: !1,
403
407
  hash: !1,
404
- ...vt(e.zoom),
405
- margin: wt
408
+ ...gt(e.zoom),
409
+ margin: vt
406
410
  };
407
411
  }
408
- function bt() {
412
+ function xt() {
409
413
  return {
410
414
  // Explicitly null rather than absent: the same page may have been
411
415
  // delivered in scroll view a moment ago, and an embedder that re-injects
@@ -417,11 +421,11 @@ function bt() {
417
421
  // size with a percentage width renders its text far larger, relative to
418
422
  // the slide, than the same deck will on a projector. No zoom margin
419
423
  // though — presenting means filling whatever it is shown in.
420
- width: be,
421
- height: xe
424
+ width: xe,
425
+ height: Ee
422
426
  };
423
427
  }
424
- const xt = [
428
+ const Et = [
425
429
  "<style>",
426
430
  ".reveal-viewport.reveal-scroll .scroll-page section {",
427
431
  " box-shadow: inset 0 0 0 calc(1px / var(--slide-scale, 1))",
@@ -429,14 +433,14 @@ const xt = [
429
433
  "}",
430
434
  "</style>"
431
435
  ].join(`
432
- `), Et = [
436
+ `), yt = [
433
437
  " var paused = document.querySelectorAll('.reveal .fragment');",
434
438
  " for (var i = 0; i < paused.length; i++) {",
435
439
  " paused[i].classList.remove('fragment');",
436
440
  " }"
437
441
  ];
438
- function yt(e, n = {}) {
439
- const t = e === "scroll" ? gt(n) : bt();
442
+ function Tt(e, n = {}) {
443
+ const t = e === "scroll" ? bt(n) : xt();
440
444
  return [
441
445
  "<script>",
442
446
  "(function () {",
@@ -464,7 +468,7 @@ function yt(e, n = {}) {
464
468
  // Inside the wrapper rather than at top level: this script sits in <head>,
465
469
  // where the slides have not been parsed yet, but the deck calls initialize
466
470
  // from the end of the document, by which time they have.
467
- ...e === "scroll" ? Et : [],
471
+ ...e === "scroll" ? yt : [],
468
472
  " return initialize(merged);",
469
473
  " };",
470
474
  "})();",
@@ -472,38 +476,38 @@ function yt(e, n = {}) {
472
476
  ].join(`
473
477
  `);
474
478
  }
475
- const Tt = /<script\b[^>]*\bsrc=["'][^"']*\breveal\.js["'][^>]*>\s*<\/script>/i, St = "<!--ptx-reveal-view-->", kt = "<!--/ptx-reveal-view-->", $t = /\n?<!--ptx-reveal-view-->[\s\S]*?<!--\/ptx-reveal-view-->/;
476
- function It(e, n, t = {}) {
477
- const r = $t.exec(e), i = r ? e.slice(0, r.index) + e.slice(r.index + r[0].length) : e, o = Tt.exec(i);
479
+ const St = /<script\b[^>]*\bsrc=["'][^"']*\breveal\.js["'][^>]*>\s*<\/script>/i, kt = "<!--ptx-reveal-view-->", $t = "<!--/ptx-reveal-view-->", It = /\n?<!--ptx-reveal-view-->[\s\S]*?<!--\/ptx-reveal-view-->/;
480
+ function _t(e, n, t = {}) {
481
+ const r = It.exec(e), i = r ? e.slice(0, r.index) + e.slice(r.index + r[0].length) : e, o = St.exec(i);
478
482
  if (!o)
479
483
  return i;
480
- const s = o.index + o[0].length, a = `
481
- ${St}
482
- ${xt}
483
- ${yt(n, t)}
484
- ${kt}`;
485
- return i.slice(0, s) + a + i.slice(s);
486
- }
487
- const Ee = "http://www.w3.org/2001/XInclude", re = 64;
488
- async function _t(e, n, t) {
484
+ const s = o.index + o[0].length, c = `
485
+ ${kt}
486
+ ${Et}
487
+ ${Tt(n, t)}
488
+ ${$t}`;
489
+ return i.slice(0, s) + c + i.slice(s);
490
+ }
491
+ const ye = "http://www.w3.org/2001/XInclude", re = 64;
492
+ async function Rt(e, n, t) {
489
493
  return e.includes("include") ? (await z(e, n, t)).content : e;
490
494
  }
491
495
  async function z(e, n, t) {
492
- const r = y(e), i = {
496
+ const r = T(e), i = {
493
497
  projectDir: h(t),
494
498
  stack: [h(n)]
495
499
  }, o = await _(
496
500
  r,
497
- I(h(n)),
501
+ E(h(n)),
498
502
  { "": "" },
499
503
  i
500
504
  );
501
- return { tree: r, content: o ? $(r) : e };
505
+ return { tree: r, content: o ? I(r) : e };
502
506
  }
503
- function Rt(e) {
507
+ function Dt(e) {
504
508
  return e.data?.ptxIncludedFile;
505
509
  }
506
- function Dt(e, n) {
510
+ function Mt(e, n) {
507
511
  const t = e.data ?? (e.data = {});
508
512
  t.ptxIncludedFile = n;
509
513
  }
@@ -513,9 +517,9 @@ function L(e, n) {
513
517
  (r === "xmlns" || r.startsWith("xmlns:")) && (t === e && (t = { ...e }), t[r === "xmlns" ? "" : r.slice(6)] = i ?? "");
514
518
  return t;
515
519
  }
516
- function ye(e, n) {
520
+ function Te(e, n) {
517
521
  const t = e.name.indexOf(":"), r = t === -1 ? "" : e.name.slice(0, t);
518
- return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && n[r] === Ee;
522
+ return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && n[r] === ye;
519
523
  }
520
524
  async function _(e, n, t, r) {
521
525
  let i = !1;
@@ -523,20 +527,20 @@ async function _(e, n, t, r) {
523
527
  const s = e.children[o];
524
528
  if (s.type !== "element")
525
529
  continue;
526
- const a = L(t, s);
527
- if (ye(s, a)) {
528
- const l = await Te(
530
+ const c = L(t, s);
531
+ if (Te(s, c)) {
532
+ const a = await Se(
529
533
  s,
530
534
  n,
531
- a,
535
+ c,
532
536
  r
533
537
  );
534
- e.children.splice(o, 1, ...l), o += l.length - 1, i = !0;
535
- } else await _(s, n, a, r) && (i = !0);
538
+ e.children.splice(o, 1, ...a), o += a.length - 1, i = !0;
539
+ } else await _(s, n, c, r) && (i = !0);
536
540
  }
537
541
  return i;
538
542
  }
539
- async function Te(e, n, t, r) {
543
+ async function Se(e, n, t, r) {
540
544
  const i = r.stack[r.stack.length - 1];
541
545
  if (e.attributes.xpointer)
542
546
  throw new Error(
@@ -550,78 +554,78 @@ async function Te(e, n, t, r) {
550
554
  s = decodeURIComponent(o);
551
555
  } catch {
552
556
  }
553
- const a = h(n, s);
554
- if (a !== r.projectDir && !a.startsWith(r.projectDir + N))
557
+ const c = h(n, s);
558
+ if (c !== r.projectDir && !c.startsWith(r.projectDir + N))
555
559
  throw new Error(
556
560
  `xi:include escapes the project directory: ${o} (in ${i})`
557
561
  );
558
- if (r.stack.includes(a))
562
+ if (r.stack.includes(c))
559
563
  throw new Error(
560
- `Circular xi:include: ${[...r.stack, a].join(" -> ")}`
564
+ `Circular xi:include: ${[...r.stack, c].join(" -> ")}`
561
565
  );
562
566
  if (r.stack.length >= re)
563
567
  throw new Error(`xi:include nesting exceeds ${re} levels`);
564
- const l = await P(a);
565
- if (l === void 0) {
566
- const p = At(e, t);
568
+ const a = await P(c);
569
+ if (a === void 0) {
570
+ const p = Lt(e, t);
567
571
  if (p)
568
572
  return await _(p, n, t, r), p.children;
569
573
  throw new Error(`xi:include target not found: ${o} (in ${i})`);
570
574
  }
571
575
  if (e.attributes.parse === "text")
572
- return [{ type: "text", value: l }];
576
+ return [{ type: "text", value: a }];
573
577
  let d;
574
578
  try {
575
- d = y(l);
579
+ d = T(a);
576
580
  } catch (p) {
577
581
  throw new Error(
578
- `Could not parse xi:include target ${a} as XML: ${p instanceof Error ? p.message : p}. (Included files must be well-formed, with a single root element.)`
582
+ `Could not parse xi:include target ${c} as XML: ${p instanceof Error ? p.message : p}. (Included files must be well-formed, with a single root element.)`
579
583
  );
580
584
  }
581
- r.stack.push(a);
585
+ r.stack.push(c);
582
586
  try {
583
- await _(d, I(a), { "": "" }, r);
587
+ await _(d, E(c), { "": "" }, r);
584
588
  } finally {
585
589
  r.stack.pop();
586
590
  }
587
- const f = d.children.filter(
591
+ const u = d.children.filter(
588
592
  (p) => p.type === "element"
589
593
  );
590
- for (const p of f)
591
- Dt(p, a);
592
- return f;
594
+ for (const p of u)
595
+ Mt(p, c);
596
+ return u;
593
597
  }
594
598
  function ie(e) {
595
599
  return e.name === "docinfo";
596
600
  }
597
- async function Mt(e, n, t) {
601
+ async function At(e, n, t) {
598
602
  try {
599
- const i = y(e).children.find(
603
+ const i = T(e).children.find(
600
604
  (d) => d.type === "element"
601
605
  );
602
606
  if (!i)
603
607
  return;
604
- const o = h(n), s = I(o), a = {
608
+ const o = h(n), s = E(o), c = {
605
609
  projectDir: h(t),
606
610
  stack: [o]
607
- }, l = L({ "": "" }, i);
611
+ }, a = L({ "": "" }, i);
608
612
  for (const d of i.children) {
609
613
  if (d.type !== "element")
610
614
  continue;
611
- const f = L(l, d);
615
+ const u = L(a, d);
612
616
  if (ie(d))
613
- return await _(d, s, f, a), $(d);
614
- if (ye(d, f)) {
615
- const u = (await Te(
617
+ return await _(d, s, u, c), I(d);
618
+ if (Te(d, u)) {
619
+ const f = (await Se(
616
620
  d,
617
621
  s,
618
- f,
619
- a
622
+ u,
623
+ c
620
624
  )).find(
621
625
  (m) => m.type === "element" && ie(m)
622
626
  );
623
- if (u)
624
- return $(u);
627
+ if (f)
628
+ return I(f);
625
629
  continue;
626
630
  }
627
631
  break;
@@ -631,78 +635,78 @@ async function Mt(e, n, t) {
631
635
  return;
632
636
  }
633
637
  }
634
- function At(e, n) {
638
+ function Lt(e, n) {
635
639
  for (const t of e.children) {
636
640
  if (t.type !== "element")
637
641
  continue;
638
642
  const r = L(n, t), i = t.name.indexOf(":"), o = i === -1 ? "" : t.name.slice(0, i);
639
- if ((i === -1 ? t.name : t.name.slice(i + 1)) === "fallback" && r[o] === Ee)
643
+ if ((i === -1 ? t.name : t.name.slice(i + 1)) === "fallback" && r[o] === ye)
640
644
  return t;
641
645
  }
642
646
  }
643
- function Se(e) {
647
+ function ke(e) {
644
648
  return typeof e == "object" && e !== null && e.type === "element";
645
649
  }
646
- function Lt(e) {
650
+ function Pt(e) {
647
651
  return /^(pf|xhtml):/.test(e.name);
648
652
  }
649
- function Pt(e, n, t) {
650
- const r = [], i = e.children.find(Se);
653
+ function Ot(e, n, t) {
654
+ const r = [], i = e.children.find(ke);
651
655
  if (i) {
652
656
  const o = t?.parentId ?? "root";
653
- ke(i, o, t?.position ?? 1, n, o, r);
657
+ $e(i, o, t?.position ?? 1, n, o, r);
654
658
  }
655
659
  return r;
656
660
  }
657
- function ke(e, n, t, r, i, o) {
658
- const s = Rt(e) ?? r;
659
- let a, l;
660
- if (Lt(e))
661
- l = "root";
661
+ function $e(e, n, t, r, i, o) {
662
+ const s = Dt(e) ?? r;
663
+ let c, a;
664
+ if (Pt(e))
665
+ a = "root";
662
666
  else {
663
- const f = e.attributes.label ?? e.attributes["xml:id"];
664
- a = f ?? `${n}-${t}`, o.push({
665
- id: a,
667
+ const u = e.attributes.label ?? e.attributes["xml:id"];
668
+ c = u ?? `${n}-${t}`, o.push({
669
+ id: c,
666
670
  file: s,
667
671
  line: e.position?.start.line ?? 1,
668
672
  column: e.position?.start.column ?? 1,
669
673
  endLine: e.position?.end.line ?? e.position?.start.line ?? 1,
670
674
  parent: i
671
- }), l = a;
675
+ }), a = c;
672
676
  }
673
677
  let d = 0;
674
- for (const f of e.children)
675
- Se(f) && (d += 1, ke(
676
- f,
677
- l,
678
+ for (const u of e.children)
679
+ ke(u) && (d += 1, $e(
680
+ u,
681
+ a,
678
682
  d,
679
683
  s,
680
- a ?? i,
684
+ c ?? i,
681
685
  o
682
686
  ));
683
687
  }
684
- function gn(e, n) {
688
+ function bn(e, n) {
685
689
  let t;
686
690
  for (const r of e)
687
691
  r.line <= n && (t = r);
688
692
  return t ?? e[0];
689
693
  }
690
- function Ot(e) {
694
+ function Bt(e) {
691
695
  const n = e.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!\[CDATA\[[\s\S]*?\]\]>/g, " ");
692
696
  return /<\s*slide(?:show)?[\s/>]/.test(n) ? "slides" : "html";
693
697
  }
694
- const $e = "pretext-html:set-theme";
695
- function bn(e) {
698
+ const Ie = "pretext-html:set-theme";
699
+ function xn(e) {
696
700
  return e === "dark" || e === "light" || e === "system";
697
701
  }
698
- function xn(e) {
699
- return { type: $e, theme: e };
702
+ function En(e) {
703
+ return { type: Ie, theme: e };
700
704
  }
701
- function Bt(e) {
705
+ function jt(e) {
702
706
  return [
703
707
  "<script>",
704
708
  "(function () {",
705
- " var CFG = " + JSON.stringify({ msg: $e, initial: e }) + ";",
709
+ " var CFG = " + JSON.stringify({ msg: Ie, initial: e }) + ";",
706
710
  // Where the last requested theme is remembered so it survives an in-place
707
711
  // document rewrite (same Window) and outranks the baked initial value.
708
712
  " var KEY = '__ptxPreviewTheme';",
@@ -773,11 +777,11 @@ function Bt(e) {
773
777
  `);
774
778
  }
775
779
  function Ct(e, n) {
776
- const t = Bt(n);
780
+ const t = jt(n);
777
781
  return /<head[^>]*>/i.test(e) ? e.replace(/<head([^>]*)>/i, `<head$1>
778
782
  ${t}`) : e;
779
783
  }
780
- const Ie = /* @__PURE__ */ new Set([
784
+ const _e = /* @__PURE__ */ new Set([
781
785
  "colophon",
782
786
  "biography",
783
787
  "dedication",
@@ -797,69 +801,69 @@ const Ie = /* @__PURE__ */ new Set([
797
801
  "glossary",
798
802
  "worksheet",
799
803
  "handout"
800
- ]), _e = /* @__PURE__ */ new Set([
804
+ ]), Re = /* @__PURE__ */ new Set([
801
805
  "book",
802
806
  "article",
803
807
  "slideshow",
804
808
  "letter",
805
809
  "memo"
806
- ]), Re = /* @__PURE__ */ new Set([
810
+ ]), De = /* @__PURE__ */ new Set([
811
+ ...Re,
807
812
  ..._e,
808
- ...Ie,
809
813
  "part",
810
814
  "frontmatter",
811
815
  "backmatter"
812
- ]), jt = /* @__PURE__ */ new Set(["docinfo"]), De = /* @__PURE__ */ new Set([
816
+ ]), Ft = /* @__PURE__ */ new Set(["docinfo"]), Me = /* @__PURE__ */ new Set([
813
817
  "title",
814
818
  "shorttitle",
815
819
  "plaintitle",
816
820
  "subtitle",
817
821
  "caption"
818
822
  ]);
819
- function v(e) {
823
+ function g(e) {
820
824
  return e.type === "element";
821
825
  }
822
- function Me(e) {
826
+ function Ae(e) {
823
827
  return e.attributes["xml:id"] ?? void 0;
824
828
  }
825
829
  function U(e, n) {
826
830
  for (const t of e.children) {
827
- if (!v(t)) continue;
828
- if (Me(t) === n) return t;
831
+ if (!g(t)) continue;
832
+ if (Ae(t) === n) return t;
829
833
  const r = U(t, n);
830
834
  if (r) return r;
831
835
  }
832
836
  }
833
837
  function M(e, n) {
834
838
  for (const t of e.children) {
835
- if (!v(t)) continue;
839
+ if (!g(t)) continue;
836
840
  if (t === n) return [t];
837
841
  const r = M(t, n);
838
842
  if (r) return [t, ...r];
839
843
  }
840
844
  }
841
- function Ft(e, n) {
845
+ function Nt(e, n) {
842
846
  let t = 0;
843
847
  for (const [r, i] of e.entries()) {
844
848
  const o = r === 0 ? void 0 : e[r - 1];
845
- _e.has(i.name) ? t = 0 : i.name === "frontmatter" || i.name === "backmatter" || i.name === "part" ? t = o?.name === "book" && n ? 1 : 0 : Ie.has(i.name) && (t += 1);
849
+ Re.has(i.name) ? t = 0 : i.name === "frontmatter" || i.name === "backmatter" || i.name === "part" ? t = o?.name === "book" && n ? 1 : 0 : _e.has(i.name) && (t += 1);
846
850
  }
847
851
  return t;
848
852
  }
849
- function Ae(e) {
850
- if (!De.has(e.name)) {
851
- e.children = e.children.filter(v);
853
+ function Le(e) {
854
+ if (!Me.has(e.name)) {
855
+ e.children = e.children.filter(g);
852
856
  for (const n of e.children)
853
- Ae(n);
857
+ Le(n);
854
858
  }
855
859
  }
856
860
  function V(e, n) {
857
861
  const t = [];
858
862
  for (const r of e.children)
859
- v(r) && (n.has(r) || jt.has(r.name) || De.has(r.name) ? t.push(r) : Re.has(r.name) && (V(r, n), t.push(r)));
863
+ g(r) && (n.has(r) || Ft.has(r.name) || Me.has(r.name) ? t.push(r) : De.has(r.name) && (V(r, n), t.push(r)));
860
864
  e.children = t;
861
865
  }
862
- function Nt(e) {
866
+ function Wt(e) {
863
867
  const n = /* @__PURE__ */ new Set(), t = (r) => {
864
868
  if (r.name === "xref") {
865
869
  const i = [
@@ -872,15 +876,15 @@ function Nt(e) {
872
876
  s && n.add(s);
873
877
  }
874
878
  for (const i of r.children)
875
- v(i) && t(i);
879
+ g(i) && t(i);
876
880
  };
877
881
  return t(e), n;
878
882
  }
879
- function Wt(e, n, t) {
883
+ function Ht(e, n, t) {
880
884
  const r = (i) => {
881
885
  for (const [o, s] of i.children.entries())
882
- if (v(s)) {
883
- if (Me(s) === n)
886
+ if (g(s)) {
887
+ if (Ae(s) === n)
884
888
  return i.children[o] = t, !0;
885
889
  if (r(s)) return !0;
886
890
  }
@@ -888,46 +892,46 @@ function Wt(e, n, t) {
888
892
  };
889
893
  return r(e);
890
894
  }
891
- function Ht(e, n) {
895
+ function Ut(e, n) {
892
896
  const t = U(e, n);
893
897
  if (!t) return;
894
898
  const r = M(e, t);
895
899
  if (!r) return;
896
900
  const i = r.filter(
897
- (u) => u.name !== "pretext" && u.name !== "mathbook"
901
+ (f) => f.name !== "pretext" && f.name !== "mathbook"
898
902
  ), o = i[0], s = o?.name === "book" && o.children.some(
899
- (u) => v(u) && u.name === "part"
900
- ), a = Ft(i, s), l = new Set(r), d = Nt(t), f = /* @__PURE__ */ new Set();
903
+ (f) => g(f) && f.name === "part"
904
+ ), c = Nt(i, s), a = new Set(r), d = Wt(t), u = /* @__PURE__ */ new Set();
901
905
  if (d.size > 0)
902
- for (const u of d) {
903
- const m = U(e, u);
906
+ for (const f of d) {
907
+ const m = U(e, f);
904
908
  if (!m || m === t) continue;
905
909
  const R = M(e, m);
906
910
  if (!R) continue;
907
- const g = [...R].reverse().find((w) => Re.has(w.name));
908
- if (g && g !== t) {
909
- f.add(g);
910
- for (const w of M(e, g) ?? [])
911
- l.add(w);
911
+ const b = [...R].reverse().find((v) => De.has(v.name));
912
+ if (b && b !== t) {
913
+ u.add(b);
914
+ for (const v of M(e, b) ?? [])
915
+ a.add(v);
912
916
  }
913
917
  }
914
- for (const u of r) {
915
- if (u === t) break;
916
- V(u, l);
918
+ for (const f of r) {
919
+ if (f === t) break;
920
+ V(f, a);
917
921
  }
918
- for (const u of f)
919
- Ae(u);
920
- const p = e.children.find(v);
921
- return p && !r.includes(p) && V(p, l), { content: $(e), divisionId: n, level: a };
922
+ for (const f of u)
923
+ Le(f);
924
+ const p = e.children.find(g);
925
+ return p && !r.includes(p) && V(p, a), { content: I(e), divisionId: n, level: c };
922
926
  }
923
- const Ut = "This live preview shows a single division, so links into the rest of the document do not work here.", Vt = /<a\b([^>]*)>/g, Xt = /\sid="([^"]*)"/g, C = /\shref="([^"]*)"/, zt = /\\href\{([^{}]*)\}/g, oe = /\stitle="([^"]*)"/;
924
- function Jt(e) {
927
+ const Vt = "This live preview shows a single division, so links into the rest of the document do not work here.", Xt = /<a\b([^>]*)>/g, zt = /\sid="([^"]*)"/g, j = /\shref="([^"]*)"/, Jt = /\\href\{([^{}]*)\}/g, oe = /\stitle="([^"]*)"/;
928
+ function Gt(e) {
925
929
  const n = /* @__PURE__ */ new Set();
926
- for (const t of e.matchAll(Xt))
930
+ for (const t of e.matchAll(zt))
927
931
  n.add(t[1]);
928
932
  return n;
929
933
  }
930
- function Gt(e) {
934
+ function Kt(e) {
931
935
  return e.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
932
936
  }
933
937
  function se(e, n) {
@@ -939,60 +943,60 @@ function se(e, n) {
939
943
  const r = e.slice(t + 1);
940
944
  return n.has(r) && r !== "" ? { kind: "same-page", id: r } : { kind: "off-page" };
941
945
  }
942
- function Kt(e, n = {}) {
943
- const t = n.offPageMessage ?? Ut, r = Jt(e);
944
- return e.replace(Vt, (o, s) => {
945
- const a = C.exec(s);
946
- if (!a) return o;
947
- const l = se(a[1], r);
948
- if (l.kind === "keep") return o;
949
- if (l.kind === "same-page")
950
- return `<a${s.replace(C, ` href="#${l.id}"`)}>`;
951
- const d = oe.exec(s), f = Gt(t), p = d ? `${d[1]} — ${f}` : f;
952
- return `<a${s.replace(C, "").replace(oe, "")} title="${p}" aria-disabled="true" style="cursor:default">`;
953
- }).replace(zt, (o, s) => {
954
- const a = se(s, r);
955
- return a.kind === "same-page" ? `\\href{#${a.id}}` : o;
946
+ function Yt(e, n = {}) {
947
+ const t = n.offPageMessage ?? Vt, r = Gt(e);
948
+ return e.replace(Xt, (o, s) => {
949
+ const c = j.exec(s);
950
+ if (!c) return o;
951
+ const a = se(c[1], r);
952
+ if (a.kind === "keep") return o;
953
+ if (a.kind === "same-page")
954
+ return `<a${s.replace(j, ` href="#${a.id}"`)}>`;
955
+ const d = oe.exec(s), u = Kt(t), p = d ? `${d[1]} — ${u}` : u;
956
+ return `<a${s.replace(j, "").replace(oe, "")} title="${p}" aria-disabled="true" style="cursor:default">`;
957
+ }).replace(Jt, (o, s) => {
958
+ const c = se(s, r);
959
+ return c.kind === "same-page" ? `\\href{#${c.id}}` : o;
956
960
  });
957
961
  }
958
- function Yt() {
959
- return fe(A(), "xsl");
960
- }
961
962
  function qt() {
962
- return "Suspending" in WebAssembly;
963
+ return pe(A(), "xsl");
963
964
  }
964
965
  function Zt() {
965
- if (!qt())
966
+ return "Suspending" in WebAssembly;
967
+ }
968
+ function Qt() {
969
+ if (!Zt())
966
970
  throw new Error(
967
971
  "WebAssembly JSPI is not enabled. Run Node with --experimental-wasm-jspi (or use the pretext-html CLI, which re-launches itself with the flag)."
968
972
  );
969
973
  }
970
- function k(e) {
974
+ function $(e) {
971
975
  return e.includes("'") ? e.includes('"') ? `concat(${e.split("'").map((t) => `'${t}'`).join(`, "'", `)})` : `"${e}"` : `'${e}'`;
972
976
  }
973
- function Qt(e) {
977
+ function en(e) {
974
978
  return e.replace(
975
979
  /from '\.\/(https:\/\/[^']+)'/g,
976
980
  (n, t) => `from '${t}'`
977
981
  );
978
982
  }
979
- const en = `https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@${he}/dist/`, tn = {
980
- "cli.version": he,
983
+ const tn = `https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@${me}/dist/`, nn = {
984
+ "cli.version": me,
981
985
  // Colon-delimited: pretext-runestone.xsl splits them with str:tokenize.
982
- "rs-js": Ye.join(":"),
983
- "rs-css": qe.join(":"),
984
- "rs-version": Ke
986
+ "rs-js": qe.join(":"),
987
+ "rs-css": Ze.join(":"),
988
+ "rs-version": Ye
985
989
  };
986
- function nn(e) {
990
+ function rn(e) {
987
991
  return e.replace(
988
992
  /(<link\b[^>]*\bhref=["'])_static\//gi,
989
- `$1${en}_static/`
993
+ `$1${tn}_static/`
990
994
  );
991
995
  }
992
- function rn(e) {
996
+ function on(e) {
993
997
  return e.slice(0, 65536).replace(/<\?[\s\S]*?\?>/g, " ").replace(/<!--[\s\S]*?-->/g, " ").replace(/<!DOCTYPE[^>]*>/gi, " ").match(/<\s*([A-Za-z][\w:-]*)/)?.[1];
994
998
  }
995
- async function ae(e) {
999
+ async function ce(e) {
996
1000
  const n = await P(e);
997
1001
  if (n === void 0)
998
1002
  throw new Error(
@@ -1000,12 +1004,12 @@ async function ae(e) {
1000
1004
  );
1001
1005
  return n;
1002
1006
  }
1003
- async function on(e, n) {
1007
+ async function sn(e, n) {
1004
1008
  const t = h(e), r = await P(t);
1005
1009
  if (r !== void 0)
1006
- return Mt(r, t, n);
1010
+ return At(r, t, n);
1007
1011
  }
1008
- function sn(e, n, t, r) {
1012
+ function cn(e, n, t, r) {
1009
1013
  const i = e.replace(/^\uFEFF/, "").replace(/<\?xml[\s\S]*?\?>/, "").replace(/<!DOCTYPE[^>]*>/i, ""), o = t === "slides" ? "slideshow" : n === "chapter" || n === "part" ? "book" : "article";
1010
1014
  return `<pretext>
1011
1015
  ${r?.trim() ? `${r.trim()}
@@ -1016,81 +1020,81 @@ ${i}
1016
1020
  </pretext>
1017
1021
  `;
1018
1022
  }
1019
- async function an(e, n, t) {
1020
- const r = y(e).children.find(
1021
- (d) => d.type === "element"
1022
- ), i = r?.attributes["xml:id"];
1023
- if (!r || !i) return;
1024
- const o = h(n), s = await P(o);
1025
- if (s === void 0) return;
1023
+ async function an(e, n, t, r) {
1024
+ const i = T(e).children.find(
1025
+ (u) => u.type === "element"
1026
+ ), o = i?.attributes["xml:id"];
1027
+ if (!i || !o) return;
1028
+ const s = h(n), c = r ?? await P(s);
1029
+ if (c === void 0) return;
1026
1030
  let a;
1027
1031
  try {
1028
- a = (await z(s, o, t)).tree;
1032
+ a = (await z(c, s, t)).tree;
1029
1033
  } catch {
1030
1034
  return;
1031
1035
  }
1032
- if (!Wt(a, i, r)) return;
1033
- const l = Ht(a, i);
1034
- if (l)
1035
- return { ...l, tree: a };
1036
+ if (!Ht(a, o, i)) return;
1037
+ const d = Ut(a, o);
1038
+ if (d)
1039
+ return { ...d, tree: a };
1036
1040
  }
1037
- let Le = !1;
1038
- function cn(e) {
1041
+ let Pe = !1;
1042
+ function ln(e) {
1039
1043
  return e instanceof Error && /\bAborted\(/.test(e.message);
1040
1044
  }
1041
- function ln(e) {
1045
+ function dn(e) {
1042
1046
  return e instanceof Error && /memory access|out of bounds/i.test(e.message);
1043
1047
  }
1044
- function dn() {
1045
- if (Le)
1048
+ function un() {
1049
+ if (Pe)
1046
1050
  throw new Error(
1047
1051
  "The WebAssembly renderer aborted earlier in this process and cannot be reused. Restart the process (or reload the page) to render again."
1048
1052
  );
1049
1053
  }
1050
- function ce(e) {
1051
- if (cn(e))
1052
- throw Le = !0, new Error(
1054
+ function ae(e) {
1055
+ if (ln(e))
1056
+ throw Pe = !0, new Error(
1053
1057
  "The WebAssembly renderer aborted and cannot be reused. Restart the process (or reload the page) to render again.",
1054
1058
  { cause: e }
1055
1059
  );
1056
- if (ln(e))
1060
+ if (dn(e))
1057
1061
  throw new Error(
1058
1062
  "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.",
1059
1063
  { cause: e }
1060
1064
  );
1061
1065
  }
1062
- let j;
1063
- async function Pe() {
1064
- return j || (j = (async () => {
1066
+ let C;
1067
+ async function Oe() {
1068
+ return C || (C = (async () => {
1065
1069
  const [e, n] = await Promise.all([
1066
1070
  import("@pretextbook/libxslt-wasm"),
1067
1071
  import("@pretextbook/libxslt-wasm/exslt")
1068
1072
  ]);
1069
1073
  return n.registerAll(), e;
1070
- })()), j;
1074
+ })()), C;
1071
1075
  }
1072
- const F = /* @__PURE__ */ new Map(), un = {
1076
+ const F = /* @__PURE__ */ new Map(), fn = {
1073
1077
  html: "preview-html.xsl",
1074
1078
  slides: "preview-revealjs.xsl"
1075
1079
  };
1076
- async function fn(e, n) {
1077
- const t = un[n], r = `${n}\0${e}`;
1080
+ async function pn(e, n) {
1081
+ const t = fn[n], r = `${n}\0${e}`;
1078
1082
  let i = F.get(r);
1079
1083
  return i || (i = (async () => {
1080
- const { XmlDocument: o, XsltStylesheet: s } = await Pe(), a = ge(e), l = await pe(A(), `/${t}`);
1081
- if (l === void 0)
1084
+ const { XmlDocument: o, XsltStylesheet: s } = await Oe(), c = be(e), a = await he(A(), `/${t}`);
1085
+ if (a === void 0)
1082
1086
  throw new Error(
1083
1087
  `Could not read ${t} from ${A()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
1084
1088
  );
1085
- const d = new TextDecoder().decode(l), f = await o.fromString(d, {
1086
- url: `${a}/${t}`,
1089
+ const d = new TextDecoder().decode(a), u = await o.fromString(d, {
1090
+ url: `${c}/${t}`,
1087
1091
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
1088
1092
  });
1089
- return s.fromXmlDocument(f);
1093
+ return s.fromXmlDocument(u);
1090
1094
  })(), F.set(r, i), i.catch(() => F.delete(r))), i;
1091
1095
  }
1092
1096
  let le = Promise.resolve();
1093
- function En(e) {
1097
+ function yn(e) {
1094
1098
  const n = le.then(
1095
1099
  () => de(e),
1096
1100
  () => de(e)
@@ -1099,10 +1103,10 @@ function En(e) {
1099
1103
  }), n;
1100
1104
  }
1101
1105
  async function de(e) {
1102
- Zt(), dn();
1103
- const { XmlDocument: n } = await Pe(), t = h(e.sourcePath), r = h(
1104
- e.projectDir ?? I(t)
1105
- ), i = e.sourceContent ?? await ae(t), o = B(r, t);
1106
+ Qt(), un();
1107
+ const { XmlDocument: n } = await Oe(), t = h(e.sourcePath), r = h(
1108
+ e.projectDir ?? E(t)
1109
+ ), i = e.sourceContent ?? await ce(t), o = B(r, t);
1106
1110
  if (o.startsWith(".."))
1107
1111
  throw new Error(
1108
1112
  `sourcePath (${t}) must live inside projectDir (${r})`
@@ -1110,126 +1114,127 @@ async function de(e) {
1110
1114
  const s = B(
1111
1115
  r,
1112
1116
  h(e.mainSourcePath ?? t)
1113
- ), a = s.startsWith("..") ? o : s, l = ge(r);
1117
+ ), c = s.startsWith("..") ? o : s, a = be(r);
1114
1118
  try {
1115
- let d, f = `${l}/__pretext-preview-publication.xml`;
1119
+ let d, u = `${a}/__pretext-preview-publication.xml`;
1116
1120
  if (e.publicationPath) {
1117
- const c = h(e.publicationPath);
1118
- d = await ae(c);
1119
- const b = B(r, c);
1120
- b.startsWith("..") || (f = `${l}/${b.split(N).join("/")}`);
1121
+ const l = h(e.publicationPath);
1122
+ d = await ce(l);
1123
+ const w = B(r, l);
1124
+ w.startsWith("..") || (u = `${a}/${w.split(N).join("/")}`);
1121
1125
  }
1122
- let p, u;
1126
+ let p, f;
1123
1127
  if (e.sourceMap) {
1124
- const c = await z(
1128
+ const l = await z(
1125
1129
  i,
1126
1130
  t,
1127
1131
  r
1128
1132
  );
1129
- p = c.tree, u = c.content;
1133
+ p = l.tree, f = l.content;
1130
1134
  } else
1131
- u = await _t(
1135
+ f = await Rt(
1132
1136
  i,
1133
1137
  t,
1134
1138
  r
1135
1139
  );
1136
- const m = e.target ?? Ot(u), R = await fn(e.xslDir ?? Yt(), m), g = pt(d, {
1140
+ const m = e.target ?? Bt(f), R = await pn(e.xslDir ?? qt(), m), b = ht(d, {
1137
1141
  cssTheme: e.cssTheme,
1138
1142
  revealTheme: e.revealTheme,
1139
1143
  target: m
1140
1144
  });
1141
- ct(f, g);
1142
- const w = ht(g), J = I(h(r, a)), G = w.external !== void 0 && w.generated !== void 0 ? {
1143
- external: h(J, w.external),
1144
- generated: h(J, w.generated)
1145
- } : void 0, D = rn(u);
1146
- let K = { parentId: "root", position: 1 }, T, Y = t;
1145
+ lt(u, b);
1146
+ const v = mt(b), J = E(h(r, c)), G = v.external !== void 0 && v.generated !== void 0 ? {
1147
+ external: h(J, v.external),
1148
+ generated: h(J, v.generated)
1149
+ } : void 0, D = on(f);
1150
+ let K = { parentId: "root", position: 1 }, S, Y = t;
1147
1151
  if (D !== "pretext" && D !== "mathbook") {
1148
1152
  if (!e.fragment)
1149
1153
  throw new Error(
1150
1154
  `The document root is <${D ?? "?"}>, not <pretext> — this looks like an xi:included fragment. Render the project's main source file instead, or pass the fragment option.`
1151
1155
  );
1152
- if (e.contextSourcePath) {
1153
- const c = await an(
1154
- u,
1155
- e.contextSourcePath,
1156
- r
1156
+ if (e.contextSourcePath || e.contextSourceContent) {
1157
+ const l = e.contextSourcePath ?? Be(E(t), "__pretext-preview-context.ptx"), w = await an(
1158
+ f,
1159
+ l,
1160
+ r,
1161
+ e.contextSourceContent
1157
1162
  );
1158
- c && (u = c.content, p = e.sourceMap ? c.tree : void 0, Y = h(e.contextSourcePath), T = { divisionId: c.divisionId, level: c.level });
1163
+ w && (f = w.content, p = e.sourceMap ? w.tree : void 0, Y = h(l), S = { divisionId: w.divisionId, level: w.level });
1159
1164
  }
1160
- if (!T) {
1161
- const c = e.docinfo ?? (e.docinfoSourcePath ? await on(e.docinfoSourcePath, r) : void 0);
1162
- u = sn(
1163
- u,
1165
+ if (!S) {
1166
+ const l = e.docinfo ?? (e.docinfoSourcePath ? await sn(e.docinfoSourcePath, r) : void 0);
1167
+ f = cn(
1168
+ f,
1164
1169
  D,
1165
1170
  m,
1166
- c
1167
- ), K = { parentId: c?.trim() ? "root-1-2" : "root-1-1", position: 2 };
1171
+ l
1172
+ ), K = { parentId: l?.trim() ? "root-1-2" : "root-1-1", position: 2 };
1168
1173
  }
1169
1174
  }
1170
- const q = p ? Pt(p, Y, K) : void 0, Z = await n.fromString(u, {
1171
- url: `${l}/${a.split(N).join("/")}`,
1175
+ const q = p ? Ot(p, Y, K) : void 0, Z = await n.fromString(f, {
1176
+ url: `${a}/${c.split(N).join("/")}`,
1172
1177
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
1173
- }), S = {
1174
- publisher: k(f)
1178
+ }), k = {
1179
+ publisher: $(u)
1175
1180
  };
1176
- for (const [c, b] of Object.entries(tn))
1177
- S[c] = k(b);
1178
- T && (S.subtree = k(T.divisionId), S["subtree-level"] = k(String(T.level)));
1179
- for (const [c, b] of Object.entries(e.stringParams ?? {}))
1180
- S[c] = k(b);
1181
+ for (const [l, w] of Object.entries(nn))
1182
+ k[l] = $(w);
1183
+ S && (k.subtree = $(S.divisionId), k["subtree-level"] = $(String(S.level)));
1184
+ for (const [l, w] of Object.entries(e.stringParams ?? {}))
1185
+ k[l] = $(w);
1181
1186
  let O;
1182
1187
  try {
1183
- O = await R.apply(Z, S);
1184
- } catch (c) {
1185
- throw ce(c), new Error(
1188
+ O = await R.apply(Z, k);
1189
+ } catch (l) {
1190
+ throw ae(l), new Error(
1186
1191
  "PreTeXt XSLT transform failed; see the PTX:ERROR/PTX:FATAL messages on stderr for details.",
1187
- { cause: c }
1192
+ { cause: l }
1188
1193
  );
1189
1194
  } finally {
1190
1195
  Z.delete();
1191
1196
  }
1192
1197
  try {
1193
- let c = Qt(O.toHtmlString());
1194
- return c = Kt(c, {
1198
+ let l = en(O.toHtmlString());
1199
+ return l = Yt(l, {
1195
1200
  ...e.offPageMessage !== void 0 ? { offPageMessage: e.offPageMessage } : {}
1196
- }), (e.openKnowls ?? !0) && (c = nt(c)), m === "slides" ? (c = nn(c), c = It(c, e.revealView ?? "scroll", {
1201
+ }), (e.openKnowls ?? !0) && (l = rt(l)), m === "slides" ? (l = rn(l), l = _t(l, e.revealView ?? "scroll", {
1197
1202
  zoom: e.revealZoom
1198
- })) : e.theme && (c = Ct(c, e.theme)), e.previewBanner && (c = Ve(c, e.previewBanner)), {
1199
- html: c,
1203
+ })) : e.theme && (l = Ct(l, e.theme)), e.previewBanner && (l = Xe(l, e.previewBanner)), {
1204
+ html: l,
1200
1205
  target: m,
1201
1206
  ...q ? { sourceMap: q } : {},
1202
1207
  ...G ? { assetDirs: G } : {}
1203
1208
  };
1204
- } catch (c) {
1205
- throw ce(c), c;
1209
+ } catch (l) {
1210
+ throw ae(l), l;
1206
1211
  } finally {
1207
1212
  O.delete();
1208
1213
  }
1209
1214
  } finally {
1210
- at(l);
1215
+ at(a);
1211
1216
  }
1212
1217
  }
1213
1218
  export {
1214
- Be as PREVIEW_BANNER_STORAGE_KEY,
1215
- $e as PREVIEW_THEME_MESSAGE,
1216
- Yt as defaultXslDir,
1217
- Ot as detectRenderTarget,
1218
- gn as findSourceMapEntry,
1219
- pt as forcePortablePublication,
1220
- Ve as injectPreviewBanner,
1221
- It as injectRevealBridge,
1219
+ je as PREVIEW_BANNER_STORAGE_KEY,
1220
+ Ie as PREVIEW_THEME_MESSAGE,
1221
+ qt as defaultXslDir,
1222
+ Bt as detectRenderTarget,
1223
+ bn as findSourceMapEntry,
1224
+ ht as forcePortablePublication,
1225
+ Xe as injectPreviewBanner,
1226
+ _t as injectRevealBridge,
1222
1227
  Ct as injectThemeBridge,
1223
- qt as isJspiAvailable,
1224
- bn as isPreviewTheme,
1225
- vn as isRevealView,
1226
- nt as openBornHiddenKnowls,
1227
- Ne as previewBannerScript,
1228
- xn as previewThemeMessage,
1229
- En as renderHtml,
1230
- yt as revealBridgeScript,
1231
- mn as setAssetsBase,
1232
- wn as setMountReader,
1233
- Bt as themeBridgeScript,
1234
- k as xpathStringLiteral
1228
+ Zt as isJspiAvailable,
1229
+ xn as isPreviewTheme,
1230
+ gn as isRevealView,
1231
+ rt as openBornHiddenKnowls,
1232
+ We as previewBannerScript,
1233
+ En as previewThemeMessage,
1234
+ yn as renderHtml,
1235
+ Tt as revealBridgeScript,
1236
+ wn as setAssetsBase,
1237
+ vn as setMountReader,
1238
+ jt as themeBridgeScript,
1239
+ $ as xpathStringLiteral
1235
1240
  };