@pretextbook/pretext-html 0.10.1 → 0.12.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,7 +1,7 @@
1
1
  import { fromXml as T } from "xast-util-from-xml";
2
2
  import { toXml as I } from "xast-util-to-xml";
3
- const N = "/";
4
- function ue(e) {
3
+ const W = "/";
4
+ function pe(e) {
5
5
  if (!e)
6
6
  return ".";
7
7
  const n = e.startsWith("/"), t = e.length > 1 && e.endsWith("/"), r = [];
@@ -25,12 +25,12 @@ function h(...e) {
25
25
  break;
26
26
  }
27
27
  n.startsWith("/") || (n = `/${n}`);
28
- const t = ue(n);
28
+ const t = pe(n);
29
29
  return t.length > 1 && t.endsWith("/") ? t.slice(0, -1) : t;
30
30
  }
31
- function Be(...e) {
31
+ function Ne(...e) {
32
32
  const n = e.filter(Boolean).join("/");
33
- return n ? ue(n) : ".";
33
+ return n ? pe(n) : ".";
34
34
  }
35
35
  function E(e) {
36
36
  const n = e.replace(/\/+$/, "");
@@ -39,28 +39,28 @@ function E(e) {
39
39
  const t = n.lastIndexOf("/");
40
40
  return t < 0 ? "." : t === 0 ? "/" : n.slice(0, t);
41
41
  }
42
- function B(e, n) {
42
+ function j(e, n) {
43
43
  const t = h(e).split("/").filter(Boolean), r = h(n).split("/").filter(Boolean);
44
44
  let i = 0;
45
45
  for (; i < t.length && i < r.length && t[i] === r[i]; )
46
46
  i += 1;
47
47
  return [...new Array(t.length - i).fill(".."), ...r.slice(i)].join("/");
48
48
  }
49
- const je = "ptxPreviewBannerDismissed", Ce = "About live preview";
50
- function Q(e) {
49
+ const Fe = "ptxPreviewBannerDismissed", We = "About live preview";
50
+ function te(e) {
51
51
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
52
52
  }
53
- function Fe(e) {
53
+ function Ue(e) {
54
54
  return [
55
55
  '<div id="ptx-preview-banner" class="ptx-preview-banner" role="note">',
56
- ` <span class="ptx-preview-banner-text">${Q(e)}</span>`,
56
+ ` <span class="ptx-preview-banner-text">${te(e)}</span>`,
57
57
  ' <button type="button" class="ptx-preview-banner-dismiss" aria-label="Dismiss">&times;</button>',
58
58
  "</div>",
59
- `<button type="button" id="ptx-preview-banner-restore" class="ptx-preview-banner-restore" hidden>${Q(Ce)}</button>`
59
+ `<button type="button" id="ptx-preview-banner-restore" class="ptx-preview-banner-restore" hidden>${te(We)}</button>`
60
60
  ].join(`
61
61
  `);
62
62
  }
63
- function Ne() {
63
+ function He() {
64
64
  return [
65
65
  "<style>",
66
66
  ".ptx-preview-banner {",
@@ -117,15 +117,23 @@ function Ne() {
117
117
  ".ptx-preview-banner-restore:hover {",
118
118
  " opacity: 0.85;",
119
119
  "}",
120
+ // Printing a preview is a real workflow — the print-preview layout exists
121
+ // to be printed from (see printout.ts) — and a warning about the preview
122
+ // has no business on the paper.
123
+ "@media print {",
124
+ " .ptx-preview-banner, .ptx-preview-banner-restore {",
125
+ " display: none !important;",
126
+ " }",
127
+ "}",
120
128
  "</style>"
121
129
  ].join(`
122
130
  `);
123
131
  }
124
- function We() {
132
+ function Ve() {
125
133
  return [
126
134
  "<script>",
127
135
  "(function () {",
128
- " var KEY = " + JSON.stringify(je) + ";",
136
+ " var KEY = " + JSON.stringify(Fe) + ";",
129
137
  ' var banner = document.getElementById("ptx-preview-banner");',
130
138
  ' var restore = document.getElementById("ptx-preview-banner-restore");',
131
139
  " if (!banner || !restore) { return; }",
@@ -162,39 +170,39 @@ function We() {
162
170
  ].join(`
163
171
  `);
164
172
  }
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;
173
+ const Xe = "<!--ptx-preview-banner-->", Je = "<!--/ptx-preview-banner-->", ze = /\n?<!--ptx-preview-banner-->[\s\S]*?<!--\/ptx-preview-banner-->/;
174
+ function Ke(e, n) {
175
+ const t = ze.exec(e), r = t ? e.slice(0, t.index) + e.slice(t.index + t[0].length) : e;
168
176
  if (!/<body[^>]*>/i.test(r))
169
177
  return r;
170
178
  const i = `
171
- ${He}
172
- ${Ne()}
173
- ${Fe(n.message)}
174
- ${We()}
175
- ${Ue}`;
179
+ ${Xe}
180
+ ${He()}
181
+ ${Ue(n.message)}
182
+ ${Ve()}
183
+ ${Je}`;
176
184
  return r.replace(/<body([^>]*)>/i, `<body$1>${i}`);
177
185
  }
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(/\/+$/, "");
186
+ const Ge = "https://cdn.jsdelivr.net/npm/@pretextbook/pretext-html@0.12.0/assets";
187
+ let he;
188
+ function Dn(e) {
189
+ he = e.replace(/\/+$/, "");
182
190
  }
183
- function A() {
184
- return fe ?? ze;
191
+ function M() {
192
+ return he ?? Ge;
185
193
  }
186
- function pe(e, n) {
194
+ function me(e, n) {
187
195
  return `${e.replace(/\/+$/, "")}/${n.replace(/^\/+/, "")}`;
188
196
  }
189
- const ee = /* @__PURE__ */ new Map();
190
- function Je(e) {
197
+ const ne = /* @__PURE__ */ new Map();
198
+ function Ye(e) {
191
199
  return `${e.replace(/\/+$/, "")}-bundle.json`;
192
200
  }
193
- function Ge(e) {
194
- let n = ee.get(e);
201
+ function qe(e) {
202
+ let n = ne.get(e);
195
203
  return n || (n = (async () => {
196
204
  try {
197
- const t = await fetch(Je(e));
205
+ const t = await fetch(Ye(e));
198
206
  if (!t.ok)
199
207
  return /* @__PURE__ */ new Map();
200
208
  const r = await t.json();
@@ -202,14 +210,14 @@ function Ge(e) {
202
210
  } catch {
203
211
  return /* @__PURE__ */ new Map();
204
212
  }
205
- })(), ee.set(e, n)), n;
213
+ })(), ne.set(e, n)), n;
206
214
  }
207
- function Ke(e) {
208
- return e === pe(A(), "xsl");
215
+ function Ze(e) {
216
+ return e === me(M(), "xsl");
209
217
  }
210
- async function he(e, n) {
211
- if (Ke(e)) {
212
- const o = (await Ge(e)).get(n.replace(/^\/+/, ""));
218
+ async function we(e, n) {
219
+ if (Ze(e)) {
220
+ const o = (await qe(e)).get(n.replace(/^\/+/, ""));
213
221
  if (o !== void 0)
214
222
  return new TextEncoder().encode(o);
215
223
  }
@@ -233,7 +241,7 @@ async function he(e, n) {
233
241
  return;
234
242
  }
235
243
  }
236
- async function P(e) {
244
+ async function B(e) {
237
245
  if (/^[a-z][a-z0-9+.-]*:\/\//i.test(e))
238
246
  try {
239
247
  const n = await fetch(e);
@@ -242,42 +250,42 @@ async function P(e) {
242
250
  return;
243
251
  }
244
252
  }
245
- const me = "2.49.1", Ye = "8.2.4", qe = [
253
+ const ve = "2.49.1", Qe = "8.2.4", et = [
246
254
  "prefix-runtime.40bd1420d3277749.bundle.js",
247
255
  "prefix-926.5c7038c8ef173faf.bundle.js",
248
256
  "prefix-runestone.b388362b5f43738a.bundle.js"
249
- ], Ze = [
257
+ ], tt = [
250
258
  "prefix-926.229729d09512acc9.css",
251
259
  "prefix-runestone.8086b62682b271d1.css"
252
- ], Qe = "born-hidden-knowl", et = /<details\b([^>]*)>(\s*)(?:<summary\b([^>]*)>)?/g;
253
- function tt(e) {
260
+ ], nt = "born-hidden-knowl", rt = /<details\b([^>]*)>(\s*)(?:<summary\b([^>]*)>)?/g;
261
+ function it(e) {
254
262
  const n = /\bclass="([^"]*)"/.exec(e);
255
263
  return n ? n[1].trim().split(/\s+/) : [];
256
264
  }
257
- function nt(e) {
265
+ function ot(e) {
258
266
  return /(^|\s)open(\s|=|$)/.test(e);
259
267
  }
260
- function te(e) {
261
- return nt(e) ? e : ` open${e}`;
268
+ function re(e) {
269
+ return ot(e) ? e : ` open${e}`;
262
270
  }
263
- function rt(e) {
271
+ function st(e) {
264
272
  return e.replace(
265
- et,
273
+ rt,
266
274
  (n, t, r, i) => {
267
- if (!tt(t).includes(Qe))
275
+ if (!it(t).includes(nt))
268
276
  return n;
269
- const o = `<details${te(t)}>`;
270
- return i === void 0 ? `${o}${r}` : `${o}${r}<summary${te(i)}>`;
277
+ const o = `<details${re(t)}>`;
278
+ return i === void 0 ? `${o}${r}` : `${o}${r}<summary${re(i)}>`;
271
279
  }
272
280
  );
273
281
  }
274
- const X = /* @__PURE__ */ new Map(), we = /* @__PURE__ */ new Map();
275
- let W, it = 0, ve = he;
276
- function vn(e) {
277
- ve = e;
282
+ const J = /* @__PURE__ */ new Map(), ge = /* @__PURE__ */ new Map();
283
+ let U, ct = 0, be = we;
284
+ function Ln(e) {
285
+ be = e;
278
286
  }
279
- function ot(e, n) {
280
- const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, r = we.get(t);
287
+ function at(e, n) {
288
+ const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, r = ge.get(t);
281
289
  if (r !== void 0)
282
290
  return Promise.resolve(new Response(r, { status: 200 }));
283
291
  let i;
@@ -286,41 +294,159 @@ function ot(e, n) {
286
294
  } catch {
287
295
  i = "";
288
296
  }
289
- const o = X.get(i);
290
- return o !== void 0 ? ct(o, t) : W(e, n);
297
+ const o = J.get(i);
298
+ return o !== void 0 ? dt(o, t) : U(e, n);
291
299
  }
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);
300
+ const lt = '<?xml version="1.0"?><pretext-preview-missing-file/>';
301
+ async function dt(e, n) {
302
+ const t = decodeURIComponent(new URL(n).pathname), r = await be(e, t);
295
303
  if (r === void 0)
296
- return new Response(st, { status: 200 });
304
+ return new Response(lt, { status: 200 });
297
305
  const i = typeof r == "string" ? r : new Uint8Array(r);
298
306
  return new Response(i, { status: 200 });
299
307
  }
300
- function ge() {
301
- W || (W = globalThis.fetch, globalThis.fetch = ot);
308
+ function xe() {
309
+ U || (U = globalThis.fetch, globalThis.fetch = at);
310
+ }
311
+ function Ee(e) {
312
+ xe();
313
+ const n = `mnt${++ct}.ptx.invalid`;
314
+ return J.set(n, e), `http://${n}`;
315
+ }
316
+ function ut(e) {
317
+ J.delete(new URL(e).host);
318
+ }
319
+ function ft(e, n) {
320
+ xe(), ge.set(e, n);
321
+ }
322
+ const pt = /<a\b[^>]*\bdata-printout="[^"]*"[^>]*>/gi;
323
+ function D(e, n) {
324
+ const t = new RegExp(`\\b${n}="([^"]*)"`, "i").exec(e);
325
+ return t ? ht(t[1]) : void 0;
326
+ }
327
+ function ht(e) {
328
+ return e.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&apos;|&#39;/g, "'").replace(/&#x27;/gi, "'").replace(/&amp;/g, "&");
329
+ }
330
+ function mt(e, n, t) {
331
+ const r = [e, n].filter(Boolean).join(" ");
332
+ return r && t ? `${r}: ${t}` : r || t;
333
+ }
334
+ function ye(e) {
335
+ const n = [], t = /* @__PURE__ */ new Set();
336
+ for (const [r] of e.matchAll(pt)) {
337
+ const i = D(r, "data-printout");
338
+ if (!i || t.has(i))
339
+ continue;
340
+ t.add(i);
341
+ const o = D(r, "data-printout-type") ?? "", s = D(r, "data-printout-number") ?? "", c = D(r, "data-printout-title") ?? "";
342
+ n.push({
343
+ id: i,
344
+ type: o,
345
+ number: s,
346
+ title: c,
347
+ label: mt(o, s, c)
348
+ });
349
+ }
350
+ return n;
351
+ }
352
+ const wt = /* @__PURE__ */ new Set([
353
+ "worksheet",
354
+ "handout",
355
+ "project",
356
+ "activity",
357
+ "exploration",
358
+ "investigation"
359
+ ]);
360
+ function vt(e, n) {
361
+ if (!(!n || !wt.has(n)))
362
+ return e[0]?.id;
302
363
  }
303
- function be(e) {
304
- ge();
305
- const n = `mnt${++it}.ptx.invalid`;
306
- return X.set(n, e), `http://${n}`;
364
+ const gt = "__ptxPrintPreview";
365
+ function bt(e) {
366
+ const n = JSON.stringify(e ?? null);
367
+ return [
368
+ "<script>",
369
+ "(function () {",
370
+ " var KEY = " + JSON.stringify(gt) + ";",
371
+ " window[KEY] = " + n + ";",
372
+ // Pin the page to light mode for the print layout; see printPreviewCss.
373
+ // `data-darkmode="disabled"` is upstream's own switch — pretext-core.js
374
+ // checks it in both isDarkMode and setDarkMode, the only two places that
375
+ // touch the class — and the theme bridge honours it too (theme.ts), so a
376
+ // later theme message from the embedder cannot undo this. Nothing removes
377
+ // the attribute again: leaving print preview delivers a new document,
378
+ // whose <html> carries whatever the render authored.
379
+ " if (window[KEY] && window.document.documentElement) {",
380
+ " var root = window.document.documentElement;",
381
+ " if (root.classList) { root.classList.remove('dark-mode'); }",
382
+ " root.setAttribute('data-darkmode', 'disabled');",
383
+ " }",
384
+ // The patch survives a document.write rebuild along with the Window, so
385
+ // installing it twice would stack wrappers; the id above is what changes.
386
+ " if (window.__ptxPrintPreviewPatched) { return; }",
387
+ " var Base = window.URLSearchParams;",
388
+ " if (!Base) { return; }",
389
+ " window.__ptxPrintPreviewPatched = true;",
390
+ " function Patched(init) {",
391
+ " var params = new Base(init === undefined || init === null ? '' : init);",
392
+ " var id = window[KEY];",
393
+ " if (id && typeof init === 'string' && init === window.location.search) {",
394
+ " params.set('printpreview', id);",
395
+ " }",
396
+ " return params;",
397
+ " }",
398
+ " Patched.prototype = Base.prototype;",
399
+ " window.URLSearchParams = Patched;",
400
+ "})();",
401
+ "<\/script>"
402
+ ].join(`
403
+ `);
307
404
  }
308
- function at(e) {
309
- X.delete(new URL(e).host);
405
+ function xt() {
406
+ return [
407
+ "<style>",
408
+ ":root {",
409
+ " color-scheme: light;",
410
+ "}",
411
+ // !important because the rule this has to beat is the *host's*, not the
412
+ // page's: VS Code injects a `body { background-color:
413
+ // var(--vscode-editor-background) }` of its own into every webview
414
+ // document, and where it injects it is not ours to rely on. The values
415
+ // still come from the print stylesheet's variables, so it stays in charge
416
+ // of what "paper" looks like.
417
+ "html, body {",
418
+ " background: var(--page-color, #fff) !important;",
419
+ " color: var(--body-text-color, #000) !important;",
420
+ "}",
421
+ "</style>"
422
+ ].join(`
423
+ `);
310
424
  }
311
- function lt(e, n) {
312
- ge(), we.set(e, n);
425
+ const Et = "<!--ptx-print-preview-->", yt = "<!--/ptx-print-preview-->", Tt = /\n?<!--ptx-print-preview-->[\s\S]*?<!--\/ptx-print-preview-->/;
426
+ function St(e, n) {
427
+ const t = Tt.exec(e), r = t ? e.slice(0, t.index) + e.slice(t.index + t[0].length) : e, i = /<head[^>]*>/i.exec(r);
428
+ if (!i)
429
+ return r;
430
+ const o = n && ye(r).some((a) => a.id === n) ? n : void 0, s = `
431
+ ${Et}
432
+ ${bt(o)}
433
+ ${o ? `${xt()}
434
+ ` : ""}${yt}`, c = i.index + i[0].length;
435
+ return r.slice(0, c) + s + r.slice(c);
313
436
  }
314
437
  const H = `<?xml version="1.0" encoding="UTF-8"?>
315
438
  <publication>
316
439
  <source>
317
440
  <directories external="../assets" generated="../generated-assets" />
318
441
  </source>
442
+ <common>
443
+ <tableofcontents level="0"/>
444
+ </common>
319
445
  <html>
320
446
  <platform portable="yes"/>
321
447
  </html>
322
448
  </publication>
323
- `, dt = ["theme", "style", "shell"];
449
+ `, $t = ["theme", "style", "shell"];
324
450
  function x(e, n) {
325
451
  for (const t of e.children)
326
452
  if (t.type === "element" && t.name === n)
@@ -330,21 +456,21 @@ function y(e, n) {
330
456
  let t = x(e, n);
331
457
  return t || (t = { type: "element", name: n, attributes: {}, children: [] }, e.children.push(t)), t;
332
458
  }
333
- function ut(e, n) {
459
+ function _t(e, n) {
334
460
  const t = x(e, "css");
335
- if (t && dt.some((i) => t.attributes?.[i]))
461
+ if (t && $t.some((i) => t.attributes?.[i]))
336
462
  return;
337
463
  const r = t ?? y(e, "css");
338
464
  r.attributes = { ...r.attributes, theme: n };
339
465
  }
340
- function ft(e, n) {
466
+ function kt(e, n) {
341
467
  const t = x(e, "appearance");
342
468
  if (t?.attributes?.theme)
343
469
  return;
344
470
  const r = t ?? y(e, "appearance");
345
471
  r.attributes = { ...r.attributes, theme: n };
346
472
  }
347
- function pt(e) {
473
+ function It(e) {
348
474
  const n = y(e, "resources");
349
475
  n.attributes = {
350
476
  ...n.attributes,
@@ -352,7 +478,7 @@ function pt(e) {
352
478
  math: "online"
353
479
  };
354
480
  }
355
- function ht(e, n = {}) {
481
+ function Rt(e, n = {}) {
356
482
  const t = n.cssTheme?.trim(), r = n.revealTheme?.trim(), i = n.target === "slides";
357
483
  if (!e && !t && !i)
358
484
  return H;
@@ -362,20 +488,20 @@ function ht(e, n = {}) {
362
488
  "Invalid publication file: no root <publication> element found"
363
489
  );
364
490
  const c = y(s, "html"), a = y(c, "platform");
365
- if (a.attributes = { ...a.attributes, portable: "yes" }, t && ut(c, t), i) {
491
+ if (a.attributes = { ...a.attributes, portable: "yes" }, t && _t(c, t), i) {
366
492
  const d = y(s, "revealjs");
367
- pt(d), r && ft(d, r);
493
+ It(d), r && kt(d, r);
368
494
  }
369
495
  return I(o);
370
496
  }
371
- function ne(e) {
497
+ function ie(e) {
372
498
  if (!(e === void 0 || e === "" || e.startsWith("/")))
373
499
  return e.endsWith("/") ? e : `${e}/`;
374
500
  }
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(
501
+ function Pt(e) {
502
+ const n = T(e ?? H), t = x(n, "publication"), r = t && x(t, "source"), i = r && x(r, "directories"), o = ie(
377
503
  i?.attributes?.external ?? void 0
378
- ), s = ne(
504
+ ), s = ie(
379
505
  i?.attributes?.generated ?? void 0
380
506
  );
381
507
  return {
@@ -384,18 +510,18 @@ function mt(e) {
384
510
  managed: o !== void 0 && s !== void 0
385
511
  };
386
512
  }
387
- function gn(e) {
513
+ function Mn(e) {
388
514
  return e === "slides" || e === "scroll";
389
515
  }
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));
516
+ const Te = 960, Se = 700, Dt = 1, Lt = 0.04;
517
+ function Mt(e) {
518
+ const n = typeof e == "number" && isFinite(e) ? e : Dt, t = Math.min(1, Math.max(0.25, n));
393
519
  return {
394
- width: Math.round(xe / t),
395
- height: Math.round(Ee / t)
520
+ width: Math.round(Te / t),
521
+ height: Math.round(Se / t)
396
522
  };
397
523
  }
398
- function bt(e) {
524
+ function At(e) {
399
525
  return {
400
526
  view: "scroll",
401
527
  scrollLayout: "compact",
@@ -405,11 +531,11 @@ function bt(e) {
405
531
  controls: !1,
406
532
  controlsTutorial: !1,
407
533
  hash: !1,
408
- ...gt(e.zoom),
409
- margin: vt
534
+ ...Mt(e.zoom),
535
+ margin: Lt
410
536
  };
411
537
  }
412
- function xt() {
538
+ function Bt() {
413
539
  return {
414
540
  // Explicitly null rather than absent: the same page may have been
415
541
  // delivered in scroll view a moment ago, and an embedder that re-injects
@@ -421,11 +547,11 @@ function xt() {
421
547
  // size with a percentage width renders its text far larger, relative to
422
548
  // the slide, than the same deck will on a projector. No zoom margin
423
549
  // though — presenting means filling whatever it is shown in.
424
- width: xe,
425
- height: Ee
550
+ width: Te,
551
+ height: Se
426
552
  };
427
553
  }
428
- const Et = [
554
+ const Ot = [
429
555
  "<style>",
430
556
  ".reveal-viewport.reveal-scroll .scroll-page section {",
431
557
  " box-shadow: inset 0 0 0 calc(1px / var(--slide-scale, 1))",
@@ -433,14 +559,14 @@ const Et = [
433
559
  "}",
434
560
  "</style>"
435
561
  ].join(`
436
- `), yt = [
562
+ `), jt = [
437
563
  " var paused = document.querySelectorAll('.reveal .fragment');",
438
564
  " for (var i = 0; i < paused.length; i++) {",
439
565
  " paused[i].classList.remove('fragment');",
440
566
  " }"
441
567
  ];
442
- function Tt(e, n = {}) {
443
- const t = e === "scroll" ? bt(n) : xt();
568
+ function Ct(e, n = {}) {
569
+ const t = e === "scroll" ? At(n) : Bt();
444
570
  return [
445
571
  "<script>",
446
572
  "(function () {",
@@ -468,7 +594,7 @@ function Tt(e, n = {}) {
468
594
  // Inside the wrapper rather than at top level: this script sits in <head>,
469
595
  // where the slides have not been parsed yet, but the deck calls initialize
470
596
  // from the end of the document, by which time they have.
471
- ...e === "scroll" ? yt : [],
597
+ ...e === "scroll" ? jt : [],
472
598
  " return initialize(merged);",
473
599
  " };",
474
600
  "})();",
@@ -476,27 +602,27 @@ function Tt(e, n = {}) {
476
602
  ].join(`
477
603
  `);
478
604
  }
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);
605
+ const Nt = /<script\b[^>]*\bsrc=["'][^"']*\breveal\.js["'][^>]*>\s*<\/script>/i, Ft = "<!--ptx-reveal-view-->", Wt = "<!--/ptx-reveal-view-->", Ut = /\n?<!--ptx-reveal-view-->[\s\S]*?<!--\/ptx-reveal-view-->/;
606
+ function Ht(e, n, t = {}) {
607
+ const r = Ut.exec(e), i = r ? e.slice(0, r.index) + e.slice(r.index + r[0].length) : e, o = Nt.exec(i);
482
608
  if (!o)
483
609
  return i;
484
610
  const s = o.index + o[0].length, c = `
485
- ${kt}
486
- ${Et}
487
- ${Tt(n, t)}
488
- ${$t}`;
611
+ ${Ft}
612
+ ${Ot}
613
+ ${Ct(n, t)}
614
+ ${Wt}`;
489
615
  return i.slice(0, s) + c + i.slice(s);
490
616
  }
491
- const ye = "http://www.w3.org/2001/XInclude", re = 64;
492
- async function Rt(e, n, t) {
617
+ const $e = "http://www.w3.org/2001/XInclude", oe = 64;
618
+ async function Vt(e, n, t) {
493
619
  return e.includes("include") ? (await z(e, n, t)).content : e;
494
620
  }
495
621
  async function z(e, n, t) {
496
622
  const r = T(e), i = {
497
623
  projectDir: h(t),
498
624
  stack: [h(n)]
499
- }, o = await _(
625
+ }, o = await R(
500
626
  r,
501
627
  E(h(n)),
502
628
  { "": "" },
@@ -504,43 +630,43 @@ async function z(e, n, t) {
504
630
  );
505
631
  return { tree: r, content: o ? I(r) : e };
506
632
  }
507
- function Dt(e) {
633
+ function Xt(e) {
508
634
  return e.data?.ptxIncludedFile;
509
635
  }
510
- function Mt(e, n) {
636
+ function Jt(e, n) {
511
637
  const t = e.data ?? (e.data = {});
512
638
  t.ptxIncludedFile = n;
513
639
  }
514
- function L(e, n) {
640
+ function A(e, n) {
515
641
  let t = e;
516
642
  for (const [r, i] of Object.entries(n.attributes))
517
643
  (r === "xmlns" || r.startsWith("xmlns:")) && (t === e && (t = { ...e }), t[r === "xmlns" ? "" : r.slice(6)] = i ?? "");
518
644
  return t;
519
645
  }
520
- function Te(e, n) {
646
+ function _e(e, n) {
521
647
  const t = e.name.indexOf(":"), r = t === -1 ? "" : e.name.slice(0, t);
522
- return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && n[r] === ye;
648
+ return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && n[r] === $e;
523
649
  }
524
- async function _(e, n, t, r) {
650
+ async function R(e, n, t, r) {
525
651
  let i = !1;
526
652
  for (let o = 0; o < e.children.length; o++) {
527
653
  const s = e.children[o];
528
654
  if (s.type !== "element")
529
655
  continue;
530
- const c = L(t, s);
531
- if (Te(s, c)) {
532
- const a = await Se(
656
+ const c = A(t, s);
657
+ if (_e(s, c)) {
658
+ const a = await ke(
533
659
  s,
534
660
  n,
535
661
  c,
536
662
  r
537
663
  );
538
664
  e.children.splice(o, 1, ...a), o += a.length - 1, i = !0;
539
- } else await _(s, n, c, r) && (i = !0);
665
+ } else await R(s, n, c, r) && (i = !0);
540
666
  }
541
667
  return i;
542
668
  }
543
- async function Se(e, n, t, r) {
669
+ async function ke(e, n, t, r) {
544
670
  const i = r.stack[r.stack.length - 1];
545
671
  if (e.attributes.xpointer)
546
672
  throw new Error(
@@ -555,7 +681,7 @@ async function Se(e, n, t, r) {
555
681
  } catch {
556
682
  }
557
683
  const c = h(n, s);
558
- if (c !== r.projectDir && !c.startsWith(r.projectDir + N))
684
+ if (c !== r.projectDir && !c.startsWith(r.projectDir + W))
559
685
  throw new Error(
560
686
  `xi:include escapes the project directory: ${o} (in ${i})`
561
687
  );
@@ -563,13 +689,13 @@ async function Se(e, n, t, r) {
563
689
  throw new Error(
564
690
  `Circular xi:include: ${[...r.stack, c].join(" -> ")}`
565
691
  );
566
- if (r.stack.length >= re)
567
- throw new Error(`xi:include nesting exceeds ${re} levels`);
568
- const a = await P(c);
692
+ if (r.stack.length >= oe)
693
+ throw new Error(`xi:include nesting exceeds ${oe} levels`);
694
+ const a = await B(c);
569
695
  if (a === void 0) {
570
- const p = Lt(e, t);
696
+ const p = Kt(e, t);
571
697
  if (p)
572
- return await _(p, n, t, r), p.children;
698
+ return await R(p, n, t, r), p.children;
573
699
  throw new Error(`xi:include target not found: ${o} (in ${i})`);
574
700
  }
575
701
  if (e.attributes.parse === "text")
@@ -584,7 +710,7 @@ async function Se(e, n, t, r) {
584
710
  }
585
711
  r.stack.push(c);
586
712
  try {
587
- await _(d, E(c), { "": "" }, r);
713
+ await R(d, E(c), { "": "" }, r);
588
714
  } finally {
589
715
  r.stack.pop();
590
716
  }
@@ -592,13 +718,13 @@ async function Se(e, n, t, r) {
592
718
  (p) => p.type === "element"
593
719
  );
594
720
  for (const p of u)
595
- Mt(p, c);
721
+ Jt(p, c);
596
722
  return u;
597
723
  }
598
- function ie(e) {
724
+ function se(e) {
599
725
  return e.name === "docinfo";
600
726
  }
601
- async function At(e, n, t) {
727
+ async function zt(e, n, t) {
602
728
  try {
603
729
  const i = T(e).children.find(
604
730
  (d) => d.type === "element"
@@ -608,21 +734,21 @@ async function At(e, n, t) {
608
734
  const o = h(n), s = E(o), c = {
609
735
  projectDir: h(t),
610
736
  stack: [o]
611
- }, a = L({ "": "" }, i);
737
+ }, a = A({ "": "" }, i);
612
738
  for (const d of i.children) {
613
739
  if (d.type !== "element")
614
740
  continue;
615
- const u = L(a, d);
616
- if (ie(d))
617
- return await _(d, s, u, c), I(d);
618
- if (Te(d, u)) {
619
- const f = (await Se(
741
+ const u = A(a, d);
742
+ if (se(d))
743
+ return await R(d, s, u, c), I(d);
744
+ if (_e(d, u)) {
745
+ const f = (await ke(
620
746
  d,
621
747
  s,
622
748
  u,
623
749
  c
624
750
  )).find(
625
- (m) => m.type === "element" && ie(m)
751
+ (w) => w.type === "element" && se(w)
626
752
  );
627
753
  if (f)
628
754
  return I(f);
@@ -635,33 +761,33 @@ async function At(e, n, t) {
635
761
  return;
636
762
  }
637
763
  }
638
- function Lt(e, n) {
764
+ function Kt(e, n) {
639
765
  for (const t of e.children) {
640
766
  if (t.type !== "element")
641
767
  continue;
642
- const r = L(n, t), i = t.name.indexOf(":"), o = i === -1 ? "" : t.name.slice(0, i);
643
- if ((i === -1 ? t.name : t.name.slice(i + 1)) === "fallback" && r[o] === ye)
768
+ const r = A(n, t), i = t.name.indexOf(":"), o = i === -1 ? "" : t.name.slice(0, i);
769
+ if ((i === -1 ? t.name : t.name.slice(i + 1)) === "fallback" && r[o] === $e)
644
770
  return t;
645
771
  }
646
772
  }
647
- function ke(e) {
773
+ function Ie(e) {
648
774
  return typeof e == "object" && e !== null && e.type === "element";
649
775
  }
650
- function Pt(e) {
776
+ function Gt(e) {
651
777
  return /^(pf|xhtml):/.test(e.name);
652
778
  }
653
- function Ot(e, n, t) {
654
- const r = [], i = e.children.find(ke);
779
+ function Yt(e, n, t) {
780
+ const r = [], i = e.children.find(Ie);
655
781
  if (i) {
656
782
  const o = t?.parentId ?? "root";
657
- $e(i, o, t?.position ?? 1, n, o, r);
783
+ Re(i, o, t?.position ?? 1, n, o, r);
658
784
  }
659
785
  return r;
660
786
  }
661
- function $e(e, n, t, r, i, o) {
662
- const s = Dt(e) ?? r;
787
+ function Re(e, n, t, r, i, o) {
788
+ const s = Xt(e) ?? r;
663
789
  let c, a;
664
- if (Pt(e))
790
+ if (Gt(e))
665
791
  a = "root";
666
792
  else {
667
793
  const u = e.attributes.label ?? e.attributes["xml:id"];
@@ -676,7 +802,7 @@ function $e(e, n, t, r, i, o) {
676
802
  }
677
803
  let d = 0;
678
804
  for (const u of e.children)
679
- ke(u) && (d += 1, $e(
805
+ Ie(u) && (d += 1, Re(
680
806
  u,
681
807
  a,
682
808
  d,
@@ -685,28 +811,28 @@ function $e(e, n, t, r, i, o) {
685
811
  o
686
812
  ));
687
813
  }
688
- function bn(e, n) {
814
+ function An(e, n) {
689
815
  let t;
690
816
  for (const r of e)
691
817
  r.line <= n && (t = r);
692
818
  return t ?? e[0];
693
819
  }
694
- function Bt(e) {
820
+ function qt(e) {
695
821
  const n = e.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!\[CDATA\[[\s\S]*?\]\]>/g, " ");
696
822
  return /<\s*slide(?:show)?[\s/>]/.test(n) ? "slides" : "html";
697
823
  }
698
- const Ie = "pretext-html:set-theme";
699
- function xn(e) {
824
+ const Pe = "pretext-html:set-theme";
825
+ function Bn(e) {
700
826
  return e === "dark" || e === "light" || e === "system";
701
827
  }
702
- function En(e) {
703
- return { type: Ie, theme: e };
828
+ function On(e) {
829
+ return { type: Pe, theme: e };
704
830
  }
705
- function jt(e) {
831
+ function Zt(e) {
706
832
  return [
707
833
  "<script>",
708
834
  "(function () {",
709
- " var CFG = " + JSON.stringify({ msg: Ie, initial: e }) + ";",
835
+ " var CFG = " + JSON.stringify({ msg: Pe, initial: e }) + ";",
710
836
  // Where the last requested theme is remembered so it survives an in-place
711
837
  // document rewrite (same Window) and outranks the baked initial value.
712
838
  " var KEY = '__ptxPreviewTheme';",
@@ -776,12 +902,12 @@ function jt(e) {
776
902
  ].join(`
777
903
  `);
778
904
  }
779
- function Ct(e, n) {
780
- const t = jt(n);
905
+ function Qt(e, n) {
906
+ const t = Zt(n);
781
907
  return /<head[^>]*>/i.test(e) ? e.replace(/<head([^>]*)>/i, `<head$1>
782
908
  ${t}`) : e;
783
909
  }
784
- const _e = /* @__PURE__ */ new Set([
910
+ const De = /* @__PURE__ */ new Set([
785
911
  "colophon",
786
912
  "biography",
787
913
  "dedication",
@@ -801,19 +927,19 @@ const _e = /* @__PURE__ */ new Set([
801
927
  "glossary",
802
928
  "worksheet",
803
929
  "handout"
804
- ]), Re = /* @__PURE__ */ new Set([
930
+ ]), Le = /* @__PURE__ */ new Set([
805
931
  "book",
806
932
  "article",
807
933
  "slideshow",
808
934
  "letter",
809
935
  "memo"
810
- ]), De = /* @__PURE__ */ new Set([
811
- ...Re,
812
- ..._e,
936
+ ]), Me = /* @__PURE__ */ new Set([
937
+ ...Le,
938
+ ...De,
813
939
  "part",
814
940
  "frontmatter",
815
941
  "backmatter"
816
- ]), Ft = /* @__PURE__ */ new Set(["docinfo"]), Me = /* @__PURE__ */ new Set([
942
+ ]), en = /* @__PURE__ */ new Set(["docinfo"]), Ae = /* @__PURE__ */ new Set([
817
943
  "title",
818
944
  "shorttitle",
819
945
  "plaintitle",
@@ -823,47 +949,47 @@ const _e = /* @__PURE__ */ new Set([
823
949
  function g(e) {
824
950
  return e.type === "element";
825
951
  }
826
- function Ae(e) {
952
+ function Be(e) {
827
953
  return e.attributes["xml:id"] ?? void 0;
828
954
  }
829
- function U(e, n) {
955
+ function V(e, n) {
830
956
  for (const t of e.children) {
831
957
  if (!g(t)) continue;
832
- if (Ae(t) === n) return t;
833
- const r = U(t, n);
958
+ if (Be(t) === n) return t;
959
+ const r = V(t, n);
834
960
  if (r) return r;
835
961
  }
836
962
  }
837
- function M(e, n) {
963
+ function L(e, n) {
838
964
  for (const t of e.children) {
839
965
  if (!g(t)) continue;
840
966
  if (t === n) return [t];
841
- const r = M(t, n);
967
+ const r = L(t, n);
842
968
  if (r) return [t, ...r];
843
969
  }
844
970
  }
845
- function Nt(e, n) {
971
+ function tn(e, n) {
846
972
  let t = 0;
847
973
  for (const [r, i] of e.entries()) {
848
974
  const o = r === 0 ? void 0 : e[r - 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);
975
+ Le.has(i.name) ? t = 0 : i.name === "frontmatter" || i.name === "backmatter" || i.name === "part" ? t = o?.name === "book" && n ? 1 : 0 : De.has(i.name) && (t += 1);
850
976
  }
851
977
  return t;
852
978
  }
853
- function Le(e) {
854
- if (!Me.has(e.name)) {
979
+ function Oe(e) {
980
+ if (!Ae.has(e.name)) {
855
981
  e.children = e.children.filter(g);
856
982
  for (const n of e.children)
857
- Le(n);
983
+ Oe(n);
858
984
  }
859
985
  }
860
- function V(e, n) {
986
+ function X(e, n) {
861
987
  const t = [];
862
988
  for (const r of e.children)
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)));
989
+ g(r) && (n.has(r) || en.has(r.name) || Ae.has(r.name) ? t.push(r) : Me.has(r.name) && (X(r, n), t.push(r)));
864
990
  e.children = t;
865
991
  }
866
- function Wt(e) {
992
+ function nn(e) {
867
993
  const n = /* @__PURE__ */ new Set(), t = (r) => {
868
994
  if (r.name === "xref") {
869
995
  const i = [
@@ -880,11 +1006,11 @@ function Wt(e) {
880
1006
  };
881
1007
  return t(e), n;
882
1008
  }
883
- function Ht(e, n, t) {
1009
+ function rn(e, n, t) {
884
1010
  const r = (i) => {
885
1011
  for (const [o, s] of i.children.entries())
886
1012
  if (g(s)) {
887
- if (Ae(s) === n)
1013
+ if (Be(s) === n)
888
1014
  return i.children[o] = t, !0;
889
1015
  if (r(s)) return !0;
890
1016
  }
@@ -892,49 +1018,49 @@ function Ht(e, n, t) {
892
1018
  };
893
1019
  return r(e);
894
1020
  }
895
- function Ut(e, n) {
896
- const t = U(e, n);
1021
+ function on(e, n) {
1022
+ const t = V(e, n);
897
1023
  if (!t) return;
898
- const r = M(e, t);
1024
+ const r = L(e, t);
899
1025
  if (!r) return;
900
1026
  const i = r.filter(
901
1027
  (f) => f.name !== "pretext" && f.name !== "mathbook"
902
1028
  ), o = i[0], s = o?.name === "book" && o.children.some(
903
1029
  (f) => g(f) && f.name === "part"
904
- ), c = Nt(i, s), a = new Set(r), d = Wt(t), u = /* @__PURE__ */ new Set();
1030
+ ), c = tn(i, s), a = new Set(r), d = nn(t), u = /* @__PURE__ */ new Set();
905
1031
  if (d.size > 0)
906
1032
  for (const f of d) {
907
- const m = U(e, f);
908
- if (!m || m === t) continue;
909
- const R = M(e, m);
910
- if (!R) continue;
911
- const b = [...R].reverse().find((v) => De.has(v.name));
1033
+ const w = V(e, f);
1034
+ if (!w || w === t) continue;
1035
+ const P = L(e, w);
1036
+ if (!P) continue;
1037
+ const b = [...P].reverse().find((v) => Me.has(v.name));
912
1038
  if (b && b !== t) {
913
1039
  u.add(b);
914
- for (const v of M(e, b) ?? [])
1040
+ for (const v of L(e, b) ?? [])
915
1041
  a.add(v);
916
1042
  }
917
1043
  }
918
1044
  for (const f of r) {
919
1045
  if (f === t) break;
920
- V(f, a);
1046
+ X(f, a);
921
1047
  }
922
1048
  for (const f of u)
923
- Le(f);
1049
+ Oe(f);
924
1050
  const p = e.children.find(g);
925
- return p && !r.includes(p) && V(p, a), { content: I(e), divisionId: n, level: c };
1051
+ return p && !r.includes(p) && X(p, a), { content: I(e), divisionId: n, level: c };
926
1052
  }
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) {
1053
+ const sn = "This live preview shows a single division, so links into the rest of the document do not work here.", cn = /<a\b([^>]*)>/g, an = /\sid="([^"]*)"/g, C = /\shref="([^"]*)"/, ln = /\\href\{([^{}]*)\}/g, ce = /\stitle="([^"]*)"/;
1054
+ function dn(e) {
929
1055
  const n = /* @__PURE__ */ new Set();
930
- for (const t of e.matchAll(zt))
1056
+ for (const t of e.matchAll(an))
931
1057
  n.add(t[1]);
932
1058
  return n;
933
1059
  }
934
- function Kt(e) {
1060
+ function un(e) {
935
1061
  return e.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
936
1062
  }
937
- function se(e, n) {
1063
+ function ae(e, n) {
938
1064
  if (e.startsWith("#") || e === "") return { kind: "keep" };
939
1065
  if (/^[a-z][a-z0-9+.-]*:/i.test(e) || e.startsWith("//"))
940
1066
  return { kind: "keep" };
@@ -943,73 +1069,73 @@ function se(e, n) {
943
1069
  const r = e.slice(t + 1);
944
1070
  return n.has(r) && r !== "" ? { kind: "same-page", id: r } : { kind: "off-page" };
945
1071
  }
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);
1072
+ function fn(e, n = {}) {
1073
+ const t = n.offPageMessage ?? sn, r = dn(e);
1074
+ return e.replace(cn, (o, s) => {
1075
+ const c = C.exec(s);
950
1076
  if (!c) return o;
951
- const a = se(c[1], r);
1077
+ const a = ae(c[1], r);
952
1078
  if (a.kind === "keep") return o;
953
1079
  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);
1080
+ return `<a${s.replace(C, ` href="#${a.id}"`)}>`;
1081
+ const d = ce.exec(s), u = un(t), p = d ? `${d[1]} — ${u}` : u;
1082
+ return `<a${s.replace(C, "").replace(ce, "")} title="${p}" aria-disabled="true" style="cursor:default">`;
1083
+ }).replace(ln, (o, s) => {
1084
+ const c = ae(s, r);
959
1085
  return c.kind === "same-page" ? `\\href{#${c.id}}` : o;
960
1086
  });
961
1087
  }
962
- function qt() {
963
- return pe(A(), "xsl");
1088
+ function pn() {
1089
+ return me(M(), "xsl");
964
1090
  }
965
- function Zt() {
1091
+ function hn() {
966
1092
  return "Suspending" in WebAssembly;
967
1093
  }
968
- function Qt() {
969
- if (!Zt())
1094
+ function mn() {
1095
+ if (!hn())
970
1096
  throw new Error(
971
1097
  "WebAssembly JSPI is not enabled. Run Node with --experimental-wasm-jspi (or use the pretext-html CLI, which re-launches itself with the flag)."
972
1098
  );
973
1099
  }
974
- function $(e) {
1100
+ function k(e) {
975
1101
  return e.includes("'") ? e.includes('"') ? `concat(${e.split("'").map((t) => `'${t}'`).join(`, "'", `)})` : `"${e}"` : `'${e}'`;
976
1102
  }
977
- function en(e) {
1103
+ function wn(e) {
978
1104
  return e.replace(
979
1105
  /from '\.\/(https:\/\/[^']+)'/g,
980
1106
  (n, t) => `from '${t}'`
981
1107
  );
982
1108
  }
983
- const tn = `https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@${me}/dist/`, nn = {
984
- "cli.version": me,
1109
+ const vn = `https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@${ve}/dist/`, gn = {
1110
+ "cli.version": ve,
985
1111
  // Colon-delimited: pretext-runestone.xsl splits them with str:tokenize.
986
- "rs-js": qe.join(":"),
987
- "rs-css": Ze.join(":"),
988
- "rs-version": Ye
1112
+ "rs-js": et.join(":"),
1113
+ "rs-css": tt.join(":"),
1114
+ "rs-version": Qe
989
1115
  };
990
- function rn(e) {
1116
+ function bn(e) {
991
1117
  return e.replace(
992
1118
  /(<link\b[^>]*\bhref=["'])_static\//gi,
993
- `$1${tn}_static/`
1119
+ `$1${vn}_static/`
994
1120
  );
995
1121
  }
996
- function on(e) {
1122
+ function xn(e) {
997
1123
  return e.slice(0, 65536).replace(/<\?[\s\S]*?\?>/g, " ").replace(/<!--[\s\S]*?-->/g, " ").replace(/<!DOCTYPE[^>]*>/gi, " ").match(/<\s*([A-Za-z][\w:-]*)/)?.[1];
998
1124
  }
999
- async function ce(e) {
1000
- const n = await P(e);
1125
+ async function le(e) {
1126
+ const n = await B(e);
1001
1127
  if (n === void 0)
1002
1128
  throw new Error(
1003
1129
  `Could not read ${e}. (In the browser build only absolute URLs are readable — pass sourceContent instead of relying on sourcePath.)`
1004
1130
  );
1005
1131
  return n;
1006
1132
  }
1007
- async function sn(e, n) {
1008
- const t = h(e), r = await P(t);
1133
+ async function En(e, n) {
1134
+ const t = h(e), r = await B(t);
1009
1135
  if (r !== void 0)
1010
- return At(r, t, n);
1136
+ return zt(r, t, n);
1011
1137
  }
1012
- function cn(e, n, t, r) {
1138
+ function yn(e, n, t, r) {
1013
1139
  const i = e.replace(/^\uFEFF/, "").replace(/<\?xml[\s\S]*?\?>/, "").replace(/<!DOCTYPE[^>]*>/i, ""), o = t === "slides" ? "slideshow" : n === "chapter" || n === "part" ? "book" : "article";
1014
1140
  return `<pretext>
1015
1141
  ${r?.trim() ? `${r.trim()}
@@ -1020,12 +1146,12 @@ ${i}
1020
1146
  </pretext>
1021
1147
  `;
1022
1148
  }
1023
- async function an(e, n, t, r) {
1149
+ async function Tn(e, n, t, r) {
1024
1150
  const i = T(e).children.find(
1025
1151
  (u) => u.type === "element"
1026
1152
  ), o = i?.attributes["xml:id"];
1027
1153
  if (!i || !o) return;
1028
- const s = h(n), c = r ?? await P(s);
1154
+ const s = h(n), c = r ?? await B(s);
1029
1155
  if (c === void 0) return;
1030
1156
  let a;
1031
1157
  try {
@@ -1033,58 +1159,58 @@ async function an(e, n, t, r) {
1033
1159
  } catch {
1034
1160
  return;
1035
1161
  }
1036
- if (!Ht(a, o, i)) return;
1037
- const d = Ut(a, o);
1162
+ if (!rn(a, o, i)) return;
1163
+ const d = on(a, o);
1038
1164
  if (d)
1039
1165
  return { ...d, tree: a };
1040
1166
  }
1041
- let Pe = !1;
1042
- function ln(e) {
1167
+ let je = !1;
1168
+ function Sn(e) {
1043
1169
  return e instanceof Error && /\bAborted\(/.test(e.message);
1044
1170
  }
1045
- function dn(e) {
1171
+ function $n(e) {
1046
1172
  return e instanceof Error && /memory access|out of bounds/i.test(e.message);
1047
1173
  }
1048
- function un() {
1049
- if (Pe)
1174
+ function _n() {
1175
+ if (je)
1050
1176
  throw new Error(
1051
1177
  "The WebAssembly renderer aborted earlier in this process and cannot be reused. Restart the process (or reload the page) to render again."
1052
1178
  );
1053
1179
  }
1054
- function ae(e) {
1055
- if (ln(e))
1056
- throw Pe = !0, new Error(
1180
+ function de(e) {
1181
+ if (Sn(e))
1182
+ throw je = !0, new Error(
1057
1183
  "The WebAssembly renderer aborted and cannot be reused. Restart the process (or reload the page) to render again.",
1058
1184
  { cause: e }
1059
1185
  );
1060
- if (dn(e))
1186
+ if ($n(e))
1061
1187
  throw new Error(
1062
1188
  "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.",
1063
1189
  { cause: e }
1064
1190
  );
1065
1191
  }
1066
- let C;
1067
- async function Oe() {
1068
- return C || (C = (async () => {
1192
+ let N;
1193
+ async function Ce() {
1194
+ return N || (N = (async () => {
1069
1195
  const [e, n] = await Promise.all([
1070
1196
  import("@pretextbook/libxslt-wasm"),
1071
1197
  import("@pretextbook/libxslt-wasm/exslt")
1072
1198
  ]);
1073
1199
  return n.registerAll(), e;
1074
- })()), C;
1200
+ })()), N;
1075
1201
  }
1076
- const F = /* @__PURE__ */ new Map(), fn = {
1202
+ const F = /* @__PURE__ */ new Map(), kn = {
1077
1203
  html: "preview-html.xsl",
1078
1204
  slides: "preview-revealjs.xsl"
1079
1205
  };
1080
- async function pn(e, n) {
1081
- const t = fn[n], r = `${n}\0${e}`;
1206
+ async function In(e, n) {
1207
+ const t = kn[n], r = `${n}\0${e}`;
1082
1208
  let i = F.get(r);
1083
1209
  return i || (i = (async () => {
1084
- const { XmlDocument: o, XsltStylesheet: s } = await Oe(), c = be(e), a = await he(A(), `/${t}`);
1210
+ const { XmlDocument: o, XsltStylesheet: s } = await Ce(), c = Ee(e), a = await we(M(), `/${t}`);
1085
1211
  if (a === void 0)
1086
1212
  throw new Error(
1087
- `Could not read ${t} from ${A()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
1213
+ `Could not read ${t} from ${M()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
1088
1214
  );
1089
1215
  const d = new TextDecoder().decode(a), u = await o.fromString(d, {
1090
1216
  url: `${c}/${t}`,
@@ -1093,35 +1219,35 @@ async function pn(e, n) {
1093
1219
  return s.fromXmlDocument(u);
1094
1220
  })(), F.set(r, i), i.catch(() => F.delete(r))), i;
1095
1221
  }
1096
- let le = Promise.resolve();
1097
- function yn(e) {
1098
- const n = le.then(
1099
- () => de(e),
1100
- () => de(e)
1222
+ let ue = Promise.resolve();
1223
+ function jn(e) {
1224
+ const n = ue.then(
1225
+ () => fe(e),
1226
+ () => fe(e)
1101
1227
  );
1102
- return le = n.catch(() => {
1228
+ return ue = n.catch(() => {
1103
1229
  }), n;
1104
1230
  }
1105
- async function de(e) {
1106
- Qt(), un();
1107
- const { XmlDocument: n } = await Oe(), t = h(e.sourcePath), r = h(
1231
+ async function fe(e) {
1232
+ mn(), _n();
1233
+ const { XmlDocument: n } = await Ce(), t = h(e.sourcePath), r = h(
1108
1234
  e.projectDir ?? E(t)
1109
- ), i = e.sourceContent ?? await ce(t), o = B(r, t);
1235
+ ), i = e.sourceContent ?? await le(t), o = j(r, t);
1110
1236
  if (o.startsWith(".."))
1111
1237
  throw new Error(
1112
1238
  `sourcePath (${t}) must live inside projectDir (${r})`
1113
1239
  );
1114
- const s = B(
1240
+ const s = j(
1115
1241
  r,
1116
1242
  h(e.mainSourcePath ?? t)
1117
- ), c = s.startsWith("..") ? o : s, a = be(r);
1243
+ ), c = s.startsWith("..") ? o : s, a = Ee(r);
1118
1244
  try {
1119
1245
  let d, u = `${a}/__pretext-preview-publication.xml`;
1120
1246
  if (e.publicationPath) {
1121
1247
  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("/")}`);
1248
+ d = await le(l);
1249
+ const m = j(r, l);
1250
+ m.startsWith("..") || (u = `${a}/${m.split(W).join("/")}`);
1125
1251
  }
1126
1252
  let p, f;
1127
1253
  if (e.sourceMap) {
@@ -1132,109 +1258,118 @@ async function de(e) {
1132
1258
  );
1133
1259
  p = l.tree, f = l.content;
1134
1260
  } else
1135
- f = await Rt(
1261
+ f = await Vt(
1136
1262
  i,
1137
1263
  t,
1138
1264
  r
1139
1265
  );
1140
- const m = e.target ?? Bt(f), R = await pn(e.xslDir ?? qt(), m), b = ht(d, {
1266
+ const w = e.target ?? qt(f), P = await In(e.xslDir ?? pn(), w), b = Rt(d, {
1141
1267
  cssTheme: e.cssTheme,
1142
1268
  revealTheme: e.revealTheme,
1143
- target: m
1269
+ target: w
1144
1270
  });
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;
1151
- if (D !== "pretext" && D !== "mathbook") {
1271
+ ft(u, b);
1272
+ const v = Pt(b), K = E(h(r, c)), G = v.external !== void 0 && v.generated !== void 0 ? {
1273
+ external: h(K, v.external),
1274
+ generated: h(K, v.generated)
1275
+ } : void 0, S = xn(f);
1276
+ let Y = { parentId: "root", position: 1 }, $, q = t;
1277
+ if (S !== "pretext" && S !== "mathbook") {
1152
1278
  if (!e.fragment)
1153
1279
  throw new Error(
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.`
1280
+ `The document root is <${S ?? "?"}>, not <pretext> — this looks like an xi:included fragment. Render the project's main source file instead, or pass the fragment option.`
1155
1281
  );
1156
1282
  if (e.contextSourcePath || e.contextSourceContent) {
1157
- const l = e.contextSourcePath ?? Be(E(t), "__pretext-preview-context.ptx"), w = await an(
1283
+ const l = e.contextSourcePath ?? Ne(E(t), "__pretext-preview-context.ptx"), m = await Tn(
1158
1284
  f,
1159
1285
  l,
1160
1286
  r,
1161
1287
  e.contextSourceContent
1162
1288
  );
1163
- w && (f = w.content, p = e.sourceMap ? w.tree : void 0, Y = h(l), S = { divisionId: w.divisionId, level: w.level });
1289
+ m && (f = m.content, p = e.sourceMap ? m.tree : void 0, q = h(l), $ = { divisionId: m.divisionId, level: m.level });
1164
1290
  }
1165
- if (!S) {
1166
- const l = e.docinfo ?? (e.docinfoSourcePath ? await sn(e.docinfoSourcePath, r) : void 0);
1167
- f = cn(
1291
+ if (!$) {
1292
+ const l = e.docinfo ?? (e.docinfoSourcePath ? await En(e.docinfoSourcePath, r) : void 0);
1293
+ f = yn(
1168
1294
  f,
1169
- D,
1170
- m,
1295
+ S,
1296
+ w,
1171
1297
  l
1172
- ), K = { parentId: l?.trim() ? "root-1-2" : "root-1-1", position: 2 };
1298
+ ), Y = { parentId: l?.trim() ? "root-1-2" : "root-1-1", position: 2 };
1173
1299
  }
1174
1300
  }
1175
- const q = p ? Ot(p, Y, K) : void 0, Z = await n.fromString(f, {
1176
- url: `${a}/${c.split(N).join("/")}`,
1301
+ const Z = p ? Yt(p, q, Y) : void 0, Q = await n.fromString(f, {
1302
+ url: `${a}/${c.split(W).join("/")}`,
1177
1303
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
1178
- }), k = {
1179
- publisher: $(u)
1304
+ }), _ = {
1305
+ publisher: k(u)
1180
1306
  };
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);
1307
+ for (const [l, m] of Object.entries(gn))
1308
+ _[l] = k(m);
1309
+ $ && (_.subtree = k($.divisionId), _["subtree-level"] = k(String($.level)));
1310
+ for (const [l, m] of Object.entries(e.stringParams ?? {}))
1311
+ _[l] = k(m);
1186
1312
  let O;
1187
1313
  try {
1188
- O = await R.apply(Z, k);
1314
+ O = await P.apply(Q, _);
1189
1315
  } catch (l) {
1190
- throw ae(l), new Error(
1316
+ throw de(l), new Error(
1191
1317
  "PreTeXt XSLT transform failed; see the PTX:ERROR/PTX:FATAL messages on stderr for details.",
1192
1318
  { cause: l }
1193
1319
  );
1194
1320
  } finally {
1195
- Z.delete();
1321
+ Q.delete();
1196
1322
  }
1197
1323
  try {
1198
- let l = en(O.toHtmlString());
1199
- return l = Yt(l, {
1324
+ let l = wn(O.toHtmlString());
1325
+ l = fn(l, {
1200
1326
  ...e.offPageMessage !== void 0 ? { offPageMessage: e.offPageMessage } : {}
1201
- }), (e.openKnowls ?? !0) && (l = rt(l)), m === "slides" ? (l = rn(l), l = _t(l, e.revealView ?? "scroll", {
1327
+ }), (e.openKnowls ?? !0) && (l = st(l)), w === "slides" ? (l = bn(l), l = Ht(l, e.revealView ?? "scroll", {
1202
1328
  zoom: e.revealZoom
1203
- })) : e.theme && (l = Ct(l, e.theme)), e.previewBanner && (l = Xe(l, e.previewBanner)), {
1329
+ })) : e.theme && (l = Qt(l, e.theme)), e.previewBanner && (l = Ke(l, e.previewBanner));
1330
+ const m = w === "slides" ? [] : ye(l), ee = vt(m, S);
1331
+ return e.printPreview && (l = St(l, e.printPreview)), {
1204
1332
  html: l,
1205
- target: m,
1206
- ...q ? { sourceMap: q } : {},
1207
- ...G ? { assetDirs: G } : {}
1333
+ target: w,
1334
+ printouts: m,
1335
+ ...Z ? { sourceMap: Z } : {},
1336
+ ...G ? { assetDirs: G } : {},
1337
+ ...ee ? { rootPrintout: ee } : {}
1208
1338
  };
1209
1339
  } catch (l) {
1210
- throw ae(l), l;
1340
+ throw de(l), l;
1211
1341
  } finally {
1212
1342
  O.delete();
1213
1343
  }
1214
1344
  } finally {
1215
- at(a);
1345
+ ut(a);
1216
1346
  }
1217
1347
  }
1218
1348
  export {
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,
1227
- Ct as injectThemeBridge,
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
1349
+ Fe as PREVIEW_BANNER_STORAGE_KEY,
1350
+ Pe as PREVIEW_THEME_MESSAGE,
1351
+ gt as PRINT_PREVIEW_GLOBAL,
1352
+ pn as defaultXslDir,
1353
+ qt as detectRenderTarget,
1354
+ An as findSourceMapEntry,
1355
+ Rt as forcePortablePublication,
1356
+ Ke as injectPreviewBanner,
1357
+ St as injectPrintPreview,
1358
+ Ht as injectRevealBridge,
1359
+ Qt as injectThemeBridge,
1360
+ hn as isJspiAvailable,
1361
+ Bn as isPreviewTheme,
1362
+ Mn as isRevealView,
1363
+ ye as listPrintouts,
1364
+ st as openBornHiddenKnowls,
1365
+ Ve as previewBannerScript,
1366
+ On as previewThemeMessage,
1367
+ bt as printPreviewBridgeScript,
1368
+ jn as renderHtml,
1369
+ Ct as revealBridgeScript,
1370
+ vt as rootPrintoutId,
1371
+ Dn as setAssetsBase,
1372
+ Ln as setMountReader,
1373
+ Zt as themeBridgeScript,
1374
+ k as xpathStringLiteral
1240
1375
  };