@pretextbook/pretext-html 0.10.1 → 0.11.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.11.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, at = 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 ct(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,30 +294,145 @@ 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 = ct);
310
+ }
311
+ function Ee(e) {
312
+ xe();
313
+ const n = `mnt${++at}.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;
302
326
  }
303
- function be(e) {
304
- ge();
305
- const n = `mnt${++it}.ptx.invalid`;
306
- return X.set(n, e), `http://${n}`;
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, "&");
307
329
  }
308
- function at(e) {
309
- X.delete(new URL(e).host);
330
+ function mt(e, n, t) {
331
+ const r = [e, n].filter(Boolean).join(" ");
332
+ return r && t ? `${r}: ${t}` : r || t;
310
333
  }
311
- function lt(e, n) {
312
- ge(), we.set(e, n);
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") ?? "", a = D(r, "data-printout-title") ?? "";
342
+ n.push({
343
+ id: i,
344
+ type: o,
345
+ number: s,
346
+ title: a,
347
+ label: mt(o, s, a)
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;
363
+ }
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
+ `);
404
+ }
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
+ `);
424
+ }
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((c) => c.id === n) ? n : void 0, s = `
431
+ ${Et}
432
+ ${bt(o)}
433
+ ${o ? `${xt()}
434
+ ` : ""}${yt}`, a = i.index + i[0].length;
435
+ return r.slice(0, a) + s + r.slice(a);
313
436
  }
314
437
  const H = `<?xml version="1.0" encoding="UTF-8"?>
315
438
  <publication>
@@ -320,7 +443,7 @@ const H = `<?xml version="1.0" encoding="UTF-8"?>
320
443
  <platform portable="yes"/>
321
444
  </html>
322
445
  </publication>
323
- `, dt = ["theme", "style", "shell"];
446
+ `, $t = ["theme", "style", "shell"];
324
447
  function x(e, n) {
325
448
  for (const t of e.children)
326
449
  if (t.type === "element" && t.name === n)
@@ -330,21 +453,21 @@ function y(e, n) {
330
453
  let t = x(e, n);
331
454
  return t || (t = { type: "element", name: n, attributes: {}, children: [] }, e.children.push(t)), t;
332
455
  }
333
- function ut(e, n) {
456
+ function _t(e, n) {
334
457
  const t = x(e, "css");
335
- if (t && dt.some((i) => t.attributes?.[i]))
458
+ if (t && $t.some((i) => t.attributes?.[i]))
336
459
  return;
337
460
  const r = t ?? y(e, "css");
338
461
  r.attributes = { ...r.attributes, theme: n };
339
462
  }
340
- function ft(e, n) {
463
+ function kt(e, n) {
341
464
  const t = x(e, "appearance");
342
465
  if (t?.attributes?.theme)
343
466
  return;
344
467
  const r = t ?? y(e, "appearance");
345
468
  r.attributes = { ...r.attributes, theme: n };
346
469
  }
347
- function pt(e) {
470
+ function It(e) {
348
471
  const n = y(e, "resources");
349
472
  n.attributes = {
350
473
  ...n.attributes,
@@ -352,7 +475,7 @@ function pt(e) {
352
475
  math: "online"
353
476
  };
354
477
  }
355
- function ht(e, n = {}) {
478
+ function Rt(e, n = {}) {
356
479
  const t = n.cssTheme?.trim(), r = n.revealTheme?.trim(), i = n.target === "slides";
357
480
  if (!e && !t && !i)
358
481
  return H;
@@ -361,21 +484,21 @@ function ht(e, n = {}) {
361
484
  throw new Error(
362
485
  "Invalid publication file: no root <publication> element found"
363
486
  );
364
- const c = y(s, "html"), a = y(c, "platform");
365
- if (a.attributes = { ...a.attributes, portable: "yes" }, t && ut(c, t), i) {
487
+ const a = y(s, "html"), c = y(a, "platform");
488
+ if (c.attributes = { ...c.attributes, portable: "yes" }, t && _t(a, t), i) {
366
489
  const d = y(s, "revealjs");
367
- pt(d), r && ft(d, r);
490
+ It(d), r && kt(d, r);
368
491
  }
369
492
  return I(o);
370
493
  }
371
- function ne(e) {
494
+ function ie(e) {
372
495
  if (!(e === void 0 || e === "" || e.startsWith("/")))
373
496
  return e.endsWith("/") ? e : `${e}/`;
374
497
  }
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(
498
+ function Pt(e) {
499
+ const n = T(e ?? H), t = x(n, "publication"), r = t && x(t, "source"), i = r && x(r, "directories"), o = ie(
377
500
  i?.attributes?.external ?? void 0
378
- ), s = ne(
501
+ ), s = ie(
379
502
  i?.attributes?.generated ?? void 0
380
503
  );
381
504
  return {
@@ -384,18 +507,18 @@ function mt(e) {
384
507
  managed: o !== void 0 && s !== void 0
385
508
  };
386
509
  }
387
- function gn(e) {
510
+ function Mn(e) {
388
511
  return e === "slides" || e === "scroll";
389
512
  }
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));
513
+ const Te = 960, Se = 700, Dt = 1, Lt = 0.04;
514
+ function Mt(e) {
515
+ const n = typeof e == "number" && isFinite(e) ? e : Dt, t = Math.min(1, Math.max(0.25, n));
393
516
  return {
394
- width: Math.round(xe / t),
395
- height: Math.round(Ee / t)
517
+ width: Math.round(Te / t),
518
+ height: Math.round(Se / t)
396
519
  };
397
520
  }
398
- function bt(e) {
521
+ function At(e) {
399
522
  return {
400
523
  view: "scroll",
401
524
  scrollLayout: "compact",
@@ -405,11 +528,11 @@ function bt(e) {
405
528
  controls: !1,
406
529
  controlsTutorial: !1,
407
530
  hash: !1,
408
- ...gt(e.zoom),
409
- margin: vt
531
+ ...Mt(e.zoom),
532
+ margin: Lt
410
533
  };
411
534
  }
412
- function xt() {
535
+ function Bt() {
413
536
  return {
414
537
  // Explicitly null rather than absent: the same page may have been
415
538
  // delivered in scroll view a moment ago, and an embedder that re-injects
@@ -421,11 +544,11 @@ function xt() {
421
544
  // size with a percentage width renders its text far larger, relative to
422
545
  // the slide, than the same deck will on a projector. No zoom margin
423
546
  // though — presenting means filling whatever it is shown in.
424
- width: xe,
425
- height: Ee
547
+ width: Te,
548
+ height: Se
426
549
  };
427
550
  }
428
- const Et = [
551
+ const Ot = [
429
552
  "<style>",
430
553
  ".reveal-viewport.reveal-scroll .scroll-page section {",
431
554
  " box-shadow: inset 0 0 0 calc(1px / var(--slide-scale, 1))",
@@ -433,14 +556,14 @@ const Et = [
433
556
  "}",
434
557
  "</style>"
435
558
  ].join(`
436
- `), yt = [
559
+ `), jt = [
437
560
  " var paused = document.querySelectorAll('.reveal .fragment');",
438
561
  " for (var i = 0; i < paused.length; i++) {",
439
562
  " paused[i].classList.remove('fragment');",
440
563
  " }"
441
564
  ];
442
- function Tt(e, n = {}) {
443
- const t = e === "scroll" ? bt(n) : xt();
565
+ function Ct(e, n = {}) {
566
+ const t = e === "scroll" ? At(n) : Bt();
444
567
  return [
445
568
  "<script>",
446
569
  "(function () {",
@@ -468,7 +591,7 @@ function Tt(e, n = {}) {
468
591
  // Inside the wrapper rather than at top level: this script sits in <head>,
469
592
  // where the slides have not been parsed yet, but the deck calls initialize
470
593
  // from the end of the document, by which time they have.
471
- ...e === "scroll" ? yt : [],
594
+ ...e === "scroll" ? jt : [],
472
595
  " return initialize(merged);",
473
596
  " };",
474
597
  "})();",
@@ -476,27 +599,27 @@ function Tt(e, n = {}) {
476
599
  ].join(`
477
600
  `);
478
601
  }
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);
602
+ 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-->/;
603
+ function Ht(e, n, t = {}) {
604
+ 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
605
  if (!o)
483
606
  return i;
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) {
607
+ const s = o.index + o[0].length, a = `
608
+ ${Ft}
609
+ ${Ot}
610
+ ${Ct(n, t)}
611
+ ${Wt}`;
612
+ return i.slice(0, s) + a + i.slice(s);
613
+ }
614
+ const $e = "http://www.w3.org/2001/XInclude", oe = 64;
615
+ async function Vt(e, n, t) {
493
616
  return e.includes("include") ? (await z(e, n, t)).content : e;
494
617
  }
495
618
  async function z(e, n, t) {
496
619
  const r = T(e), i = {
497
620
  projectDir: h(t),
498
621
  stack: [h(n)]
499
- }, o = await _(
622
+ }, o = await R(
500
623
  r,
501
624
  E(h(n)),
502
625
  { "": "" },
@@ -504,43 +627,43 @@ async function z(e, n, t) {
504
627
  );
505
628
  return { tree: r, content: o ? I(r) : e };
506
629
  }
507
- function Dt(e) {
630
+ function Xt(e) {
508
631
  return e.data?.ptxIncludedFile;
509
632
  }
510
- function Mt(e, n) {
633
+ function Jt(e, n) {
511
634
  const t = e.data ?? (e.data = {});
512
635
  t.ptxIncludedFile = n;
513
636
  }
514
- function L(e, n) {
637
+ function A(e, n) {
515
638
  let t = e;
516
639
  for (const [r, i] of Object.entries(n.attributes))
517
640
  (r === "xmlns" || r.startsWith("xmlns:")) && (t === e && (t = { ...e }), t[r === "xmlns" ? "" : r.slice(6)] = i ?? "");
518
641
  return t;
519
642
  }
520
- function Te(e, n) {
643
+ function _e(e, n) {
521
644
  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;
645
+ return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && n[r] === $e;
523
646
  }
524
- async function _(e, n, t, r) {
647
+ async function R(e, n, t, r) {
525
648
  let i = !1;
526
649
  for (let o = 0; o < e.children.length; o++) {
527
650
  const s = e.children[o];
528
651
  if (s.type !== "element")
529
652
  continue;
530
- const c = L(t, s);
531
- if (Te(s, c)) {
532
- const a = await Se(
653
+ const a = A(t, s);
654
+ if (_e(s, a)) {
655
+ const c = await ke(
533
656
  s,
534
657
  n,
535
- c,
658
+ a,
536
659
  r
537
660
  );
538
- e.children.splice(o, 1, ...a), o += a.length - 1, i = !0;
539
- } else await _(s, n, c, r) && (i = !0);
661
+ e.children.splice(o, 1, ...c), o += c.length - 1, i = !0;
662
+ } else await R(s, n, a, r) && (i = !0);
540
663
  }
541
664
  return i;
542
665
  }
543
- async function Se(e, n, t, r) {
666
+ async function ke(e, n, t, r) {
544
667
  const i = r.stack[r.stack.length - 1];
545
668
  if (e.attributes.xpointer)
546
669
  throw new Error(
@@ -554,37 +677,37 @@ async function Se(e, n, t, r) {
554
677
  s = decodeURIComponent(o);
555
678
  } catch {
556
679
  }
557
- const c = h(n, s);
558
- if (c !== r.projectDir && !c.startsWith(r.projectDir + N))
680
+ const a = h(n, s);
681
+ if (a !== r.projectDir && !a.startsWith(r.projectDir + W))
559
682
  throw new Error(
560
683
  `xi:include escapes the project directory: ${o} (in ${i})`
561
684
  );
562
- if (r.stack.includes(c))
685
+ if (r.stack.includes(a))
563
686
  throw new Error(
564
- `Circular xi:include: ${[...r.stack, c].join(" -> ")}`
687
+ `Circular xi:include: ${[...r.stack, a].join(" -> ")}`
565
688
  );
566
- if (r.stack.length >= re)
567
- throw new Error(`xi:include nesting exceeds ${re} levels`);
568
- const a = await P(c);
569
- if (a === void 0) {
570
- const p = Lt(e, t);
689
+ if (r.stack.length >= oe)
690
+ throw new Error(`xi:include nesting exceeds ${oe} levels`);
691
+ const c = await B(a);
692
+ if (c === void 0) {
693
+ const p = Kt(e, t);
571
694
  if (p)
572
- return await _(p, n, t, r), p.children;
695
+ return await R(p, n, t, r), p.children;
573
696
  throw new Error(`xi:include target not found: ${o} (in ${i})`);
574
697
  }
575
698
  if (e.attributes.parse === "text")
576
- return [{ type: "text", value: a }];
699
+ return [{ type: "text", value: c }];
577
700
  let d;
578
701
  try {
579
- d = T(a);
702
+ d = T(c);
580
703
  } catch (p) {
581
704
  throw new Error(
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.)`
705
+ `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.)`
583
706
  );
584
707
  }
585
- r.stack.push(c);
708
+ r.stack.push(a);
586
709
  try {
587
- await _(d, E(c), { "": "" }, r);
710
+ await R(d, E(a), { "": "" }, r);
588
711
  } finally {
589
712
  r.stack.pop();
590
713
  }
@@ -592,37 +715,37 @@ async function Se(e, n, t, r) {
592
715
  (p) => p.type === "element"
593
716
  );
594
717
  for (const p of u)
595
- Mt(p, c);
718
+ Jt(p, a);
596
719
  return u;
597
720
  }
598
- function ie(e) {
721
+ function se(e) {
599
722
  return e.name === "docinfo";
600
723
  }
601
- async function At(e, n, t) {
724
+ async function zt(e, n, t) {
602
725
  try {
603
726
  const i = T(e).children.find(
604
727
  (d) => d.type === "element"
605
728
  );
606
729
  if (!i)
607
730
  return;
608
- const o = h(n), s = E(o), c = {
731
+ const o = h(n), s = E(o), a = {
609
732
  projectDir: h(t),
610
733
  stack: [o]
611
- }, a = L({ "": "" }, i);
734
+ }, c = A({ "": "" }, i);
612
735
  for (const d of i.children) {
613
736
  if (d.type !== "element")
614
737
  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(
738
+ const u = A(c, d);
739
+ if (se(d))
740
+ return await R(d, s, u, a), I(d);
741
+ if (_e(d, u)) {
742
+ const f = (await ke(
620
743
  d,
621
744
  s,
622
745
  u,
623
- c
746
+ a
624
747
  )).find(
625
- (m) => m.type === "element" && ie(m)
748
+ (w) => w.type === "element" && se(w)
626
749
  );
627
750
  if (f)
628
751
  return I(f);
@@ -635,78 +758,78 @@ async function At(e, n, t) {
635
758
  return;
636
759
  }
637
760
  }
638
- function Lt(e, n) {
761
+ function Kt(e, n) {
639
762
  for (const t of e.children) {
640
763
  if (t.type !== "element")
641
764
  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)
765
+ const r = A(n, t), i = t.name.indexOf(":"), o = i === -1 ? "" : t.name.slice(0, i);
766
+ if ((i === -1 ? t.name : t.name.slice(i + 1)) === "fallback" && r[o] === $e)
644
767
  return t;
645
768
  }
646
769
  }
647
- function ke(e) {
770
+ function Ie(e) {
648
771
  return typeof e == "object" && e !== null && e.type === "element";
649
772
  }
650
- function Pt(e) {
773
+ function Gt(e) {
651
774
  return /^(pf|xhtml):/.test(e.name);
652
775
  }
653
- function Ot(e, n, t) {
654
- const r = [], i = e.children.find(ke);
776
+ function Yt(e, n, t) {
777
+ const r = [], i = e.children.find(Ie);
655
778
  if (i) {
656
779
  const o = t?.parentId ?? "root";
657
- $e(i, o, t?.position ?? 1, n, o, r);
780
+ Re(i, o, t?.position ?? 1, n, o, r);
658
781
  }
659
782
  return r;
660
783
  }
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";
784
+ function Re(e, n, t, r, i, o) {
785
+ const s = Xt(e) ?? r;
786
+ let a, c;
787
+ if (Gt(e))
788
+ c = "root";
666
789
  else {
667
790
  const u = e.attributes.label ?? e.attributes["xml:id"];
668
- c = u ?? `${n}-${t}`, o.push({
669
- id: c,
791
+ a = u ?? `${n}-${t}`, o.push({
792
+ id: a,
670
793
  file: s,
671
794
  line: e.position?.start.line ?? 1,
672
795
  column: e.position?.start.column ?? 1,
673
796
  endLine: e.position?.end.line ?? e.position?.start.line ?? 1,
674
797
  parent: i
675
- }), a = c;
798
+ }), c = a;
676
799
  }
677
800
  let d = 0;
678
801
  for (const u of e.children)
679
- ke(u) && (d += 1, $e(
802
+ Ie(u) && (d += 1, Re(
680
803
  u,
681
- a,
804
+ c,
682
805
  d,
683
806
  s,
684
- c ?? i,
807
+ a ?? i,
685
808
  o
686
809
  ));
687
810
  }
688
- function bn(e, n) {
811
+ function An(e, n) {
689
812
  let t;
690
813
  for (const r of e)
691
814
  r.line <= n && (t = r);
692
815
  return t ?? e[0];
693
816
  }
694
- function Bt(e) {
817
+ function qt(e) {
695
818
  const n = e.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!\[CDATA\[[\s\S]*?\]\]>/g, " ");
696
819
  return /<\s*slide(?:show)?[\s/>]/.test(n) ? "slides" : "html";
697
820
  }
698
- const Ie = "pretext-html:set-theme";
699
- function xn(e) {
821
+ const Pe = "pretext-html:set-theme";
822
+ function Bn(e) {
700
823
  return e === "dark" || e === "light" || e === "system";
701
824
  }
702
- function En(e) {
703
- return { type: Ie, theme: e };
825
+ function On(e) {
826
+ return { type: Pe, theme: e };
704
827
  }
705
- function jt(e) {
828
+ function Zt(e) {
706
829
  return [
707
830
  "<script>",
708
831
  "(function () {",
709
- " var CFG = " + JSON.stringify({ msg: Ie, initial: e }) + ";",
832
+ " var CFG = " + JSON.stringify({ msg: Pe, initial: e }) + ";",
710
833
  // Where the last requested theme is remembered so it survives an in-place
711
834
  // document rewrite (same Window) and outranks the baked initial value.
712
835
  " var KEY = '__ptxPreviewTheme';",
@@ -776,12 +899,12 @@ function jt(e) {
776
899
  ].join(`
777
900
  `);
778
901
  }
779
- function Ct(e, n) {
780
- const t = jt(n);
902
+ function Qt(e, n) {
903
+ const t = Zt(n);
781
904
  return /<head[^>]*>/i.test(e) ? e.replace(/<head([^>]*)>/i, `<head$1>
782
905
  ${t}`) : e;
783
906
  }
784
- const _e = /* @__PURE__ */ new Set([
907
+ const De = /* @__PURE__ */ new Set([
785
908
  "colophon",
786
909
  "biography",
787
910
  "dedication",
@@ -801,19 +924,19 @@ const _e = /* @__PURE__ */ new Set([
801
924
  "glossary",
802
925
  "worksheet",
803
926
  "handout"
804
- ]), Re = /* @__PURE__ */ new Set([
927
+ ]), Le = /* @__PURE__ */ new Set([
805
928
  "book",
806
929
  "article",
807
930
  "slideshow",
808
931
  "letter",
809
932
  "memo"
810
- ]), De = /* @__PURE__ */ new Set([
811
- ...Re,
812
- ..._e,
933
+ ]), Me = /* @__PURE__ */ new Set([
934
+ ...Le,
935
+ ...De,
813
936
  "part",
814
937
  "frontmatter",
815
938
  "backmatter"
816
- ]), Ft = /* @__PURE__ */ new Set(["docinfo"]), Me = /* @__PURE__ */ new Set([
939
+ ]), en = /* @__PURE__ */ new Set(["docinfo"]), Ae = /* @__PURE__ */ new Set([
817
940
  "title",
818
941
  "shorttitle",
819
942
  "plaintitle",
@@ -823,47 +946,47 @@ const _e = /* @__PURE__ */ new Set([
823
946
  function g(e) {
824
947
  return e.type === "element";
825
948
  }
826
- function Ae(e) {
949
+ function Be(e) {
827
950
  return e.attributes["xml:id"] ?? void 0;
828
951
  }
829
- function U(e, n) {
952
+ function V(e, n) {
830
953
  for (const t of e.children) {
831
954
  if (!g(t)) continue;
832
- if (Ae(t) === n) return t;
833
- const r = U(t, n);
955
+ if (Be(t) === n) return t;
956
+ const r = V(t, n);
834
957
  if (r) return r;
835
958
  }
836
959
  }
837
- function M(e, n) {
960
+ function L(e, n) {
838
961
  for (const t of e.children) {
839
962
  if (!g(t)) continue;
840
963
  if (t === n) return [t];
841
- const r = M(t, n);
964
+ const r = L(t, n);
842
965
  if (r) return [t, ...r];
843
966
  }
844
967
  }
845
- function Nt(e, n) {
968
+ function tn(e, n) {
846
969
  let t = 0;
847
970
  for (const [r, i] of e.entries()) {
848
971
  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);
972
+ 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
973
  }
851
974
  return t;
852
975
  }
853
- function Le(e) {
854
- if (!Me.has(e.name)) {
976
+ function Oe(e) {
977
+ if (!Ae.has(e.name)) {
855
978
  e.children = e.children.filter(g);
856
979
  for (const n of e.children)
857
- Le(n);
980
+ Oe(n);
858
981
  }
859
982
  }
860
- function V(e, n) {
983
+ function X(e, n) {
861
984
  const t = [];
862
985
  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)));
986
+ 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
987
  e.children = t;
865
988
  }
866
- function Wt(e) {
989
+ function nn(e) {
867
990
  const n = /* @__PURE__ */ new Set(), t = (r) => {
868
991
  if (r.name === "xref") {
869
992
  const i = [
@@ -880,11 +1003,11 @@ function Wt(e) {
880
1003
  };
881
1004
  return t(e), n;
882
1005
  }
883
- function Ht(e, n, t) {
1006
+ function rn(e, n, t) {
884
1007
  const r = (i) => {
885
1008
  for (const [o, s] of i.children.entries())
886
1009
  if (g(s)) {
887
- if (Ae(s) === n)
1010
+ if (Be(s) === n)
888
1011
  return i.children[o] = t, !0;
889
1012
  if (r(s)) return !0;
890
1013
  }
@@ -892,49 +1015,49 @@ function Ht(e, n, t) {
892
1015
  };
893
1016
  return r(e);
894
1017
  }
895
- function Ut(e, n) {
896
- const t = U(e, n);
1018
+ function on(e, n) {
1019
+ const t = V(e, n);
897
1020
  if (!t) return;
898
- const r = M(e, t);
1021
+ const r = L(e, t);
899
1022
  if (!r) return;
900
1023
  const i = r.filter(
901
1024
  (f) => f.name !== "pretext" && f.name !== "mathbook"
902
1025
  ), o = i[0], s = o?.name === "book" && o.children.some(
903
1026
  (f) => g(f) && f.name === "part"
904
- ), c = Nt(i, s), a = new Set(r), d = Wt(t), u = /* @__PURE__ */ new Set();
1027
+ ), a = tn(i, s), c = new Set(r), d = nn(t), u = /* @__PURE__ */ new Set();
905
1028
  if (d.size > 0)
906
1029
  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));
1030
+ const w = V(e, f);
1031
+ if (!w || w === t) continue;
1032
+ const P = L(e, w);
1033
+ if (!P) continue;
1034
+ const b = [...P].reverse().find((v) => Me.has(v.name));
912
1035
  if (b && b !== t) {
913
1036
  u.add(b);
914
- for (const v of M(e, b) ?? [])
915
- a.add(v);
1037
+ for (const v of L(e, b) ?? [])
1038
+ c.add(v);
916
1039
  }
917
1040
  }
918
1041
  for (const f of r) {
919
1042
  if (f === t) break;
920
- V(f, a);
1043
+ X(f, c);
921
1044
  }
922
1045
  for (const f of u)
923
- Le(f);
1046
+ Oe(f);
924
1047
  const p = e.children.find(g);
925
- return p && !r.includes(p) && V(p, a), { content: I(e), divisionId: n, level: c };
1048
+ return p && !r.includes(p) && X(p, c), { content: I(e), divisionId: n, level: a };
926
1049
  }
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) {
1050
+ const sn = "This live preview shows a single division, so links into the rest of the document do not work here.", an = /<a\b([^>]*)>/g, cn = /\sid="([^"]*)"/g, C = /\shref="([^"]*)"/, ln = /\\href\{([^{}]*)\}/g, ae = /\stitle="([^"]*)"/;
1051
+ function dn(e) {
929
1052
  const n = /* @__PURE__ */ new Set();
930
- for (const t of e.matchAll(zt))
1053
+ for (const t of e.matchAll(cn))
931
1054
  n.add(t[1]);
932
1055
  return n;
933
1056
  }
934
- function Kt(e) {
1057
+ function un(e) {
935
1058
  return e.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
936
1059
  }
937
- function se(e, n) {
1060
+ function ce(e, n) {
938
1061
  if (e.startsWith("#") || e === "") return { kind: "keep" };
939
1062
  if (/^[a-z][a-z0-9+.-]*:/i.test(e) || e.startsWith("//"))
940
1063
  return { kind: "keep" };
@@ -943,73 +1066,73 @@ function se(e, n) {
943
1066
  const r = e.slice(t + 1);
944
1067
  return n.has(r) && r !== "" ? { kind: "same-page", id: r } : { kind: "off-page" };
945
1068
  }
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;
1069
+ function fn(e, n = {}) {
1070
+ const t = n.offPageMessage ?? sn, r = dn(e);
1071
+ return e.replace(an, (o, s) => {
1072
+ const a = C.exec(s);
1073
+ if (!a) return o;
1074
+ const c = ce(a[1], r);
1075
+ if (c.kind === "keep") return o;
1076
+ if (c.kind === "same-page")
1077
+ return `<a${s.replace(C, ` href="#${c.id}"`)}>`;
1078
+ const d = ae.exec(s), u = un(t), p = d ? `${d[1]} — ${u}` : u;
1079
+ return `<a${s.replace(C, "").replace(ae, "")} title="${p}" aria-disabled="true" style="cursor:default">`;
1080
+ }).replace(ln, (o, s) => {
1081
+ const a = ce(s, r);
1082
+ return a.kind === "same-page" ? `\\href{#${a.id}}` : o;
960
1083
  });
961
1084
  }
962
- function qt() {
963
- return pe(A(), "xsl");
1085
+ function pn() {
1086
+ return me(M(), "xsl");
964
1087
  }
965
- function Zt() {
1088
+ function hn() {
966
1089
  return "Suspending" in WebAssembly;
967
1090
  }
968
- function Qt() {
969
- if (!Zt())
1091
+ function mn() {
1092
+ if (!hn())
970
1093
  throw new Error(
971
1094
  "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
1095
  );
973
1096
  }
974
- function $(e) {
1097
+ function k(e) {
975
1098
  return e.includes("'") ? e.includes('"') ? `concat(${e.split("'").map((t) => `'${t}'`).join(`, "'", `)})` : `"${e}"` : `'${e}'`;
976
1099
  }
977
- function en(e) {
1100
+ function wn(e) {
978
1101
  return e.replace(
979
1102
  /from '\.\/(https:\/\/[^']+)'/g,
980
1103
  (n, t) => `from '${t}'`
981
1104
  );
982
1105
  }
983
- const tn = `https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@${me}/dist/`, nn = {
984
- "cli.version": me,
1106
+ const vn = `https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@${ve}/dist/`, gn = {
1107
+ "cli.version": ve,
985
1108
  // Colon-delimited: pretext-runestone.xsl splits them with str:tokenize.
986
- "rs-js": qe.join(":"),
987
- "rs-css": Ze.join(":"),
988
- "rs-version": Ye
1109
+ "rs-js": et.join(":"),
1110
+ "rs-css": tt.join(":"),
1111
+ "rs-version": Qe
989
1112
  };
990
- function rn(e) {
1113
+ function bn(e) {
991
1114
  return e.replace(
992
1115
  /(<link\b[^>]*\bhref=["'])_static\//gi,
993
- `$1${tn}_static/`
1116
+ `$1${vn}_static/`
994
1117
  );
995
1118
  }
996
- function on(e) {
1119
+ function xn(e) {
997
1120
  return e.slice(0, 65536).replace(/<\?[\s\S]*?\?>/g, " ").replace(/<!--[\s\S]*?-->/g, " ").replace(/<!DOCTYPE[^>]*>/gi, " ").match(/<\s*([A-Za-z][\w:-]*)/)?.[1];
998
1121
  }
999
- async function ce(e) {
1000
- const n = await P(e);
1122
+ async function le(e) {
1123
+ const n = await B(e);
1001
1124
  if (n === void 0)
1002
1125
  throw new Error(
1003
1126
  `Could not read ${e}. (In the browser build only absolute URLs are readable — pass sourceContent instead of relying on sourcePath.)`
1004
1127
  );
1005
1128
  return n;
1006
1129
  }
1007
- async function sn(e, n) {
1008
- const t = h(e), r = await P(t);
1130
+ async function En(e, n) {
1131
+ const t = h(e), r = await B(t);
1009
1132
  if (r !== void 0)
1010
- return At(r, t, n);
1133
+ return zt(r, t, n);
1011
1134
  }
1012
- function cn(e, n, t, r) {
1135
+ function yn(e, n, t, r) {
1013
1136
  const i = e.replace(/^\uFEFF/, "").replace(/<\?xml[\s\S]*?\?>/, "").replace(/<!DOCTYPE[^>]*>/i, ""), o = t === "slides" ? "slideshow" : n === "chapter" || n === "part" ? "book" : "article";
1014
1137
  return `<pretext>
1015
1138
  ${r?.trim() ? `${r.trim()}
@@ -1020,108 +1143,108 @@ ${i}
1020
1143
  </pretext>
1021
1144
  `;
1022
1145
  }
1023
- async function an(e, n, t, r) {
1146
+ async function Tn(e, n, t, r) {
1024
1147
  const i = T(e).children.find(
1025
1148
  (u) => u.type === "element"
1026
1149
  ), o = i?.attributes["xml:id"];
1027
1150
  if (!i || !o) return;
1028
- const s = h(n), c = r ?? await P(s);
1029
- if (c === void 0) return;
1030
- let a;
1151
+ const s = h(n), a = r ?? await B(s);
1152
+ if (a === void 0) return;
1153
+ let c;
1031
1154
  try {
1032
- a = (await z(c, s, t)).tree;
1155
+ c = (await z(a, s, t)).tree;
1033
1156
  } catch {
1034
1157
  return;
1035
1158
  }
1036
- if (!Ht(a, o, i)) return;
1037
- const d = Ut(a, o);
1159
+ if (!rn(c, o, i)) return;
1160
+ const d = on(c, o);
1038
1161
  if (d)
1039
- return { ...d, tree: a };
1162
+ return { ...d, tree: c };
1040
1163
  }
1041
- let Pe = !1;
1042
- function ln(e) {
1164
+ let je = !1;
1165
+ function Sn(e) {
1043
1166
  return e instanceof Error && /\bAborted\(/.test(e.message);
1044
1167
  }
1045
- function dn(e) {
1168
+ function $n(e) {
1046
1169
  return e instanceof Error && /memory access|out of bounds/i.test(e.message);
1047
1170
  }
1048
- function un() {
1049
- if (Pe)
1171
+ function _n() {
1172
+ if (je)
1050
1173
  throw new Error(
1051
1174
  "The WebAssembly renderer aborted earlier in this process and cannot be reused. Restart the process (or reload the page) to render again."
1052
1175
  );
1053
1176
  }
1054
- function ae(e) {
1055
- if (ln(e))
1056
- throw Pe = !0, new Error(
1177
+ function de(e) {
1178
+ if (Sn(e))
1179
+ throw je = !0, new Error(
1057
1180
  "The WebAssembly renderer aborted and cannot be reused. Restart the process (or reload the page) to render again.",
1058
1181
  { cause: e }
1059
1182
  );
1060
- if (dn(e))
1183
+ if ($n(e))
1061
1184
  throw new Error(
1062
1185
  "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
1186
  { cause: e }
1064
1187
  );
1065
1188
  }
1066
- let C;
1067
- async function Oe() {
1068
- return C || (C = (async () => {
1189
+ let N;
1190
+ async function Ce() {
1191
+ return N || (N = (async () => {
1069
1192
  const [e, n] = await Promise.all([
1070
1193
  import("@pretextbook/libxslt-wasm"),
1071
1194
  import("@pretextbook/libxslt-wasm/exslt")
1072
1195
  ]);
1073
1196
  return n.registerAll(), e;
1074
- })()), C;
1197
+ })()), N;
1075
1198
  }
1076
- const F = /* @__PURE__ */ new Map(), fn = {
1199
+ const F = /* @__PURE__ */ new Map(), kn = {
1077
1200
  html: "preview-html.xsl",
1078
1201
  slides: "preview-revealjs.xsl"
1079
1202
  };
1080
- async function pn(e, n) {
1081
- const t = fn[n], r = `${n}\0${e}`;
1203
+ async function In(e, n) {
1204
+ const t = kn[n], r = `${n}\0${e}`;
1082
1205
  let i = F.get(r);
1083
1206
  return i || (i = (async () => {
1084
- const { XmlDocument: o, XsltStylesheet: s } = await Oe(), c = be(e), a = await he(A(), `/${t}`);
1085
- if (a === void 0)
1207
+ const { XmlDocument: o, XsltStylesheet: s } = await Ce(), a = Ee(e), c = await we(M(), `/${t}`);
1208
+ if (c === void 0)
1086
1209
  throw new Error(
1087
- `Could not read ${t} from ${A()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
1210
+ `Could not read ${t} from ${M()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
1088
1211
  );
1089
- const d = new TextDecoder().decode(a), u = await o.fromString(d, {
1090
- url: `${c}/${t}`,
1212
+ const d = new TextDecoder().decode(c), u = await o.fromString(d, {
1213
+ url: `${a}/${t}`,
1091
1214
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
1092
1215
  });
1093
1216
  return s.fromXmlDocument(u);
1094
1217
  })(), F.set(r, i), i.catch(() => F.delete(r))), i;
1095
1218
  }
1096
- let le = Promise.resolve();
1097
- function yn(e) {
1098
- const n = le.then(
1099
- () => de(e),
1100
- () => de(e)
1219
+ let ue = Promise.resolve();
1220
+ function jn(e) {
1221
+ const n = ue.then(
1222
+ () => fe(e),
1223
+ () => fe(e)
1101
1224
  );
1102
- return le = n.catch(() => {
1225
+ return ue = n.catch(() => {
1103
1226
  }), n;
1104
1227
  }
1105
- async function de(e) {
1106
- Qt(), un();
1107
- const { XmlDocument: n } = await Oe(), t = h(e.sourcePath), r = h(
1228
+ async function fe(e) {
1229
+ mn(), _n();
1230
+ const { XmlDocument: n } = await Ce(), t = h(e.sourcePath), r = h(
1108
1231
  e.projectDir ?? E(t)
1109
- ), i = e.sourceContent ?? await ce(t), o = B(r, t);
1232
+ ), i = e.sourceContent ?? await le(t), o = j(r, t);
1110
1233
  if (o.startsWith(".."))
1111
1234
  throw new Error(
1112
1235
  `sourcePath (${t}) must live inside projectDir (${r})`
1113
1236
  );
1114
- const s = B(
1237
+ const s = j(
1115
1238
  r,
1116
1239
  h(e.mainSourcePath ?? t)
1117
- ), c = s.startsWith("..") ? o : s, a = be(r);
1240
+ ), a = s.startsWith("..") ? o : s, c = Ee(r);
1118
1241
  try {
1119
- let d, u = `${a}/__pretext-preview-publication.xml`;
1242
+ let d, u = `${c}/__pretext-preview-publication.xml`;
1120
1243
  if (e.publicationPath) {
1121
1244
  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("/")}`);
1245
+ d = await le(l);
1246
+ const m = j(r, l);
1247
+ m.startsWith("..") || (u = `${c}/${m.split(W).join("/")}`);
1125
1248
  }
1126
1249
  let p, f;
1127
1250
  if (e.sourceMap) {
@@ -1132,109 +1255,118 @@ async function de(e) {
1132
1255
  );
1133
1256
  p = l.tree, f = l.content;
1134
1257
  } else
1135
- f = await Rt(
1258
+ f = await Vt(
1136
1259
  i,
1137
1260
  t,
1138
1261
  r
1139
1262
  );
1140
- const m = e.target ?? Bt(f), R = await pn(e.xslDir ?? qt(), m), b = ht(d, {
1263
+ const w = e.target ?? qt(f), P = await In(e.xslDir ?? pn(), w), b = Rt(d, {
1141
1264
  cssTheme: e.cssTheme,
1142
1265
  revealTheme: e.revealTheme,
1143
- target: m
1266
+ target: w
1144
1267
  });
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") {
1268
+ ft(u, b);
1269
+ const v = Pt(b), K = E(h(r, a)), G = v.external !== void 0 && v.generated !== void 0 ? {
1270
+ external: h(K, v.external),
1271
+ generated: h(K, v.generated)
1272
+ } : void 0, S = xn(f);
1273
+ let Y = { parentId: "root", position: 1 }, $, q = t;
1274
+ if (S !== "pretext" && S !== "mathbook") {
1152
1275
  if (!e.fragment)
1153
1276
  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.`
1277
+ `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
1278
  );
1156
1279
  if (e.contextSourcePath || e.contextSourceContent) {
1157
- const l = e.contextSourcePath ?? Be(E(t), "__pretext-preview-context.ptx"), w = await an(
1280
+ const l = e.contextSourcePath ?? Ne(E(t), "__pretext-preview-context.ptx"), m = await Tn(
1158
1281
  f,
1159
1282
  l,
1160
1283
  r,
1161
1284
  e.contextSourceContent
1162
1285
  );
1163
- w && (f = w.content, p = e.sourceMap ? w.tree : void 0, Y = h(l), S = { divisionId: w.divisionId, level: w.level });
1286
+ m && (f = m.content, p = e.sourceMap ? m.tree : void 0, q = h(l), $ = { divisionId: m.divisionId, level: m.level });
1164
1287
  }
1165
- if (!S) {
1166
- const l = e.docinfo ?? (e.docinfoSourcePath ? await sn(e.docinfoSourcePath, r) : void 0);
1167
- f = cn(
1288
+ if (!$) {
1289
+ const l = e.docinfo ?? (e.docinfoSourcePath ? await En(e.docinfoSourcePath, r) : void 0);
1290
+ f = yn(
1168
1291
  f,
1169
- D,
1170
- m,
1292
+ S,
1293
+ w,
1171
1294
  l
1172
- ), K = { parentId: l?.trim() ? "root-1-2" : "root-1-1", position: 2 };
1295
+ ), Y = { parentId: l?.trim() ? "root-1-2" : "root-1-1", position: 2 };
1173
1296
  }
1174
1297
  }
1175
- const q = p ? Ot(p, Y, K) : void 0, Z = await n.fromString(f, {
1176
- url: `${a}/${c.split(N).join("/")}`,
1298
+ const Z = p ? Yt(p, q, Y) : void 0, Q = await n.fromString(f, {
1299
+ url: `${c}/${a.split(W).join("/")}`,
1177
1300
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
1178
- }), k = {
1179
- publisher: $(u)
1301
+ }), _ = {
1302
+ publisher: k(u)
1180
1303
  };
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);
1304
+ for (const [l, m] of Object.entries(gn))
1305
+ _[l] = k(m);
1306
+ $ && (_.subtree = k($.divisionId), _["subtree-level"] = k(String($.level)));
1307
+ for (const [l, m] of Object.entries(e.stringParams ?? {}))
1308
+ _[l] = k(m);
1186
1309
  let O;
1187
1310
  try {
1188
- O = await R.apply(Z, k);
1311
+ O = await P.apply(Q, _);
1189
1312
  } catch (l) {
1190
- throw ae(l), new Error(
1313
+ throw de(l), new Error(
1191
1314
  "PreTeXt XSLT transform failed; see the PTX:ERROR/PTX:FATAL messages on stderr for details.",
1192
1315
  { cause: l }
1193
1316
  );
1194
1317
  } finally {
1195
- Z.delete();
1318
+ Q.delete();
1196
1319
  }
1197
1320
  try {
1198
- let l = en(O.toHtmlString());
1199
- return l = Yt(l, {
1321
+ let l = wn(O.toHtmlString());
1322
+ l = fn(l, {
1200
1323
  ...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", {
1324
+ }), (e.openKnowls ?? !0) && (l = st(l)), w === "slides" ? (l = bn(l), l = Ht(l, e.revealView ?? "scroll", {
1202
1325
  zoom: e.revealZoom
1203
- })) : e.theme && (l = Ct(l, e.theme)), e.previewBanner && (l = Xe(l, e.previewBanner)), {
1326
+ })) : e.theme && (l = Qt(l, e.theme)), e.previewBanner && (l = Ke(l, e.previewBanner));
1327
+ const m = w === "slides" ? [] : ye(l), ee = vt(m, S);
1328
+ return e.printPreview && (l = St(l, e.printPreview)), {
1204
1329
  html: l,
1205
- target: m,
1206
- ...q ? { sourceMap: q } : {},
1207
- ...G ? { assetDirs: G } : {}
1330
+ target: w,
1331
+ printouts: m,
1332
+ ...Z ? { sourceMap: Z } : {},
1333
+ ...G ? { assetDirs: G } : {},
1334
+ ...ee ? { rootPrintout: ee } : {}
1208
1335
  };
1209
1336
  } catch (l) {
1210
- throw ae(l), l;
1337
+ throw de(l), l;
1211
1338
  } finally {
1212
1339
  O.delete();
1213
1340
  }
1214
1341
  } finally {
1215
- at(a);
1342
+ ut(c);
1216
1343
  }
1217
1344
  }
1218
1345
  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
1346
+ Fe as PREVIEW_BANNER_STORAGE_KEY,
1347
+ Pe as PREVIEW_THEME_MESSAGE,
1348
+ gt as PRINT_PREVIEW_GLOBAL,
1349
+ pn as defaultXslDir,
1350
+ qt as detectRenderTarget,
1351
+ An as findSourceMapEntry,
1352
+ Rt as forcePortablePublication,
1353
+ Ke as injectPreviewBanner,
1354
+ St as injectPrintPreview,
1355
+ Ht as injectRevealBridge,
1356
+ Qt as injectThemeBridge,
1357
+ hn as isJspiAvailable,
1358
+ Bn as isPreviewTheme,
1359
+ Mn as isRevealView,
1360
+ ye as listPrintouts,
1361
+ st as openBornHiddenKnowls,
1362
+ Ve as previewBannerScript,
1363
+ On as previewThemeMessage,
1364
+ bt as printPreviewBridgeScript,
1365
+ jn as renderHtml,
1366
+ Ct as revealBridgeScript,
1367
+ vt as rootPrintoutId,
1368
+ Dn as setAssetsBase,
1369
+ Ln as setMountReader,
1370
+ Zt as themeBridgeScript,
1371
+ k as xpathStringLiteral
1240
1372
  };