@pretextbook/pretext-html 0.17.0 → 0.18.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
- import { fromXml as oe } from "xast-util-from-xml";
1
+ import { fromXml as ne } from "xast-util-from-xml";
2
2
  import { toXml as te } from "xast-util-to-xml";
3
- const Ie = "/";
4
- function ze(e) {
3
+ const Ae = "/";
4
+ function Ge(e) {
5
5
  if (!e)
6
6
  return ".";
7
7
  const t = e.startsWith("/"), n = e.length > 1 && e.endsWith("/"), r = [];
@@ -17,7 +17,7 @@ function ze(e) {
17
17
  let i = r.join("/");
18
18
  return t && (i = `/${i}`), i ? (n && !i.endsWith("/") && (i += "/"), i) : t ? "/" : ".";
19
19
  }
20
- function E(...e) {
20
+ function S(...e) {
21
21
  let t = "";
22
22
  for (let r = e.length - 1; r >= 0; r--) {
23
23
  const i = e[r];
@@ -25,14 +25,14 @@ function E(...e) {
25
25
  break;
26
26
  }
27
27
  t.startsWith("/") || (t = `/${t}`);
28
- const n = ze(t);
28
+ const n = Ge(t);
29
29
  return n.length > 1 && n.endsWith("/") ? n.slice(0, -1) : n;
30
30
  }
31
- function St(...e) {
31
+ function It(...e) {
32
32
  const t = e.filter(Boolean).join("/");
33
- return t ? ze(t) : ".";
33
+ return t ? Ge(t) : ".";
34
34
  }
35
- function Y(e) {
35
+ function K(e) {
36
36
  const t = e.replace(/\/+$/, "");
37
37
  if (!t)
38
38
  return e.startsWith("/") ? "/" : ".";
@@ -40,27 +40,27 @@ function Y(e) {
40
40
  return n < 0 ? "." : n === 0 ? "/" : t.slice(0, n);
41
41
  }
42
42
  function ye(e, t) {
43
- const n = E(e).split("/").filter(Boolean), r = E(t).split("/").filter(Boolean);
43
+ const n = S(e).split("/").filter(Boolean), r = S(t).split("/").filter(Boolean);
44
44
  let i = 0;
45
45
  for (; i < n.length && i < r.length && n[i] === r[i]; )
46
46
  i += 1;
47
47
  return [...new Array(n.length - i).fill(".."), ...r.slice(i)].join("/");
48
48
  }
49
- const Tt = "ptxPreviewBannerDismissed", It = "About live preview";
50
- function Ce(e) {
49
+ const At = "ptxPreviewBannerDismissed", Lt = "About live preview";
50
+ function Oe(e) {
51
51
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
52
52
  }
53
- function At(e) {
53
+ function _t(e) {
54
54
  return [
55
55
  '<div id="ptx-preview-banner" class="ptx-preview-banner" role="note">',
56
- ` <span class="ptx-preview-banner-text">${Ce(e)}</span>`,
56
+ ` <span class="ptx-preview-banner-text">${Oe(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>${Ce(It)}</button>`
59
+ `<button type="button" id="ptx-preview-banner-restore" class="ptx-preview-banner-restore" hidden>${Oe(Lt)}</button>`
60
60
  ].join(`
61
61
  `);
62
62
  }
63
- function Lt() {
63
+ function $t() {
64
64
  return [
65
65
  "<style>",
66
66
  ".ptx-preview-banner {",
@@ -129,11 +129,11 @@ function Lt() {
129
129
  ].join(`
130
130
  `);
131
131
  }
132
- function $t() {
132
+ function kt() {
133
133
  return [
134
134
  "<script>",
135
135
  "(function () {",
136
- " var KEY = " + JSON.stringify(Tt) + ";",
136
+ " var KEY = " + JSON.stringify(At) + ";",
137
137
  ' var banner = document.getElementById("ptx-preview-banner");',
138
138
  ' var restore = document.getElementById("ptx-preview-banner-restore");',
139
139
  " if (!banner || !restore) { return; }",
@@ -170,39 +170,39 @@ function $t() {
170
170
  ].join(`
171
171
  `);
172
172
  }
173
- const _t = "<!--ptx-preview-banner-->", kt = "<!--/ptx-preview-banner-->", Nt = /\n?<!--ptx-preview-banner-->[\s\S]*?<!--\/ptx-preview-banner-->/;
174
- function Rt(e, t) {
175
- const n = Nt.exec(e), r = n ? e.slice(0, n.index) + e.slice(n.index + n[0].length) : e;
173
+ const Nt = "<!--ptx-preview-banner-->", Rt = "<!--/ptx-preview-banner-->", Pt = /\n?<!--ptx-preview-banner-->[\s\S]*?<!--\/ptx-preview-banner-->/;
174
+ function Ct(e, t) {
175
+ const n = Pt.exec(e), r = n ? e.slice(0, n.index) + e.slice(n.index + n[0].length) : e;
176
176
  if (!/<body[^>]*>/i.test(r))
177
177
  return r;
178
178
  const i = `
179
- ${_t}
180
- ${Lt()}
181
- ${At(t.message)}
179
+ ${Nt}
182
180
  ${$t()}
183
- ${kt}`;
181
+ ${_t(t.message)}
182
+ ${kt()}
183
+ ${Rt}`;
184
184
  return r.replace(/<body([^>]*)>/i, `<body$1>${i}`);
185
185
  }
186
- const Pt = "https://cdn.jsdelivr.net/npm/@pretextbook/pretext-html@0.17.0/assets";
186
+ const Dt = "https://cdn.jsdelivr.net/npm/@pretextbook/pretext-html@0.18.0/assets";
187
187
  let Je;
188
- function Ar(e) {
188
+ function $r(e) {
189
189
  Je = e.replace(/\/+$/, "");
190
190
  }
191
191
  function fe() {
192
- return Je ?? Pt;
192
+ return Je ?? Dt;
193
193
  }
194
- function Ge(e, t) {
194
+ function Ke(e, t) {
195
195
  return `${e.replace(/\/+$/, "")}/${t.replace(/^\/+/, "")}`;
196
196
  }
197
- const De = /* @__PURE__ */ new Map();
198
- function Ct(e) {
197
+ const Me = /* @__PURE__ */ new Map();
198
+ function Ot(e) {
199
199
  return `${e.replace(/\/+$/, "")}-bundle.json`;
200
200
  }
201
- function Dt(e) {
202
- let t = De.get(e);
201
+ function Mt(e) {
202
+ let t = Me.get(e);
203
203
  return t || (t = (async () => {
204
204
  try {
205
- const n = await fetch(Ct(e));
205
+ const n = await fetch(Ot(e));
206
206
  if (!n.ok)
207
207
  return /* @__PURE__ */ new Map();
208
208
  const r = await n.json();
@@ -210,14 +210,14 @@ function Dt(e) {
210
210
  } catch {
211
211
  return /* @__PURE__ */ new Map();
212
212
  }
213
- })(), De.set(e, t)), t;
213
+ })(), Me.set(e, t)), t;
214
214
  }
215
- function Mt(e) {
216
- return e === Ge(fe(), "xsl");
215
+ function Bt(e) {
216
+ return e === Ke(fe(), "xsl");
217
217
  }
218
- async function Ke(e, t) {
219
- if (Mt(e)) {
220
- const o = (await Dt(e)).get(t.replace(/^\/+/, ""));
218
+ async function Ye(e, t) {
219
+ if (Bt(e)) {
220
+ const o = (await Mt(e)).get(t.replace(/^\/+/, ""));
221
221
  if (o !== void 0)
222
222
  return new TextEncoder().encode(o);
223
223
  }
@@ -241,7 +241,7 @@ async function Ke(e, t) {
241
241
  return;
242
242
  }
243
243
  }
244
- async function Ot(e) {
244
+ async function jt(e) {
245
245
  if (/^[a-z][a-z0-9+.-]*:\/\//i.test(e))
246
246
  try {
247
247
  const t = await fetch(e);
@@ -250,42 +250,42 @@ async function Ot(e) {
250
250
  return;
251
251
  }
252
252
  }
253
- const Ye = "2.55.0", Bt = "8.3.3", jt = [
253
+ const qe = "2.55.0", Ut = "8.3.3", Ft = [
254
254
  "prefix-runtime.dd07797f77620576.bundle.js",
255
255
  "prefix-926.5c7038c8ef173faf.bundle.js",
256
256
  "prefix-runestone.11d27cdc38930c2c.bundle.js"
257
- ], Ut = [
257
+ ], Wt = [
258
258
  "prefix-926.229729d09512acc9.css",
259
259
  "prefix-runestone.347e2ecdeacfed99.css"
260
- ], Ft = "born-hidden-knowl", Wt = /<details\b([^>]*)>(\s*)(?:<summary\b([^>]*)>)?/g;
261
- function Ht(e) {
260
+ ], Ht = "born-hidden-knowl", Vt = /<details\b([^>]*)>(\s*)(?:<summary\b([^>]*)>)?/g;
261
+ function Xt(e) {
262
262
  const t = /\bclass="([^"]*)"/.exec(e);
263
263
  return t ? t[1].trim().split(/\s+/) : [];
264
264
  }
265
- function Vt(e) {
265
+ function zt(e) {
266
266
  return /(^|\s)open(\s|=|$)/.test(e);
267
267
  }
268
- function Me(e) {
269
- return Vt(e) ? e : ` open${e}`;
268
+ function Be(e) {
269
+ return zt(e) ? e : ` open${e}`;
270
270
  }
271
- function Xt(e) {
271
+ function Gt(e) {
272
272
  return e.replace(
273
- Wt,
273
+ Vt,
274
274
  (t, n, r, i) => {
275
- if (!Ht(n).includes(Ft))
275
+ if (!Xt(n).includes(Ht))
276
276
  return t;
277
- const o = `<details${Me(n)}>`;
278
- return i === void 0 ? `${o}${r}` : `${o}${r}<summary${Me(i)}>`;
277
+ const o = `<details${Be(n)}>`;
278
+ return i === void 0 ? `${o}${r}` : `${o}${r}<summary${Be(i)}>`;
279
279
  }
280
280
  );
281
281
  }
282
- const _e = /* @__PURE__ */ new Map(), qe = /* @__PURE__ */ new Map();
283
- let Ae, zt = 0, Ze = Ke;
284
- function Lr(e) {
285
- Ze = e;
282
+ const ke = /* @__PURE__ */ new Map(), Ze = /* @__PURE__ */ new Map();
283
+ let Le, Jt = 0, Qe = Ye;
284
+ function kr(e) {
285
+ Qe = e;
286
286
  }
287
- function Jt(e, t) {
288
- const n = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, r = qe.get(n);
287
+ function Kt(e, t) {
288
+ const n = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, r = Ze.get(n);
289
289
  if (r !== void 0)
290
290
  return Promise.resolve(new Response(r, { status: 200 }));
291
291
  let i;
@@ -294,62 +294,62 @@ function Jt(e, t) {
294
294
  } catch {
295
295
  i = "";
296
296
  }
297
- const o = _e.get(i);
298
- return o !== void 0 ? Kt(o, n) : Ae(e, t);
297
+ const o = ke.get(i);
298
+ return o !== void 0 ? qt(o, n) : Le(e, t);
299
299
  }
300
- const Gt = '<?xml version="1.0"?><pretext-preview-missing-file/>';
301
- async function Kt(e, t) {
302
- const n = decodeURIComponent(new URL(t).pathname), r = await Ze(e, n);
300
+ const Yt = '<?xml version="1.0"?><pretext-preview-missing-file/>';
301
+ async function qt(e, t) {
302
+ const n = decodeURIComponent(new URL(t).pathname), r = await Qe(e, n);
303
303
  if (r === void 0)
304
- return new Response(Gt, { status: 200 });
304
+ return new Response(Yt, { status: 200 });
305
305
  const i = typeof r == "string" ? r : new Uint8Array(r);
306
306
  return new Response(i, { status: 200 });
307
307
  }
308
- function Qe() {
309
- Ae || (Ae = globalThis.fetch, globalThis.fetch = Jt);
308
+ function et() {
309
+ Le || (Le = globalThis.fetch, globalThis.fetch = Kt);
310
310
  }
311
- function et(e) {
312
- Qe();
313
- const t = `mnt${++zt}.ptx.invalid`;
314
- return _e.set(t, e), `http://${t}`;
311
+ function tt(e) {
312
+ et();
313
+ const t = `mnt${++Jt}.ptx.invalid`;
314
+ return ke.set(t, e), `http://${t}`;
315
315
  }
316
- function Yt(e) {
317
- _e.delete(new URL(e).host);
316
+ function Zt(e) {
317
+ ke.delete(new URL(e).host);
318
318
  }
319
- function qt(e, t) {
320
- Qe(), qe.set(e, t);
319
+ function Qt(e, t) {
320
+ et(), Ze.set(e, t);
321
321
  }
322
- const Zt = /<a\b[^>]*\bdata-printout="[^"]*"[^>]*>/gi;
323
- function ue(e, t) {
322
+ const en = /<a\b[^>]*\bdata-printout="[^"]*"[^>]*>/gi;
323
+ function le(e, t) {
324
324
  const n = new RegExp(`\\b${t}="([^"]*)"`, "i").exec(e);
325
- return n ? Qt(n[1]) : void 0;
325
+ return n ? tn(n[1]) : void 0;
326
326
  }
327
- function Qt(e) {
327
+ function tn(e) {
328
328
  return e.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&apos;|&#39;/g, "'").replace(/&#x27;/gi, "'").replace(/&amp;/g, "&");
329
329
  }
330
- function en(e, t, n) {
330
+ function nn(e, t, n) {
331
331
  const r = [e, t].filter(Boolean).join(" ");
332
332
  return r && n ? `${r}: ${n}` : r || n;
333
333
  }
334
- function tt(e) {
334
+ function nt(e) {
335
335
  const t = [], n = /* @__PURE__ */ new Set();
336
- for (const [r] of e.matchAll(Zt)) {
337
- const i = ue(r, "data-printout");
336
+ for (const [r] of e.matchAll(en)) {
337
+ const i = le(r, "data-printout");
338
338
  if (!i || n.has(i))
339
339
  continue;
340
340
  n.add(i);
341
- const o = ue(r, "data-printout-type") ?? "", a = ue(r, "data-printout-number") ?? "", l = ue(r, "data-printout-title") ?? "";
341
+ const o = le(r, "data-printout-type") ?? "", a = le(r, "data-printout-number") ?? "", l = le(r, "data-printout-title") ?? "";
342
342
  t.push({
343
343
  id: i,
344
344
  type: o,
345
345
  number: a,
346
346
  title: l,
347
- label: en(o, a, l)
347
+ label: nn(o, a, l)
348
348
  });
349
349
  }
350
350
  return t;
351
351
  }
352
- const tn = /* @__PURE__ */ new Set([
352
+ const rn = /* @__PURE__ */ new Set([
353
353
  "worksheet",
354
354
  "handout",
355
355
  "project",
@@ -357,17 +357,17 @@ const tn = /* @__PURE__ */ new Set([
357
357
  "exploration",
358
358
  "investigation"
359
359
  ]);
360
- function nn(e, t) {
361
- if (!(!t || !tn.has(t)))
360
+ function on(e, t) {
361
+ if (!(!t || !rn.has(t)))
362
362
  return e[0]?.id;
363
363
  }
364
- const rn = "__ptxPrintPreview";
365
- function on(e) {
364
+ const sn = "__ptxPrintPreview";
365
+ function an(e) {
366
366
  const t = JSON.stringify(e ?? null);
367
367
  return [
368
368
  "<script>",
369
369
  "(function () {",
370
- " var KEY = " + JSON.stringify(rn) + ";",
370
+ " var KEY = " + JSON.stringify(sn) + ";",
371
371
  " window[KEY] = " + t + ";",
372
372
  // Pin the page to light mode for the print layout; see printPreviewCss.
373
373
  // `data-darkmode="disabled"` is upstream's own switch — pretext-core.js
@@ -402,7 +402,7 @@ function on(e) {
402
402
  ].join(`
403
403
  `);
404
404
  }
405
- function sn() {
405
+ function cn() {
406
406
  return [
407
407
  "<style>",
408
408
  ":root {",
@@ -422,19 +422,19 @@ function sn() {
422
422
  ].join(`
423
423
  `);
424
424
  }
425
- const an = "<!--ptx-print-preview-->", cn = "<!--/ptx-print-preview-->", ln = /\n?<!--ptx-print-preview-->[\s\S]*?<!--\/ptx-print-preview-->/;
426
- function un(e, t) {
427
- const n = ln.exec(e), r = n ? e.slice(0, n.index) + e.slice(n.index + n[0].length) : e, i = /<head[^>]*>/i.exec(r);
425
+ const ln = "<!--ptx-print-preview-->", un = "<!--/ptx-print-preview-->", fn = /\n?<!--ptx-print-preview-->[\s\S]*?<!--\/ptx-print-preview-->/;
426
+ function dn(e, t) {
427
+ const n = fn.exec(e), r = n ? e.slice(0, n.index) + e.slice(n.index + n[0].length) : e, i = /<head[^>]*>/i.exec(r);
428
428
  if (!i)
429
429
  return r;
430
- const o = t && tt(r).some((h) => h.id === t) ? t : void 0, a = `
431
- ${an}
432
- ${on(o)}
433
- ${o ? `${sn()}
434
- ` : ""}${cn}`, l = i.index + i[0].length;
430
+ const o = t && nt(r).some((d) => d.id === t) ? t : void 0, a = `
431
+ ${ln}
432
+ ${an(o)}
433
+ ${o ? `${cn()}
434
+ ` : ""}${un}`, l = i.index + i[0].length;
435
435
  return r.slice(0, l) + a + r.slice(l);
436
436
  }
437
- const de = `<?xml version="1.0" encoding="UTF-8"?>
437
+ const Ne = `<?xml version="1.0" encoding="UTF-8"?>
438
438
  <publication>
439
439
  <source>
440
440
  <directories external="../assets" generated="../generated-assets" />
@@ -442,35 +442,37 @@ const de = `<?xml version="1.0" encoding="UTF-8"?>
442
442
  <common>
443
443
  <tableofcontents level="0"/>
444
444
  </common>
445
- <html>
446
- <platform portable="yes"/>
447
- </html>
448
445
  </publication>
449
- `, fn = ["theme", "style", "shell"];
450
- function j(e, t) {
446
+ `, hn = [
447
+ [["html", "resources"], "host", "cdn"],
448
+ [["html", "platform"], "portable", "no"],
449
+ [["html", "cross-references"], "knowled", "never"],
450
+ [["common", "chunking"], "level", "0"]
451
+ ], pn = ["theme", "style", "shell"];
452
+ function O(e, t) {
451
453
  for (const n of e.children)
452
454
  if (n.type === "element" && n.name === t)
453
455
  return n;
454
456
  }
455
457
  function ee(e, t) {
456
- let n = j(e, t);
458
+ let n = O(e, t);
457
459
  return n || (n = { type: "element", name: t, attributes: {}, children: [] }, e.children.push(n)), n;
458
460
  }
459
- function dn(e, t) {
460
- const n = j(e, "css");
461
- if (n && fn.some((i) => n.attributes?.[i]))
461
+ function mn(e, t) {
462
+ const n = O(e, "css");
463
+ if (n && pn.some((i) => n.attributes?.[i]))
462
464
  return;
463
465
  const r = n ?? ee(e, "css");
464
466
  r.attributes = { ...r.attributes, theme: t };
465
467
  }
466
- function hn(e, t) {
467
- const n = j(e, "appearance");
468
+ function vn(e, t) {
469
+ const n = O(e, "appearance");
468
470
  if (n?.attributes?.theme)
469
471
  return;
470
472
  const r = n ?? ee(e, "appearance");
471
473
  r.attributes = { ...r.attributes, theme: t };
472
474
  }
473
- function pn(e) {
475
+ function wn(e) {
474
476
  const t = ee(e, "resources");
475
477
  t.attributes = {
476
478
  ...t.attributes,
@@ -478,70 +480,82 @@ function pn(e) {
478
480
  math: "online"
479
481
  };
480
482
  }
481
- function mn(e, t = {}) {
482
- const n = t.cssTheme?.trim(), r = t.revealTheme?.trim(), i = t.target === "slides";
483
- if (!e && !n && !i)
484
- return de;
485
- const o = oe(e ?? de), a = j(o, "publication");
483
+ function rt(e, t = {}) {
484
+ const n = t.cssTheme?.trim(), r = t.revealTheme?.trim(), i = t.target === "slides", o = ne(e ?? Ne), a = O(o, "publication");
486
485
  if (!a)
487
486
  throw new Error(
488
487
  "Invalid publication file: no root <publication> element found"
489
488
  );
490
- const l = ee(a, "html"), h = ee(l, "platform");
491
- if (h.attributes = { ...h.attributes, portable: "yes" }, n && dn(l, n), i) {
492
- const p = ee(a, "revealjs");
493
- pn(p), r && hn(p, r);
489
+ for (const [d, p, m] of hn) {
490
+ const h = d.reduce(
491
+ (T, x) => ee(T, x),
492
+ a
493
+ );
494
+ h.attributes = { ...h.attributes, [p]: m };
495
+ }
496
+ const l = ee(a, "html");
497
+ if (n && mn(l, n), i) {
498
+ const d = ee(a, "revealjs");
499
+ wn(d), r && vn(d, r);
494
500
  }
495
501
  return te(o);
496
502
  }
497
- function Oe(e) {
503
+ const Nr = rt, bn = "generated/";
504
+ function Ee(e) {
498
505
  if (!(e === void 0 || e === "" || e.startsWith("/")))
499
506
  return e.endsWith("/") ? e : `${e}/`;
500
507
  }
501
- function Be(e) {
508
+ function je(e) {
502
509
  const t = e?.attributes?.level;
503
510
  if (t == null || t === "") return;
504
511
  const n = Number(t);
505
512
  return Number.isFinite(n) && n >= 0 ? n : void 0;
506
513
  }
507
- function wn(e) {
508
- const t = oe(e ?? de), n = j(t, "publication"), r = n && j(n, "common"), i = r && j(r, "tableofcontents"), o = n && j(n, "numbering");
514
+ function gn(e) {
515
+ const t = ne(e ?? Ne), n = O(t, "publication"), r = n && O(n, "common"), i = r && O(r, "tableofcontents"), o = n && O(n, "numbering");
509
516
  let a, l;
510
- for (const h of o?.children ?? []) {
511
- if (h.type !== "element") continue;
512
- const p = Be(h);
513
- p !== void 0 && (h.name === "divisions" ? l = p : a = Math.max(a ?? 0, p));
517
+ for (const d of o?.children ?? []) {
518
+ if (d.type !== "element") continue;
519
+ const p = je(d);
520
+ p !== void 0 && (d.name === "divisions" ? l = p : a = Math.max(a ?? 0, p));
514
521
  }
515
522
  return {
516
- tocLevel: Be(i),
523
+ tocLevel: je(i),
517
524
  numberingLevel: a,
518
525
  maxNumberingLevel: l
519
526
  };
520
527
  }
521
- function vn(e) {
522
- const t = oe(e ?? de), n = j(t, "publication"), r = n && j(n, "source"), i = r && j(r, "directories"), o = Oe(
523
- i?.attributes?.external ?? void 0
524
- ), a = Oe(
525
- i?.attributes?.generated ?? void 0
526
- );
527
- return {
528
- external: o,
529
- generated: a,
530
- managed: o !== void 0 && a !== void 0
531
- };
528
+ function yn(e, t) {
529
+ const n = ne(e ?? Ne), r = O(n, "publication"), i = r && O(r, "source"), o = i && O(i, "directories"), a = (p) => {
530
+ const m = o?.attributes?.[p];
531
+ return m == null ? void 0 : String(m);
532
+ }, l = Ee(t !== void 0 ? t : a("external")), d = Ee(a("generated")) ?? bn;
533
+ return l === void 0 ? { generated: d } : { external: l, generated: d };
532
534
  }
533
- function $r(e) {
535
+ function ue(e) {
536
+ if (typeof e == "string")
537
+ try {
538
+ return ue(ne(e));
539
+ } catch {
540
+ return;
541
+ }
542
+ const t = e.children.find(
543
+ (o) => o.type === "element"
544
+ ), n = t?.name === "docinfo" ? t : t && O(t, "docinfo"), i = (n && O(n, "directories"))?.attributes?.external;
545
+ return i == null ? void 0 : String(i);
546
+ }
547
+ function Rr(e) {
534
548
  return e === "slides" || e === "scroll";
535
549
  }
536
- const nt = 960, rt = 700, bn = 1, gn = 0.04;
537
- function yn(e) {
538
- const t = typeof e == "number" && isFinite(e) ? e : bn, n = Math.min(1, Math.max(0.25, t));
550
+ const it = 960, ot = 700, En = 1, xn = 0.04;
551
+ function Sn(e) {
552
+ const t = typeof e == "number" && isFinite(e) ? e : En, n = Math.min(1, Math.max(0.25, t));
539
553
  return {
540
- width: Math.round(nt / n),
541
- height: Math.round(rt / n)
554
+ width: Math.round(it / n),
555
+ height: Math.round(ot / n)
542
556
  };
543
557
  }
544
- function En(e) {
558
+ function Tn(e) {
545
559
  return {
546
560
  view: "scroll",
547
561
  scrollLayout: "compact",
@@ -551,11 +565,11 @@ function En(e) {
551
565
  controls: !1,
552
566
  controlsTutorial: !1,
553
567
  hash: !1,
554
- ...yn(e.zoom),
555
- margin: gn
568
+ ...Sn(e.zoom),
569
+ margin: xn
556
570
  };
557
571
  }
558
- function xn() {
572
+ function In() {
559
573
  return {
560
574
  // Explicitly null rather than absent: the same page may have been
561
575
  // delivered in scroll view a moment ago, and an embedder that re-injects
@@ -567,11 +581,11 @@ function xn() {
567
581
  // size with a percentage width renders its text far larger, relative to
568
582
  // the slide, than the same deck will on a projector. No zoom margin
569
583
  // though — presenting means filling whatever it is shown in.
570
- width: nt,
571
- height: rt
584
+ width: it,
585
+ height: ot
572
586
  };
573
587
  }
574
- const Sn = [
588
+ const An = [
575
589
  "<style>",
576
590
  ".reveal-viewport.reveal-scroll .scroll-page section {",
577
591
  " box-shadow: inset 0 0 0 calc(1px / var(--slide-scale, 1))",
@@ -579,14 +593,14 @@ const Sn = [
579
593
  "}",
580
594
  "</style>"
581
595
  ].join(`
582
- `), Tn = [
596
+ `), Ln = [
583
597
  " var paused = document.querySelectorAll('.reveal .fragment');",
584
598
  " for (var i = 0; i < paused.length; i++) {",
585
599
  " paused[i].classList.remove('fragment');",
586
600
  " }"
587
601
  ];
588
- function In(e, t = {}) {
589
- const n = e === "scroll" ? En(t) : xn();
602
+ function _n(e, t = {}) {
603
+ const n = e === "scroll" ? Tn(t) : In();
590
604
  return [
591
605
  "<script>",
592
606
  "(function () {",
@@ -614,7 +628,7 @@ function In(e, t = {}) {
614
628
  // Inside the wrapper rather than at top level: this script sits in <head>,
615
629
  // where the slides have not been parsed yet, but the deck calls initialize
616
630
  // from the end of the document, by which time they have.
617
- ...e === "scroll" ? Tn : [],
631
+ ...e === "scroll" ? Ln : [],
618
632
  " return initialize(merged);",
619
633
  " };",
620
634
  "})();",
@@ -622,35 +636,35 @@ function In(e, t = {}) {
622
636
  ].join(`
623
637
  `);
624
638
  }
625
- const An = /<script\b[^>]*\bsrc=["'][^"']*\breveal\.js["'][^>]*>\s*<\/script>/i, Ln = "<!--ptx-reveal-view-->", $n = "<!--/ptx-reveal-view-->", _n = /\n?<!--ptx-reveal-view-->[\s\S]*?<!--\/ptx-reveal-view-->/;
626
- function kn(e, t, n = {}) {
627
- const r = _n.exec(e), i = r ? e.slice(0, r.index) + e.slice(r.index + r[0].length) : e, o = An.exec(i);
639
+ const $n = /<script\b[^>]*\bsrc=["'][^"']*\breveal\.js["'][^>]*>\s*<\/script>/i, kn = "<!--ptx-reveal-view-->", Nn = "<!--/ptx-reveal-view-->", Rn = /\n?<!--ptx-reveal-view-->[\s\S]*?<!--\/ptx-reveal-view-->/;
640
+ function Pn(e, t, n = {}) {
641
+ const r = Rn.exec(e), i = r ? e.slice(0, r.index) + e.slice(r.index + r[0].length) : e, o = $n.exec(i);
628
642
  if (!o)
629
643
  return i;
630
644
  const a = o.index + o[0].length, l = `
631
- ${Ln}
632
- ${Sn}
633
- ${In(t, n)}
634
- ${$n}`;
645
+ ${kn}
646
+ ${An}
647
+ ${_n(t, n)}
648
+ ${Nn}`;
635
649
  return i.slice(0, a) + l + i.slice(a);
636
650
  }
637
- const it = "http://www.w3.org/2001/XInclude", je = 64;
638
- async function be(e, t) {
639
- return (e?.readSource ? await e.readSource(t) : void 0) ?? await Ot(t);
651
+ const st = "http://www.w3.org/2001/XInclude", Ue = 64;
652
+ async function we(e, t) {
653
+ return (e?.readSource ? await e.readSource(t) : void 0) ?? await jt(t);
640
654
  }
641
- function ke(e, t, n) {
642
- return e.cache ? e.cache.parse(t, n) : oe(n);
655
+ function Re(e, t, n) {
656
+ return e.cache ? e.cache.parse(t, n) : ne(n);
643
657
  }
644
- async function Ne(e, t, n, r = {}) {
645
- const i = E(t), o = ke(r, i, e), a = {
658
+ async function Pe(e, t, n, r = {}) {
659
+ const i = S(t), o = Re(r, i, e), a = {
646
660
  ...r,
647
- projectDir: E(n),
661
+ projectDir: S(n),
648
662
  stack: [i],
649
663
  files: [i],
650
664
  bytes: e.length
651
- }, l = await ie(
665
+ }, l = await oe(
652
666
  o,
653
- Y(i),
667
+ K(i),
654
668
  { "": "" },
655
669
  a
656
670
  );
@@ -661,43 +675,43 @@ async function Ne(e, t, n, r = {}) {
661
675
  bytes: a.bytes
662
676
  };
663
677
  }
664
- function ot(e) {
678
+ function at(e) {
665
679
  return e.data?.ptxIncludedFile;
666
680
  }
667
- function st(e, t) {
681
+ function ct(e, t) {
668
682
  const n = e.data ?? (e.data = {});
669
683
  n.ptxIncludedFile = t;
670
684
  }
671
- function he(e, t) {
685
+ function de(e, t) {
672
686
  let n = e;
673
687
  for (const [r, i] of Object.entries(t.attributes))
674
688
  (r === "xmlns" || r.startsWith("xmlns:")) && (n === e && (n = { ...e }), n[r === "xmlns" ? "" : r.slice(6)] = i ?? "");
675
689
  return n;
676
690
  }
677
- function at(e, t) {
691
+ function lt(e, t) {
678
692
  const n = e.name.indexOf(":"), r = n === -1 ? "" : e.name.slice(0, n);
679
- return (n === -1 ? e.name : e.name.slice(n + 1)) === "include" && t[r] === it;
693
+ return (n === -1 ? e.name : e.name.slice(n + 1)) === "include" && t[r] === st;
680
694
  }
681
- async function ie(e, t, n, r) {
695
+ async function oe(e, t, n, r) {
682
696
  let i = !1;
683
697
  for (let o = 0; o < e.children.length; o++) {
684
698
  const a = e.children[o];
685
699
  if (a.type !== "element")
686
700
  continue;
687
- const l = he(n, a);
688
- if (at(a, l)) {
689
- const h = await ct(
701
+ const l = de(n, a);
702
+ if (lt(a, l)) {
703
+ const d = await ut(
690
704
  a,
691
705
  t,
692
706
  l,
693
707
  r
694
708
  );
695
- e.children.splice(o, 1, ...h), o += h.length - 1, i = !0;
696
- } else await ie(a, t, l, r) && (i = !0);
709
+ e.children.splice(o, 1, ...d), o += d.length - 1, i = !0;
710
+ } else await oe(a, t, l, r) && (i = !0);
697
711
  }
698
712
  return i;
699
713
  }
700
- async function ct(e, t, n, r) {
714
+ async function ut(e, t, n, r) {
701
715
  const i = r.stack[r.stack.length - 1];
702
716
  if (e.attributes.xpointer)
703
717
  throw new Error(
@@ -711,8 +725,8 @@ async function ct(e, t, n, r) {
711
725
  a = decodeURIComponent(o);
712
726
  } catch {
713
727
  }
714
- const l = E(t, a);
715
- if (l !== r.projectDir && !l.startsWith(r.projectDir + Ie))
728
+ const l = S(t, a);
729
+ if (l !== r.projectDir && !l.startsWith(r.projectDir + Ae))
716
730
  throw new Error(
717
731
  `xi:include escapes the project directory: ${o} (in ${i})`
718
732
  );
@@ -720,69 +734,69 @@ async function ct(e, t, n, r) {
720
734
  throw new Error(
721
735
  `Circular xi:include: ${[...r.stack, l].join(" -> ")}`
722
736
  );
723
- if (r.stack.length >= je)
724
- throw new Error(`xi:include nesting exceeds ${je} levels`);
725
- const h = await be(r, l);
726
- if (h === void 0) {
727
- const d = Rn(e, n);
728
- if (d)
729
- return await ie(d, t, n, r), d.children;
737
+ if (r.stack.length >= Ue)
738
+ throw new Error(`xi:include nesting exceeds ${Ue} levels`);
739
+ const d = await we(r, l);
740
+ if (d === void 0) {
741
+ const h = Dn(e, n);
742
+ if (h)
743
+ return await oe(h, t, n, r), h.children;
730
744
  throw new Error(`xi:include target not found: ${o} (in ${i})`);
731
745
  }
732
- if (r.files.includes(l) || r.files.push(l), r.bytes += h.length, e.attributes.parse === "text")
733
- return [{ type: "text", value: h }];
746
+ if (r.files.includes(l) || r.files.push(l), r.bytes += d.length, e.attributes.parse === "text")
747
+ return [{ type: "text", value: d }];
734
748
  let p;
735
749
  try {
736
- p = ke(r, l, h);
737
- } catch (d) {
750
+ p = Re(r, l, d);
751
+ } catch (h) {
738
752
  throw new Error(
739
- `Could not parse xi:include target ${l} as XML: ${d instanceof Error ? d.message : d}. (Included files must be well-formed, with a single root element.)`
753
+ `Could not parse xi:include target ${l} as XML: ${h instanceof Error ? h.message : h}. (Included files must be well-formed, with a single root element.)`
740
754
  );
741
755
  }
742
756
  r.stack.push(l);
743
757
  try {
744
- await ie(p, Y(l), { "": "" }, r);
758
+ await oe(p, K(l), { "": "" }, r);
745
759
  } finally {
746
760
  r.stack.pop();
747
761
  }
748
- const w = p.children.filter(
749
- (d) => d.type === "element"
762
+ const m = p.children.filter(
763
+ (h) => h.type === "element"
750
764
  );
751
- for (const d of w)
752
- st(d, l);
753
- return w;
765
+ for (const h of m)
766
+ ct(h, l);
767
+ return m;
754
768
  }
755
- function Ue(e) {
769
+ function Fe(e) {
756
770
  return e.name === "docinfo";
757
771
  }
758
- async function Nn(e, t, n, r = {}) {
772
+ async function Cn(e, t, n, r = {}) {
759
773
  try {
760
- const i = E(t), a = ke(r, i, e).children.find(
761
- (w) => w.type === "element"
774
+ const i = S(t), a = Re(r, i, e).children.find(
775
+ (m) => m.type === "element"
762
776
  );
763
777
  if (!a)
764
778
  return;
765
- const l = Y(i), h = {
779
+ const l = K(i), d = {
766
780
  ...r,
767
- projectDir: E(n),
781
+ projectDir: S(n),
768
782
  stack: [i],
769
783
  files: [i],
770
784
  bytes: e.length
771
- }, p = he({ "": "" }, a);
772
- for (const w of a.children) {
773
- if (w.type !== "element")
785
+ }, p = de({ "": "" }, a);
786
+ for (const m of a.children) {
787
+ if (m.type !== "element")
774
788
  continue;
775
- const d = he(p, w);
776
- if (Ue(w))
777
- return await ie(w, l, d, h), te(w);
778
- if (at(w, d)) {
779
- const x = (await ct(
780
- w,
789
+ const h = de(p, m);
790
+ if (Fe(m))
791
+ return await oe(m, l, h, d), te(m);
792
+ if (lt(m, h)) {
793
+ const x = (await ut(
794
+ m,
781
795
  l,
782
- d,
783
- h
796
+ h,
797
+ d
784
798
  )).find(
785
- (_) => _.type === "element" && Ue(_)
799
+ (_) => _.type === "element" && Fe(_)
786
800
  );
787
801
  if (x)
788
802
  return te(x);
@@ -795,24 +809,24 @@ async function Nn(e, t, n, r = {}) {
795
809
  return;
796
810
  }
797
811
  }
798
- function Rn(e, t) {
812
+ function Dn(e, t) {
799
813
  for (const n of e.children) {
800
814
  if (n.type !== "element")
801
815
  continue;
802
- const r = he(t, n), i = n.name.indexOf(":"), o = i === -1 ? "" : n.name.slice(0, i);
803
- if ((i === -1 ? n.name : n.name.slice(i + 1)) === "fallback" && r[o] === it)
816
+ const r = de(t, n), i = n.name.indexOf(":"), o = i === -1 ? "" : n.name.slice(0, i);
817
+ if ((i === -1 ? n.name : n.name.slice(i + 1)) === "fallback" && r[o] === st)
804
818
  return n;
805
819
  }
806
820
  }
807
- function lt(e) {
821
+ function ft(e) {
808
822
  return typeof e == "object" && e !== null && e.type === "element";
809
823
  }
810
- function Pn(e) {
824
+ function On(e) {
811
825
  return /^(pf|xhtml):/.test(e.name);
812
826
  }
813
- function Cn(e, t, n) {
827
+ function Mn(e, t, n) {
814
828
  const r = [];
815
- return ut(e, t, n, (i, o, a, l) => {
829
+ return dt(e, t, n, (i, o, a, l) => {
816
830
  r.push({
817
831
  id: o,
818
832
  file: a,
@@ -823,36 +837,36 @@ function Cn(e, t, n) {
823
837
  });
824
838
  }), r;
825
839
  }
826
- function Dn(e, t, n) {
840
+ function Bn(e, t, n) {
827
841
  let r;
828
- return ut(e, "", n, (i, o) => {
842
+ return dt(e, "", n, (i, o) => {
829
843
  if (i === t)
830
844
  return r = o, !1;
831
845
  }), r;
832
846
  }
833
- function ut(e, t, n, r) {
834
- const i = e.children.find(lt);
847
+ function dt(e, t, n, r) {
848
+ const i = e.children.find(ft);
835
849
  if (i) {
836
850
  const o = n?.parentId ?? "root";
837
- ft(i, o, n?.position ?? 1, t, o, r);
851
+ ht(i, o, n?.position ?? 1, t, o, r);
838
852
  }
839
853
  }
840
- function ft(e, t, n, r, i, o) {
841
- const a = ot(e) ?? r;
842
- let l, h;
843
- if (Pn(e))
844
- h = "root";
854
+ function ht(e, t, n, r, i, o) {
855
+ const a = at(e) ?? r;
856
+ let l, d;
857
+ if (On(e))
858
+ d = "root";
845
859
  else {
846
- const w = e.attributes.label ?? e.attributes["xml:id"];
847
- if (l = w ?? `${t}-${n}`, o(e, l, a, i) === !1)
860
+ const m = e.attributes.label ?? e.attributes["xml:id"];
861
+ if (l = m ?? `${t}-${n}`, o(e, l, a, i) === !1)
848
862
  return !1;
849
- h = l;
863
+ d = l;
850
864
  }
851
865
  let p = 0;
852
- for (const w of e.children)
853
- if (lt(w) && (p += 1, !ft(
854
- w,
855
- h,
866
+ for (const m of e.children)
867
+ if (ft(m) && (p += 1, !ht(
868
+ m,
869
+ d,
856
870
  p,
857
871
  a,
858
872
  l ?? i,
@@ -861,28 +875,28 @@ function ft(e, t, n, r, i, o) {
861
875
  return !1;
862
876
  return !0;
863
877
  }
864
- function _r(e, t) {
878
+ function Pr(e, t) {
865
879
  let n;
866
880
  for (const r of e)
867
881
  r.line <= t && (n = r);
868
882
  return n ?? e[0];
869
883
  }
870
- function Mn(e) {
884
+ function jn(e) {
871
885
  const t = e.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!\[CDATA\[[\s\S]*?\]\]>/g, " ");
872
886
  return /<\s*slide(?:show)?[\s/>]/.test(t) ? "slides" : "html";
873
887
  }
874
- const dt = "pretext-html:set-theme";
875
- function kr(e) {
888
+ const pt = "pretext-html:set-theme";
889
+ function Cr(e) {
876
890
  return e === "dark" || e === "light" || e === "system";
877
891
  }
878
- function Nr(e) {
879
- return { type: dt, theme: e };
892
+ function Dr(e) {
893
+ return { type: pt, theme: e };
880
894
  }
881
- function On(e) {
895
+ function Un(e) {
882
896
  return [
883
897
  "<script>",
884
898
  "(function () {",
885
- " var CFG = " + JSON.stringify({ msg: dt, initial: e }) + ";",
899
+ " var CFG = " + JSON.stringify({ msg: pt, initial: e }) + ";",
886
900
  // Where the last requested theme is remembered so it survives an in-place
887
901
  // document rewrite (same Window) and outranks the baked initial value.
888
902
  " var KEY = '__ptxPreviewTheme';",
@@ -952,12 +966,12 @@ function On(e) {
952
966
  ].join(`
953
967
  `);
954
968
  }
955
- function Bn(e, t) {
956
- const n = On(t);
969
+ function Fn(e, t) {
970
+ const n = Un(t);
957
971
  return /<head[^>]*>/i.test(e) ? e.replace(/<head([^>]*)>/i, `<head$1>
958
972
  ${n}`) : e;
959
973
  }
960
- const ht = /* @__PURE__ */ new Set([
974
+ const mt = /* @__PURE__ */ new Set([
961
975
  "colophon",
962
976
  "biography",
963
977
  "dedication",
@@ -977,89 +991,89 @@ const ht = /* @__PURE__ */ new Set([
977
991
  "glossary",
978
992
  "worksheet",
979
993
  "handout"
980
- ]), pt = /* @__PURE__ */ new Set([
994
+ ]), vt = /* @__PURE__ */ new Set([
981
995
  "book",
982
996
  "article",
983
997
  "slideshow",
984
998
  "letter",
985
999
  "memo"
986
1000
  ]), z = /* @__PURE__ */ new Set([
987
- ...pt,
988
- ...ht,
1001
+ ...vt,
1002
+ ...mt,
989
1003
  "part",
990
1004
  "foreword",
991
1005
  "frontmatter",
992
1006
  "backmatter"
993
1007
  ]);
994
- function ge(e) {
1008
+ function be(e) {
995
1009
  return z.has(e.name);
996
1010
  }
997
- const jn = /* @__PURE__ */ new Set(["docinfo"]), mt = /* @__PURE__ */ new Set([
1011
+ const Wn = /* @__PURE__ */ new Set(["docinfo"]), wt = /* @__PURE__ */ new Set([
998
1012
  "title",
999
1013
  "shorttitle",
1000
1014
  "plaintitle",
1001
1015
  "subtitle",
1002
1016
  "caption"
1003
1017
  ]);
1004
- function N(e) {
1018
+ function R(e) {
1005
1019
  return e.type === "element";
1006
1020
  }
1007
- function wt(e) {
1021
+ function bt(e) {
1008
1022
  return e.attributes["xml:id"] ?? void 0;
1009
1023
  }
1010
- function pe(e, t) {
1024
+ function he(e, t) {
1011
1025
  for (const n of e.children) {
1012
- if (!N(n)) continue;
1013
- if (wt(n) === t) return n;
1014
- const r = pe(n, t);
1026
+ if (!R(n)) continue;
1027
+ if (bt(n) === t) return n;
1028
+ const r = he(n, t);
1015
1029
  if (r) return r;
1016
1030
  }
1017
1031
  }
1018
1032
  function X(e, t) {
1019
1033
  for (const n of e.children) {
1020
- if (!N(n)) continue;
1034
+ if (!R(n)) continue;
1021
1035
  if (n === t) return [n];
1022
1036
  const r = X(n, t);
1023
1037
  if (r) return [n, ...r];
1024
1038
  }
1025
1039
  }
1026
- function vt(e, t, n, r) {
1027
- return pt.has(n) ? 0 : n === "frontmatter" || n === "backmatter" || n === "part" ? t === "book" && r ? 1 : 0 : ht.has(n) ? e + 1 : e;
1040
+ function gt(e, t, n, r) {
1041
+ return vt.has(n) ? 0 : n === "frontmatter" || n === "backmatter" || n === "part" ? t === "book" && r ? 1 : 0 : mt.has(n) ? e + 1 : e;
1028
1042
  }
1029
- function me(e, t) {
1043
+ function pe(e, t) {
1030
1044
  let n = 0;
1031
1045
  for (const [r, i] of e.entries()) {
1032
1046
  const o = r === 0 ? void 0 : e[r - 1];
1033
- n = vt(n, o?.name, i.name, t);
1047
+ n = gt(n, o?.name, i.name, t);
1034
1048
  }
1035
1049
  return n;
1036
1050
  }
1037
- function Re(e) {
1051
+ function Ce(e) {
1038
1052
  return e?.name === "book" && e.children.some(
1039
- (t) => N(t) && t.name === "part"
1053
+ (t) => R(t) && t.name === "part"
1040
1054
  );
1041
1055
  }
1042
1056
  function Q(e, t) {
1043
1057
  return e.children.some(
1044
- (n) => N(n) && t.includes(n.name)
1058
+ (n) => R(n) && t.includes(n.name)
1045
1059
  );
1046
1060
  }
1047
- function Un(e) {
1061
+ function Hn(e) {
1048
1062
  if (!e) return 0;
1049
1063
  const t = e.name;
1050
1064
  if (t === "book") {
1051
- const n = Re(e), r = n ? e.children.some(
1052
- (o) => N(o) && o.name === "part" && Q(o, ["chapter"])
1065
+ const n = Ce(e), r = n ? e.children.some(
1066
+ (o) => R(o) && o.name === "part" && Q(o, ["chapter"])
1053
1067
  ) : Q(e, ["chapter"]), i = (n ? e.children.flatMap(
1054
- (o) => N(o) && o.name === "part" ? o.children : []
1068
+ (o) => R(o) && o.name === "part" ? o.children : []
1055
1069
  ) : e.children).some(
1056
- (o) => N(o) && o.name === "chapter" && Q(o, ["section"])
1070
+ (o) => R(o) && o.name === "chapter" && Q(o, ["section"])
1057
1071
  );
1058
1072
  return n && i ? 3 : n && r || i ? 2 : r ? 1 : 0;
1059
1073
  }
1060
1074
  if (t === "article") {
1061
1075
  const n = e.children.filter(
1062
- (r) => N(r) && r.name === "section"
1076
+ (r) => R(r) && r.name === "section"
1063
1077
  );
1064
1078
  if (n.some((r) => Q(r, ["subsection"])))
1065
1079
  return 2;
@@ -1068,21 +1082,21 @@ function Un(e) {
1068
1082
  }
1069
1083
  return 0;
1070
1084
  }
1071
- function Fn(e) {
1072
- return e ? e.name === "book" ? Re(e) ? 3 : 2 : e.name === "article" && Q(e, ["section", "worksheet", "handout"]) ? 1 : 0 : 0;
1085
+ function Vn(e) {
1086
+ return e ? e.name === "book" ? Ce(e) ? 3 : 2 : e.name === "article" && Q(e, ["section", "worksheet", "handout"]) ? 1 : 0 : 0;
1073
1087
  }
1074
- function Pe(e) {
1075
- if (!mt.has(e.name)) {
1076
- e.children = e.children.filter(N);
1088
+ function De(e) {
1089
+ if (!wt.has(e.name)) {
1090
+ e.children = e.children.filter(R);
1077
1091
  for (const t of e.children)
1078
- Pe(t);
1092
+ De(t);
1079
1093
  }
1080
1094
  }
1081
- function Wn(e) {
1095
+ function Xn(e) {
1082
1096
  for (const t of e.children)
1083
- N(t) && !z.has(t.name) && Pe(t);
1097
+ R(t) && !z.has(t.name) && De(t);
1084
1098
  }
1085
- function Hn(e, t = !1) {
1099
+ function zn(e, t = !1) {
1086
1100
  const n = /* @__PURE__ */ new Set(), r = (i) => {
1087
1101
  if (!(t && i !== e && z.has(i.name))) {
1088
1102
  if (i.name === "xref") {
@@ -1096,16 +1110,16 @@ function Hn(e, t = !1) {
1096
1110
  l && n.add(l);
1097
1111
  }
1098
1112
  for (const o of i.children)
1099
- N(o) && r(o);
1113
+ R(o) && r(o);
1100
1114
  }
1101
1115
  };
1102
1116
  return r(e), n;
1103
1117
  }
1104
- function Vn(e, t, n) {
1118
+ function Gn(e, t, n) {
1105
1119
  const r = (i) => {
1106
1120
  for (const [o, a] of i.children.entries())
1107
- if (N(a)) {
1108
- if (wt(a) === t)
1121
+ if (R(a)) {
1122
+ if (bt(a) === t)
1109
1123
  return i.children[o] = n, !0;
1110
1124
  if (r(a)) return !0;
1111
1125
  }
@@ -1113,88 +1127,88 @@ function Vn(e, t, n) {
1113
1127
  };
1114
1128
  return r(e);
1115
1129
  }
1116
- function bt(e, t, n) {
1130
+ function yt(e, t, n) {
1117
1131
  const r = n.contentKept.has(e), i = n.chain.has(e), o = [];
1118
1132
  for (const a of e.children) {
1119
- if (!N(a)) {
1133
+ if (!R(a)) {
1120
1134
  r && o.push(a);
1121
1135
  continue;
1122
1136
  }
1123
- if (n.verbatim.has(a) || jn.has(a.name) || mt.has(a.name))
1137
+ if (n.verbatim.has(a) || Wn.has(a.name) || wt.has(a.name))
1124
1138
  o.push(a);
1125
1139
  else if (z.has(a.name)) {
1126
- const l = vt(
1140
+ const l = gt(
1127
1141
  t,
1128
1142
  e.name,
1129
1143
  a.name,
1130
1144
  n.hasParts
1131
1145
  );
1132
- (n.chain.has(a) || i || l <= n.tocLevel) && (bt(a, l, n), o.push(a));
1146
+ (n.chain.has(a) || i || l <= n.tocLevel) && (yt(a, l, n), o.push(a));
1133
1147
  } else r && o.push(a);
1134
1148
  }
1135
1149
  e.children = o;
1136
1150
  }
1137
- function Xn(e, t, n = {}) {
1138
- const r = pe(e, t);
1151
+ function Jn(e, t, n = {}) {
1152
+ const r = he(e, t);
1139
1153
  if (!r) return;
1140
1154
  const i = X(e, r);
1141
1155
  if (!i) return;
1142
1156
  const o = (n.collapseChildren ?? !1) && r.children.some(
1143
- (g) => N(g) && z.has(g.name)
1144
- ), a = (g) => g.name === "pretext" || g.name === "mathbook", l = i.filter((g) => !a(g)), h = l[0], p = Re(h), w = me(l, p), d = (g) => {
1145
- const k = X(e, g)?.filter((S) => !a(S)) ?? [];
1146
- return me(k, p);
1147
- }, L = n.maxNumberingLevel ?? 1 / 0, x = Math.min(
1148
- n.numberingLevel ?? Fn(h),
1149
- L
1150
- ), _ = n.tocLevel ?? Un(h), T = {
1157
+ (g) => R(g) && z.has(g.name)
1158
+ ), a = (g) => g.name === "pretext" || g.name === "mathbook", l = i.filter((g) => !a(g)), d = l[0], p = Ce(d), m = pe(l, p), h = (g) => {
1159
+ const N = X(e, g)?.filter((E) => !a(E)) ?? [];
1160
+ return pe(N, p);
1161
+ }, T = n.maxNumberingLevel ?? 1 / 0, x = Math.min(
1162
+ n.numberingLevel ?? Vn(d),
1163
+ T
1164
+ ), _ = n.tocLevel ?? Hn(d), I = {
1151
1165
  verbatim: /* @__PURE__ */ new Set(),
1152
1166
  chain: new Set(i),
1153
1167
  contentKept: /* @__PURE__ */ new Set(),
1154
1168
  tocLevel: _,
1155
1169
  hasParts: p
1156
- }, F = /* @__PURE__ */ new Set(), D = /* @__PURE__ */ new Set();
1157
- o ? T.contentKept.add(r) : T.verbatim.add(r);
1158
- const q = (g) => {
1159
- const k = X(e, g);
1160
- if (!k) return;
1161
- const S = k.filter((I) => z.has(I.name)), P = S[S.length - 1];
1162
- if (!P || P === r) return;
1163
- if (i.includes(P)) {
1164
- T.contentKept.add(P), D.add(P);
1170
+ }, F = /* @__PURE__ */ new Set(), M = /* @__PURE__ */ new Set();
1171
+ o ? I.contentKept.add(r) : I.verbatim.add(r);
1172
+ const Y = (g) => {
1173
+ const N = X(e, g);
1174
+ if (!N) return;
1175
+ const E = N.filter(($) => z.has($.name)), j = E[E.length - 1];
1176
+ if (!j || j === r) return;
1177
+ if (i.includes(j)) {
1178
+ I.contentKept.add(j), M.add(j);
1165
1179
  return;
1166
1180
  }
1167
- let B = P;
1168
- for (let I = S.length - 1; I >= 0 && !(d(S[I]) <= x || i.includes(S[I - 1])); I--)
1169
- B = S[I - 1] ?? B;
1170
- if (!T.verbatim.has(B)) {
1171
- T.verbatim.add(B), F.add(B);
1172
- for (const I of X(e, B) ?? []) T.chain.add(I);
1181
+ let C = j;
1182
+ for (let $ = E.length - 1; $ >= 0 && !(h(E[$]) <= x || i.includes(E[$ - 1])); $--)
1183
+ C = E[$ - 1] ?? C;
1184
+ if (!I.verbatim.has(C)) {
1185
+ I.verbatim.add(C), F.add(C);
1186
+ for (const $ of X(e, C) ?? []) I.chain.add($);
1173
1187
  }
1174
1188
  };
1175
- for (const g of Hn(r, o)) {
1176
- const k = pe(e, g);
1177
- k && k !== r && q(k);
1189
+ for (const g of zn(r, o)) {
1190
+ const N = he(e, g);
1191
+ N && N !== r && Y(N);
1178
1192
  }
1179
- for (const g of [...T.chain]) {
1180
- if (!z.has(g.name) || d(g) <= x)
1193
+ for (const g of [...I.chain]) {
1194
+ if (!z.has(g.name) || h(g) <= x)
1181
1195
  continue;
1182
- const k = X(e, g)?.at(-2);
1183
- if (k)
1184
- for (const S of k.children) {
1185
- if (S === g) break;
1186
- !N(S) || !z.has(S.name) || T.verbatim.has(S) || T.chain.has(S) || (T.verbatim.add(S), F.add(S));
1196
+ const N = X(e, g)?.at(-2);
1197
+ if (N)
1198
+ for (const E of N.children) {
1199
+ if (E === g) break;
1200
+ !R(E) || !z.has(E.name) || I.verbatim.has(E) || I.chain.has(E) || (I.verbatim.add(E), F.add(E));
1187
1201
  }
1188
1202
  }
1189
- const O = e.children.find(N);
1190
- O && bt(O, 0, T);
1203
+ const B = e.children.find(R);
1204
+ B && yt(B, 0, I);
1191
1205
  for (const g of F)
1192
- Pe(g);
1193
- for (const g of D)
1194
- Wn(g);
1195
- return { content: te(e), divisionId: t, level: w, collapsed: o };
1206
+ De(g);
1207
+ for (const g of M)
1208
+ Xn(g);
1209
+ return { content: te(e), divisionId: t, level: m, collapsed: o };
1196
1210
  }
1197
- class zn {
1211
+ class Kn {
1198
1212
  entries = /* @__PURE__ */ new Map();
1199
1213
  maxEntries;
1200
1214
  /** Cumulative hit/miss counts, for diagnostics and tests. */
@@ -1214,15 +1228,15 @@ class zn {
1214
1228
  parse(t, n) {
1215
1229
  const r = this.entries.get(t);
1216
1230
  if (r && r.content === n)
1217
- return this.hits += 1, this.entries.delete(t), this.entries.set(t, r), Le(r.tree);
1231
+ return this.hits += 1, this.entries.delete(t), this.entries.set(t, r), _e(r.tree);
1218
1232
  this.misses += 1;
1219
- const i = oe(n);
1233
+ const i = ne(n);
1220
1234
  for (this.entries.delete(t), this.entries.set(t, { content: n, tree: i }); this.entries.size > this.maxEntries; ) {
1221
1235
  const o = this.entries.keys().next().value;
1222
1236
  if (o === void 0) break;
1223
1237
  this.entries.delete(o);
1224
1238
  }
1225
- return Le(i);
1239
+ return _e(i);
1226
1240
  }
1227
1241
  /** Number of files currently held. */
1228
1242
  get size() {
@@ -1233,86 +1247,86 @@ class zn {
1233
1247
  t === void 0 ? this.entries.clear() : this.entries.delete(t);
1234
1248
  }
1235
1249
  }
1236
- function Le(e) {
1250
+ function _e(e) {
1237
1251
  const t = { ...e };
1238
- return t.attributes && (t.attributes = { ...t.attributes }), t.children && (t.children = t.children.map((n) => Le(n))), t.data && (t.data = { ...t.data }), t;
1252
+ return t.attributes && (t.attributes = { ...t.attributes }), t.children && (t.children = t.children.map((n) => _e(n))), t.data && (t.data = { ...t.data }), t;
1239
1253
  }
1240
- function we(e) {
1254
+ function me(e) {
1241
1255
  return typeof e == "object" && e !== null && e.type === "element";
1242
1256
  }
1243
- function Jn(e) {
1257
+ function Yn(e) {
1244
1258
  for (let t = e.length - 1; t >= 0; t--)
1245
- if (ge(e[t])) return e[t];
1246
- }
1247
- function Gn(e, t, n) {
1248
- const r = [], i = (a, l, h) => {
1249
- const p = ot(a) ?? l, w = [...h, a];
1250
- p === n && ge(a) && r.push({ element: a, chain: w });
1251
- for (const d of a.children)
1252
- we(d) && i(d, p, w);
1253
- }, o = e.children.find(we);
1259
+ if (be(e[t])) return e[t];
1260
+ }
1261
+ function qn(e, t, n) {
1262
+ const r = [], i = (a, l, d) => {
1263
+ const p = at(a) ?? l, m = [...d, a];
1264
+ p === n && be(a) && r.push({ element: a, chain: m });
1265
+ for (const h of a.children)
1266
+ me(h) && i(h, p, m);
1267
+ }, o = e.children.find(me);
1254
1268
  return o && i(o, t, []), r;
1255
1269
  }
1256
- function Kn(e, t, n, r) {
1257
- const i = Gn(e, t, n);
1270
+ function Zn(e, t, n, r) {
1271
+ const i = qn(e, t, n);
1258
1272
  let o, a, l;
1259
- for (const { element: h } of i) {
1260
- const p = h.position?.start.line, w = h.position?.end.line ?? p;
1261
- p === void 0 || w === void 0 || (p <= r && r <= w ? o = h : p > r ? a ??= h : l = h);
1273
+ for (const { element: d } of i) {
1274
+ const p = d.position?.start.line, m = d.position?.end.line ?? p;
1275
+ p === void 0 || m === void 0 || (p <= r && r <= m ? o = d : p > r ? a ??= d : l = d);
1262
1276
  }
1263
1277
  return o ?? a ?? l;
1264
1278
  }
1265
- function Yn(e, t, n) {
1279
+ function Qn(e, t, n) {
1266
1280
  let r;
1267
1281
  if (t.id !== void 0) {
1268
- const d = pe(e, t.id), L = d && X(e, d);
1269
- r = L && Jn(L);
1282
+ const h = he(e, t.id), T = h && X(e, h);
1283
+ r = T && Yn(T);
1270
1284
  } else if (t.line !== void 0) {
1271
- const d = E(n), L = E(t.file ?? n);
1272
- r = Kn(e, d, L, t.line);
1285
+ const h = S(n), T = S(t.file ?? n);
1286
+ r = Zn(e, h, T, t.line);
1273
1287
  }
1274
1288
  if (!r) return;
1275
1289
  const i = t.level ?? 1 / 0;
1276
1290
  let o = !1;
1277
1291
  const l = (X(e, r) ?? [r]).filter(
1278
- (d) => d.name !== "pretext" && d.name !== "mathbook"
1279
- ), h = l[0], p = h?.name === "book" && h.children.some(
1280
- (d) => we(d) && d.name === "part"
1281
- ), w = me(l, p);
1282
- if (w > i)
1283
- for (let d = 0; d < l.length; d++) {
1284
- const L = l[d];
1285
- if (ge(L) && me(l.slice(0, d + 1), p) >= i) {
1286
- r = L;
1292
+ (h) => h.name !== "pretext" && h.name !== "mathbook"
1293
+ ), d = l[0], p = d?.name === "book" && d.children.some(
1294
+ (h) => me(h) && h.name === "part"
1295
+ ), m = pe(l, p);
1296
+ if (m > i)
1297
+ for (let h = 0; h < l.length; h++) {
1298
+ const T = l[h];
1299
+ if (be(T) && pe(l.slice(0, h + 1), p) >= i) {
1300
+ r = T;
1287
1301
  break;
1288
1302
  }
1289
1303
  }
1290
- else w < i && (o = !0);
1291
- return { element: r, id: gt(e, r), collapse: o };
1304
+ else m < i && (o = !0);
1305
+ return { element: r, id: Et(e, r), collapse: o };
1292
1306
  }
1293
- function gt(e, t) {
1307
+ function Et(e, t) {
1294
1308
  const n = t.attributes["xml:id"];
1295
1309
  if (n) return n;
1296
- const r = Dn(e, t) ?? "root-1";
1310
+ const r = Bn(e, t) ?? "root-1";
1297
1311
  return t.attributes["xml:id"] = r, r;
1298
1312
  }
1299
1313
  function ve(e) {
1300
1314
  let t = 0;
1301
1315
  for (const n of e.children)
1302
- we(n) && (t += 1 + ve(n));
1316
+ me(n) && (t += 1 + ve(n));
1303
1317
  return t;
1304
1318
  }
1305
- const qn = "This live preview shows a single division, so links into the rest of the document do not work here.", Zn = /<a\b([^>]*)>/g, Qn = /\sid="([^"]*)"/g, Ee = /\shref="([^"]*)"/, er = /\\href\{([^{}]*)\}/g, Fe = /\stitle="([^"]*)"/;
1306
- function tr(e) {
1319
+ const er = "This live preview shows a single division, so links into the rest of the document do not work here.", tr = /<a\b([^>]*)>/g, nr = /\sid="([^"]*)"/g, xe = /\shref="([^"]*)"/, rr = /\\href\{([^{}]*)\}/g, We = /\stitle="([^"]*)"/;
1320
+ function ir(e) {
1307
1321
  const t = /* @__PURE__ */ new Set();
1308
- for (const n of e.matchAll(Qn))
1322
+ for (const n of e.matchAll(nr))
1309
1323
  t.add(n[1]);
1310
1324
  return t;
1311
1325
  }
1312
- function xe(e) {
1326
+ function Se(e) {
1313
1327
  return e.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1314
1328
  }
1315
- function We(e, t) {
1329
+ function He(e, t) {
1316
1330
  if (e.startsWith("#") || e === "") return { kind: "keep" };
1317
1331
  if (/^[a-z][a-z0-9+.-]*:/i.test(e) || e.startsWith("//"))
1318
1332
  return { kind: "keep" };
@@ -1321,89 +1335,89 @@ function We(e, t) {
1321
1335
  const o = e.slice(n + 1);
1322
1336
  return t.has(o) && o !== "" ? { kind: "same-page", id: o } : { kind: "off-page", division: i, ...o ? { id: o } : {} };
1323
1337
  }
1324
- function nr(e, t = {}) {
1325
- const n = t.offPageMessage ?? qn, r = tr(e);
1326
- return e.replace(Zn, (o, a) => {
1327
- const l = Ee.exec(a);
1338
+ function or(e, t = {}) {
1339
+ const n = t.offPageMessage ?? er, r = ir(e);
1340
+ return e.replace(tr, (o, a) => {
1341
+ const l = xe.exec(a);
1328
1342
  if (!l) return o;
1329
- const h = We(l[1], r);
1330
- if (h.kind === "keep") return o;
1331
- if (h.kind === "same-page")
1332
- return `<a${a.replace(Ee, ` href="#${h.id}"`)}>`;
1333
- const p = Fe.exec(a), w = xe(n), d = p ? `${p[1]} — ${w}` : w, x = a.replace(Ee, "").replace(Fe, ""), _ = ` data-ptx-division="${xe(h.division)}"` + (h.id ? ` data-ptx-id="${xe(h.id)}"` : "");
1334
- return `<a${x} title="${d}" aria-disabled="true" style="cursor:default"${_}>`;
1335
- }).replace(er, (o, a) => {
1336
- const l = We(a, r);
1343
+ const d = He(l[1], r);
1344
+ if (d.kind === "keep") return o;
1345
+ if (d.kind === "same-page")
1346
+ return `<a${a.replace(xe, ` href="#${d.id}"`)}>`;
1347
+ const p = We.exec(a), m = Se(n), h = p ? `${p[1]} — ${m}` : m, x = a.replace(xe, "").replace(We, ""), _ = ` data-ptx-division="${Se(d.division)}"` + (d.id ? ` data-ptx-id="${Se(d.id)}"` : "");
1348
+ return `<a${x} title="${h}" aria-disabled="true" style="cursor:default"${_}>`;
1349
+ }).replace(rr, (o, a) => {
1350
+ const l = He(a, r);
1337
1351
  return l.kind === "same-page" ? `\\href{#${l.id}}` : o;
1338
1352
  });
1339
1353
  }
1340
- function rr() {
1341
- return Ge(fe(), "xsl");
1354
+ function sr() {
1355
+ return Ke(fe(), "xsl");
1342
1356
  }
1343
- function ir() {
1357
+ function ar() {
1344
1358
  return "Suspending" in WebAssembly;
1345
1359
  }
1346
- function or() {
1347
- if (!ir())
1360
+ function cr() {
1361
+ if (!ar())
1348
1362
  throw new Error(
1349
1363
  "WebAssembly JSPI is not enabled. Run Node with --experimental-wasm-jspi (or use the pretext-html CLI, which re-launches itself with the flag)."
1350
1364
  );
1351
1365
  }
1352
- function re(e) {
1366
+ function ie(e) {
1353
1367
  return e.includes("'") ? e.includes('"') ? `concat(${e.split("'").map((n) => `'${n}'`).join(`, "'", `)})` : `"${e}"` : `'${e}'`;
1354
1368
  }
1355
- function sr(e) {
1369
+ function lr(e) {
1356
1370
  return e.replace(
1357
1371
  /from '\.\/(https:\/\/[^']+)'/g,
1358
1372
  (t, n) => `from '${n}'`
1359
1373
  );
1360
1374
  }
1361
- const ar = `https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@${Ye}/dist/`, cr = {
1362
- "cli.version": Ye,
1375
+ const ur = `https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@${qe}/dist/`, fr = {
1376
+ "cli.version": qe,
1363
1377
  // Colon-delimited: pretext-runestone.xsl splits them with str:tokenize.
1364
- "rs-js": jt.join(":"),
1365
- "rs-css": Ut.join(":"),
1366
- "rs-version": Bt
1378
+ "rs-js": Ft.join(":"),
1379
+ "rs-css": Wt.join(":"),
1380
+ "rs-version": Ut
1367
1381
  };
1368
- function lr(e) {
1382
+ function dr(e) {
1369
1383
  return e.replace(
1370
1384
  /(<link\b[^>]*\bhref=["'])_static\//gi,
1371
- `$1${ar}_static/`
1385
+ `$1${ur}_static/`
1372
1386
  );
1373
1387
  }
1374
- function ur(e) {
1388
+ function hr(e) {
1375
1389
  return e.slice(0, 65536).replace(/<\?[\s\S]*?\?>/g, " ").replace(/<!--[\s\S]*?-->/g, " ").replace(/<!DOCTYPE[^>]*>/gi, " ").match(/<\s*([A-Za-z][\w:-]*)/)?.[1];
1376
1390
  }
1377
- let fr;
1378
- function dr() {
1379
- return fr ??= new zn();
1391
+ let pr;
1392
+ function mr() {
1393
+ return pr ??= new Kn();
1380
1394
  }
1381
- function yt(e) {
1395
+ function xt(e) {
1382
1396
  const t = e.files ? new Map(
1383
1397
  Object.entries(e.files).map(([o, a]) => [
1384
- E(o),
1398
+ S(o),
1385
1399
  a
1386
1400
  ])
1387
- ) : void 0, n = e.readSource, r = t || n ? async (o) => t?.get(o) ?? await n?.(o) : void 0, i = e.cache === !1 ? void 0 : e.cache ?? dr();
1401
+ ) : void 0, n = e.readSource, r = t || n ? async (o) => t?.get(o) ?? await n?.(o) : void 0, i = e.cache === !1 ? void 0 : e.cache ?? mr();
1388
1402
  return { readSource: r, cache: i };
1389
1403
  }
1390
1404
  async function $e(e, t) {
1391
- const n = await be(e, t);
1405
+ const n = await we(e, t);
1392
1406
  if (n === void 0)
1393
1407
  throw new Error(
1394
1408
  `Could not read ${t}. (In the browser build only absolute URLs are readable — pass sourceContent instead of relying on sourcePath.)`
1395
1409
  );
1396
1410
  return n;
1397
1411
  }
1398
- async function hr(e, t, n) {
1399
- const r = E(e), i = await be(n, r);
1412
+ async function vr(e, t, n) {
1413
+ const r = S(e), i = await we(n, r);
1400
1414
  if (i !== void 0)
1401
- return Nn(i, r, t, n);
1415
+ return Cn(i, r, t, n);
1402
1416
  }
1403
- async function Rr(e) {
1404
- const t = yt(e), n = E(e.sourcePath), r = E(
1405
- e.projectDir ?? Y(n)
1406
- ), i = e.sourceContent ?? await $e(t, n), o = await Ne(
1417
+ async function Or(e) {
1418
+ const t = xt(e), n = S(e.sourcePath), r = S(
1419
+ e.projectDir ?? K(n)
1420
+ ), i = e.sourceContent ?? await $e(t, n), o = await Pe(
1407
1421
  i,
1408
1422
  n,
1409
1423
  r,
@@ -1415,7 +1429,7 @@ async function Rr(e) {
1415
1429
  files: o.files
1416
1430
  };
1417
1431
  }
1418
- function pr(e, t, n, r) {
1432
+ function wr(e, t, n, r) {
1419
1433
  const i = e.replace(/^\uFEFF/, "").replace(/<\?xml[\s\S]*?\?>/, "").replace(/<!DOCTYPE[^>]*>/i, ""), o = n === "slides" ? "slideshow" : t === "chapter" || t === "part" ? "book" : "article";
1420
1434
  return `<pretext>
1421
1435
  ${r?.trim() ? `${r.trim()}
@@ -1426,15 +1440,15 @@ ${i}
1426
1440
  </pretext>
1427
1441
  `;
1428
1442
  }
1429
- async function mr(e, t, n, r, i, o) {
1443
+ async function br(e, t, n, r, i, o) {
1430
1444
  const a = e.attributes["xml:id"];
1431
1445
  if (!a) return;
1432
- const l = E(n), h = i ?? await be(o, l);
1433
- if (h === void 0) return;
1434
- let p, w, d;
1446
+ const l = S(n), d = i ?? await we(o, l);
1447
+ if (d === void 0) return;
1448
+ let p, m, h;
1435
1449
  try {
1436
- ({ tree: p, files: w, bytes: d } = await Ne(
1437
- h,
1450
+ ({ tree: p, files: m, bytes: h } = await Pe(
1451
+ d,
1438
1452
  l,
1439
1453
  r,
1440
1454
  o
@@ -1442,77 +1456,77 @@ async function mr(e, t, n, r, i, o) {
1442
1456
  } catch {
1443
1457
  return;
1444
1458
  }
1445
- if (st(e, t), !!Vn(p, a, e))
1446
- return w.includes(t) || w.push(t), { tree: p, divisionId: a, files: w, bytes: d };
1459
+ if (ct(e, t), !!Gn(p, a, e))
1460
+ return m.includes(t) || m.push(t), { tree: p, divisionId: a, files: m, bytes: h };
1447
1461
  }
1448
- let Et = !1;
1449
- function wr(e) {
1462
+ let St = !1;
1463
+ function gr(e) {
1450
1464
  return e instanceof Error && /\bAborted\(/.test(e.message);
1451
1465
  }
1452
- function vr(e) {
1466
+ function yr(e) {
1453
1467
  return e instanceof Error && /memory access|out of bounds/i.test(e.message);
1454
1468
  }
1455
- function br() {
1456
- if (Et)
1469
+ function Er() {
1470
+ if (St)
1457
1471
  throw new Error(
1458
1472
  "The WebAssembly renderer aborted earlier in this process and cannot be reused. Restart the process (or reload the page) to render again."
1459
1473
  );
1460
1474
  }
1461
- function He(e) {
1462
- if (wr(e))
1463
- throw Et = !0, new Error(
1475
+ function Ve(e) {
1476
+ if (gr(e))
1477
+ throw St = !0, new Error(
1464
1478
  "The WebAssembly renderer aborted and cannot be reused. Restart the process (or reload the page) to render again.",
1465
1479
  { cause: e }
1466
1480
  );
1467
- if (vr(e))
1481
+ if (yr(e))
1468
1482
  throw new Error(
1469
1483
  "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.",
1470
1484
  { cause: e }
1471
1485
  );
1472
1486
  }
1473
- let Se;
1474
- async function xt() {
1475
- return Se || (Se = (async () => {
1487
+ let Te;
1488
+ async function Tt() {
1489
+ return Te || (Te = (async () => {
1476
1490
  const [e, t] = await Promise.all([
1477
1491
  import("@pretextbook/libxslt-wasm"),
1478
1492
  import("@pretextbook/libxslt-wasm/exslt")
1479
1493
  ]);
1480
1494
  return t.registerAll(), e;
1481
- })()), Se;
1495
+ })()), Te;
1482
1496
  }
1483
- const Te = /* @__PURE__ */ new Map(), gr = {
1497
+ const Ie = /* @__PURE__ */ new Map(), xr = {
1484
1498
  html: "preview-html.xsl",
1485
1499
  slides: "preview-revealjs.xsl"
1486
1500
  };
1487
- async function yr(e, t) {
1488
- const n = gr[t], r = `${t}\0${e}`;
1489
- let i = Te.get(r);
1501
+ async function Sr(e, t) {
1502
+ const n = xr[t], r = `${t}\0${e}`;
1503
+ let i = Ie.get(r);
1490
1504
  return i || (i = (async () => {
1491
- const { XmlDocument: o, XsltStylesheet: a } = await xt(), l = et(e), h = await Ke(fe(), `/${n}`);
1492
- if (h === void 0)
1505
+ const { XmlDocument: o, XsltStylesheet: a } = await Tt(), l = tt(e), d = await Ye(fe(), `/${n}`);
1506
+ if (d === void 0)
1493
1507
  throw new Error(
1494
1508
  `Could not read ${n} from ${fe()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
1495
1509
  );
1496
- const p = new TextDecoder().decode(h), w = await o.fromString(p, {
1510
+ const p = new TextDecoder().decode(d), m = await o.fromString(p, {
1497
1511
  url: `${l}/${n}`,
1498
1512
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
1499
1513
  });
1500
- return a.fromXmlDocument(w);
1501
- })(), Te.set(r, i), i.catch(() => Te.delete(r))), i;
1502
- }
1503
- let Ve = Promise.resolve();
1504
- function Pr(e) {
1505
- const t = Ve.then(
1506
- () => Xe(e),
1507
- () => Xe(e)
1514
+ return a.fromXmlDocument(m);
1515
+ })(), Ie.set(r, i), i.catch(() => Ie.delete(r))), i;
1516
+ }
1517
+ let Xe = Promise.resolve();
1518
+ function Mr(e) {
1519
+ const t = Xe.then(
1520
+ () => ze(e),
1521
+ () => ze(e)
1508
1522
  );
1509
- return Ve = t.catch(() => {
1523
+ return Xe = t.catch(() => {
1510
1524
  }), t;
1511
1525
  }
1512
- async function Xe(e) {
1513
- or(), br();
1514
- const { XmlDocument: t } = await xt(), n = yt(e), r = E(e.sourcePath), i = E(
1515
- e.projectDir ?? Y(r)
1526
+ async function ze(e) {
1527
+ cr(), Er();
1528
+ const { XmlDocument: t } = await Tt(), n = xt(e), r = S(e.sourcePath), i = S(
1529
+ e.projectDir ?? K(r)
1516
1530
  ), o = e.sourceContent ?? await $e(n, r), a = ye(i, r);
1517
1531
  if (a.startsWith(".."))
1518
1532
  throw new Error(
@@ -1520,140 +1534,141 @@ async function Xe(e) {
1520
1534
  );
1521
1535
  const l = ye(
1522
1536
  i,
1523
- E(e.mainSourcePath ?? r)
1524
- ), h = l.startsWith("..") ? a : l, p = et(i);
1537
+ S(e.mainSourcePath ?? r)
1538
+ ), d = l.startsWith("..") ? a : l, p = tt(i);
1525
1539
  try {
1526
- let w, d = `${p}/__pretext-preview-publication.xml`;
1540
+ let m, h = `${p}/__pretext-preview-publication.xml`;
1527
1541
  if (e.publicationPath) {
1528
- const s = E(e.publicationPath);
1529
- w = await $e(n, s);
1530
- const c = ye(i, s);
1531
- c.startsWith("..") || (d = `${p}/${c.split(Ie).join("/")}`);
1542
+ const s = S(e.publicationPath);
1543
+ m = await $e(n, s);
1544
+ const u = ye(i, s);
1545
+ u.startsWith("..") || (h = `${p}/${u.split(Ae).join("/")}`);
1532
1546
  }
1533
- const L = await Ne(
1547
+ const T = await Pe(
1534
1548
  o,
1535
1549
  r,
1536
1550
  i,
1537
1551
  n
1538
1552
  );
1539
- let x = L.tree, _ = L.content, T = L.files, F = L.bytes;
1540
- const D = e.target ?? Mn(_), q = await yr(e.xslDir ?? rr(), D), O = mn(w, {
1553
+ let x = T.tree, _ = T.content, I = T.files, F = T.bytes;
1554
+ const M = e.target ?? jn(_), Y = await Sr(e.xslDir ?? sr(), M), B = rt(m, {
1541
1555
  cssTheme: e.cssTheme,
1542
1556
  revealTheme: e.revealTheme,
1543
- target: D
1557
+ target: M
1544
1558
  });
1545
- qt(d, O);
1546
- const g = vn(O), k = Y(E(i, h)), S = g.external !== void 0 && g.generated !== void 0 ? {
1547
- external: E(k, g.external),
1548
- generated: E(k, g.generated)
1549
- } : void 0, P = ur(_);
1550
- let B = { parentId: "root", position: 1 }, I, se = r, J;
1551
- const ae = (s, c) => {
1552
- J = { bytes: F, elements: ve(s), files: T };
1553
- const u = e.subtree ? Yn(s, e.subtree, r) : void 0, f = u?.id ?? c;
1554
- if (!f) return !1;
1555
- const b = e.subtree?.wholeDocumentUpTo;
1556
- if (b !== void 0 && J.elements <= b) return !1;
1557
- const v = u?.collapse && u.element ? u.element.children.filter(
1558
- (y) => y.type === "element" && ge(y)
1559
- ).map((y) => gt(s, y)) : [], m = Xn(s, f, {
1560
- collapseChildren: u?.collapse,
1561
- ...wn(O)
1559
+ Qt(h, B);
1560
+ const g = hr(_);
1561
+ let N = { parentId: "root", position: 1 }, E, j = r, C, $;
1562
+ const se = (s, u) => {
1563
+ C = { bytes: F, elements: ve(s), files: I };
1564
+ const f = e.subtree ? Qn(s, e.subtree, r) : void 0, b = f?.id ?? u;
1565
+ if (!b) return !1;
1566
+ const w = e.subtree?.wholeDocumentUpTo;
1567
+ if (w !== void 0 && C.elements <= w) return !1;
1568
+ const v = f?.collapse && f.element ? f.element.children.filter(
1569
+ (k) => k.type === "element" && be(k)
1570
+ ).map((k) => Et(s, k)) : [], y = Jn(s, b, {
1571
+ collapseChildren: f?.collapse,
1572
+ ...gn(B)
1562
1573
  });
1563
- return m ? (_ = m.content, I = {
1564
- id: m.divisionId,
1565
- level: m.level,
1566
- collapsed: m.collapsed,
1567
- children: m.collapsed ? v : []
1574
+ return y ? (_ = y.content, E = {
1575
+ id: y.divisionId,
1576
+ level: y.level,
1577
+ collapsed: y.collapsed,
1578
+ children: y.collapsed ? v : []
1568
1579
  }, !0) : !1;
1569
1580
  };
1570
- if (P !== "pretext" && P !== "mathbook") {
1581
+ if (g !== "pretext" && g !== "mathbook") {
1571
1582
  if (!e.fragment)
1572
1583
  throw new Error(
1573
- `The document root is <${P ?? "?"}>, not <pretext> — this looks like an xi:included fragment. Render the project's main source file instead, or pass the fragment option.`
1584
+ `The document root is <${g ?? "?"}>, not <pretext> — this looks like an xi:included fragment. Render the project's main source file instead, or pass the fragment option.`
1574
1585
  );
1575
1586
  let s = !1;
1576
1587
  if (e.contextSourcePath || e.contextSourceContent) {
1577
- const c = e.contextSourcePath ?? St(Y(r), "__pretext-preview-context.ptx"), u = x.children.find(
1578
- (b) => b.type === "element"
1579
- ), f = u ? await mr(
1580
- u,
1588
+ const u = e.contextSourcePath ?? It(K(r), "__pretext-preview-context.ptx"), f = x.children.find(
1589
+ (w) => w.type === "element"
1590
+ ), b = f ? await br(
1591
+ f,
1581
1592
  r,
1582
- c,
1593
+ u,
1583
1594
  i,
1584
1595
  e.contextSourceContent,
1585
1596
  n
1586
1597
  ) : void 0;
1587
- f && (s = !0, x = f.tree, T = f.files, F = f.bytes, se = E(c), ae(x, f.divisionId) || (_ = te(x)));
1598
+ b && (s = !0, x = b.tree, $ = ue(x), I = b.files, F = b.bytes, j = S(u), se(x, b.divisionId) || (_ = te(x)));
1588
1599
  }
1589
1600
  if (!s) {
1590
- const c = e.docinfo ?? (e.docinfoSourcePath ? await hr(
1601
+ const u = e.docinfo ?? (e.docinfoSourcePath ? await vr(
1591
1602
  e.docinfoSourcePath,
1592
1603
  i,
1593
1604
  n
1594
1605
  ) : void 0);
1595
- _ = pr(
1606
+ _ = wr(
1596
1607
  _,
1597
- P,
1598
- D,
1599
- c
1600
- ), B = { parentId: c?.trim() ? "root-1-2" : "root-1-1", position: 2 };
1608
+ g,
1609
+ M,
1610
+ u
1611
+ ), $ = u === void 0 ? void 0 : ue(u), N = { parentId: u?.trim() ? "root-1-2" : "root-1-1", position: 2 };
1601
1612
  }
1602
- } else e.subtree && ae(x);
1603
- J ??= { bytes: F, elements: ve(x), files: T };
1604
- const ce = e.sourceMap ? Cn(x, se, B) : void 0, ne = await t.fromString(_, {
1605
- url: `${p}/${h.split(Ie).join("/")}`,
1613
+ } else
1614
+ $ = ue(x), e.subtree && se(x);
1615
+ C ??= { bytes: F, elements: ve(x), files: I };
1616
+ const q = yn(B, $), ae = K(S(i, d)), ge = {
1617
+ generated: S(ae, q.generated),
1618
+ ...q.external !== void 0 ? { external: S(ae, q.external) } : {}
1619
+ }, re = e.sourceMap ? Mn(x, j, N) : void 0, Z = await t.fromString(_, {
1620
+ url: `${p}/${d.split(Ae).join("/")}`,
1606
1621
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
1607
- }), W = {
1608
- publisher: re(d)
1622
+ }), H = {
1623
+ publisher: ie(h)
1609
1624
  };
1610
- for (const [s, c] of Object.entries(cr))
1611
- W[s] = re(c);
1612
- I && (W.subtree = re(I.id), W["subtree-level"] = re(
1613
- String(I.level + (I.collapsed ? 1 : 0))
1625
+ for (const [s, u] of Object.entries(fr))
1626
+ H[s] = ie(u);
1627
+ E && (H.subtree = ie(E.id), H["subtree-level"] = ie(
1628
+ String(E.level + (E.collapsed ? 1 : 0))
1614
1629
  ));
1615
- for (const [s, c] of Object.entries(e.stringParams ?? {}))
1616
- W[s] = re(c);
1617
- let Z;
1630
+ for (const [s, u] of Object.entries(e.stringParams ?? {}))
1631
+ H[s] = ie(u);
1632
+ let c;
1618
1633
  try {
1619
- Z = await q.apply(ne, W);
1634
+ c = await Y.apply(Z, H);
1620
1635
  } catch (s) {
1621
- throw He(s), new Error(
1636
+ throw Ve(s), new Error(
1622
1637
  "PreTeXt XSLT transform failed; see the PTX:ERROR/PTX:FATAL messages on stderr for details.",
1623
1638
  { cause: s }
1624
1639
  );
1625
1640
  } finally {
1626
- ne.delete();
1641
+ Z.delete();
1627
1642
  }
1628
1643
  try {
1629
- let s = sr(Z.toHtmlString());
1630
- s = nr(s, {
1644
+ let s = lr(c.toHtmlString());
1645
+ s = or(s, {
1631
1646
  ...e.offPageMessage !== void 0 ? { offPageMessage: e.offPageMessage } : {}
1632
- }), (e.openKnowls ?? !0) && (s = Xt(s)), D === "slides" ? (s = lr(s), s = kn(s, e.revealView ?? "scroll", {
1647
+ }), (e.openKnowls ?? !0) && (s = Gt(s)), M === "slides" ? (s = dr(s), s = Pn(s, e.revealView ?? "scroll", {
1633
1648
  zoom: e.revealZoom
1634
- })) : e.theme && (s = Bn(s, e.theme)), e.previewBanner && (s = Rt(s, e.previewBanner));
1635
- const c = D === "slides" ? [] : tt(s), u = nn(c, P);
1636
- return e.printPreview && (s = un(s, e.printPreview)), {
1649
+ })) : e.theme && (s = Fn(s, e.theme)), e.previewBanner && (s = Ct(s, e.previewBanner));
1650
+ const u = M === "slides" ? [] : nt(s), f = on(u, g);
1651
+ return e.printPreview && (s = dn(s, e.printPreview)), {
1637
1652
  html: s,
1638
- target: D,
1639
- printouts: c,
1640
- size: J,
1641
- ...I ? { subtree: I } : {},
1642
- ...ce ? { sourceMap: ce } : {},
1643
- ...S ? { assetDirs: S } : {},
1644
- ...u ? { rootPrintout: u } : {}
1653
+ target: M,
1654
+ printouts: u,
1655
+ size: C,
1656
+ assetDirs: ge,
1657
+ ...E ? { subtree: E } : {},
1658
+ ...re ? { sourceMap: re } : {},
1659
+ ...f ? { rootPrintout: f } : {}
1645
1660
  };
1646
1661
  } catch (s) {
1647
- throw He(s), s;
1662
+ throw Ve(s), s;
1648
1663
  } finally {
1649
- Z.delete();
1664
+ c.delete();
1650
1665
  }
1651
1666
  } finally {
1652
- Yt(p);
1667
+ Zt(p);
1653
1668
  }
1654
1669
  }
1655
- const Er = "__ptxLivePatch";
1656
- function xr(e, t, n) {
1670
+ const Tr = "__ptxLivePatch";
1671
+ function Ir(e, t, n) {
1657
1672
  const r = "script, #latex-macros, [data-component], .ptx-runestone-container", i = /* @__PURE__ */ new Set([
1658
1673
  "BODY",
1659
1674
  "MAIN",
@@ -1712,257 +1727,257 @@ function xr(e, t, n) {
1712
1727
  "U",
1713
1728
  "VAR",
1714
1729
  "WBR"
1715
- ]), a = ["clipboardable"], l = 25e4, h = 3, p = [], w = /* @__PURE__ */ new Map();
1716
- function d(s) {
1717
- return { bail: s };
1730
+ ]), a = ["clipboardable"], l = 25e4, d = 3, p = [], m = /* @__PURE__ */ new Map();
1731
+ function h(c) {
1732
+ return { bail: c };
1718
1733
  }
1719
- function L(s) {
1720
- return typeof s == "object" && s !== null && typeof s.bail == "string";
1734
+ function T(c) {
1735
+ return typeof c == "object" && c !== null && typeof c.bail == "string";
1721
1736
  }
1722
- function x(s) {
1723
- return s.matches(r) || s.querySelector(r) !== null;
1737
+ function x(c) {
1738
+ return c.matches(r) || c.querySelector(r) !== null;
1724
1739
  }
1725
- function _(s) {
1726
- return s.tagName === "SCRIPT" && !s.hasAttribute("src") && (s.textContent ?? "").indexOf("ptx_lunr_docs") !== -1;
1740
+ function _(c) {
1741
+ return c.tagName === "SCRIPT" && !c.hasAttribute("src") && (c.textContent ?? "").indexOf("ptx_lunr_docs") !== -1;
1727
1742
  }
1728
- function T(s) {
1729
- if (!i.has(s.tagName) || s.matches(".process-math") || // Never looked inside: a change anywhere in one is a change to it.
1730
- s.matches(r))
1743
+ function I(c) {
1744
+ if (!i.has(c.tagName) || c.matches(".process-math") || // Never looked inside: a change anywhere in one is a change to it.
1745
+ c.matches(r))
1731
1746
  return !1;
1732
- for (const c of Array.from(s.childNodes))
1733
- if (c.nodeType === h && /\S/.test(c.nodeValue ?? ""))
1747
+ for (const s of Array.from(c.childNodes))
1748
+ if (s.nodeType === d && /\S/.test(s.nodeValue ?? ""))
1734
1749
  return !1;
1735
- if (s.tagName === "DIV" || s.tagName === "LI") {
1736
- for (const c of Array.from(s.children))
1737
- if (o.has(c.tagName.toUpperCase()))
1750
+ if (c.tagName === "DIV" || c.tagName === "LI") {
1751
+ for (const s of Array.from(c.children))
1752
+ if (o.has(s.tagName.toUpperCase()))
1738
1753
  return !1;
1739
1754
  }
1740
1755
  return !0;
1741
1756
  }
1742
- function F(s) {
1743
- return a.indexOf(s) !== -1;
1757
+ function F(c) {
1758
+ return a.indexOf(c) !== -1;
1744
1759
  }
1745
- function D(s, c) {
1746
- if (s.tagName !== c.tagName)
1760
+ function M(c, s) {
1761
+ if (c.tagName !== s.tagName)
1747
1762
  return !1;
1748
- const u = c.getAttribute("id");
1749
- if (u !== null && s.getAttribute("id") !== u)
1763
+ const u = s.getAttribute("id");
1764
+ if (u !== null && c.getAttribute("id") !== u)
1750
1765
  return !1;
1751
- for (const f of Array.from(c.classList))
1766
+ for (const f of Array.from(s.classList))
1752
1767
  if (!F(f))
1753
- return s.classList.contains(f);
1768
+ return c.classList.contains(f);
1754
1769
  return !0;
1755
1770
  }
1756
- function q(s, c) {
1757
- const u = Array.from(s.children), f = [];
1771
+ function Y(c, s) {
1772
+ const u = Array.from(c.children), f = [];
1758
1773
  let b = 0;
1759
- for (const v of c) {
1760
- let m = null;
1761
- for (; !m && b < u.length; ) {
1774
+ for (const w of s) {
1775
+ let v = null;
1776
+ for (; !v && b < u.length; ) {
1762
1777
  const y = u[b++];
1763
- D(y, v) ? m = { inner: y, outer: y } : y.tagName === "DIV" && a.some((M) => y.classList.contains(M)) && y.firstElementChild && D(y.firstElementChild, v) && (m = { inner: y.firstElementChild, outer: y });
1778
+ M(y, w) ? v = { inner: y, outer: y } : y.tagName === "DIV" && a.some((k) => y.classList.contains(k)) && y.firstElementChild && M(y.firstElementChild, w) && (v = { inner: y.firstElementChild, outer: y });
1764
1779
  }
1765
- if (!m)
1780
+ if (!v)
1766
1781
  return null;
1767
- f.push(m);
1782
+ f.push(v);
1768
1783
  }
1769
1784
  return f;
1770
1785
  }
1771
- function O(s, c) {
1772
- if (s.attributes.length !== c.attributes.length)
1786
+ function B(c, s) {
1787
+ if (c.attributes.length !== s.attributes.length)
1773
1788
  return !1;
1774
- for (const u of Array.from(s.attributes))
1775
- if (c.getAttributeNS(u.namespaceURI, u.localName) !== u.value)
1789
+ for (const u of Array.from(c.attributes))
1790
+ if (s.getAttributeNS(u.namespaceURI, u.localName) !== u.value)
1776
1791
  return !1;
1777
1792
  return !0;
1778
1793
  }
1779
- function g(s) {
1780
- return s.outerHTML.replace(/<([A-Za-z][^\s/>]*)\s[^>]*>/g, "<$1>");
1794
+ function g(c) {
1795
+ return c.outerHTML.replace(/<([A-Za-z][^\s/>]*)\s[^>]*>/g, "<$1>");
1781
1796
  }
1782
- function k(s) {
1783
- let c = w.get(s);
1784
- return c === void 0 && (c = s.outerHTML.replace(/<span class="codenumber">[^<]*<\/span>/g, "").replace(/<([A-Za-z][^\s/>]*)\s[^>]*>/g, "<$1>"), w.set(s, c)), c;
1797
+ function N(c) {
1798
+ let s = m.get(c);
1799
+ return s === void 0 && (s = c.outerHTML.replace(/<span class="codenumber">[^<]*<\/span>/g, "").replace(/<([A-Za-z][^\s/>]*)\s[^>]*>/g, "<$1>"), m.set(c, s)), s;
1785
1800
  }
1786
- function S(s, c, u, f, b) {
1787
- const v = /* @__PURE__ */ new Map(), m = (H) => {
1788
- const U = k(H);
1789
- let le = v.get(U);
1790
- return le === void 0 && (le = v.size, v.set(U, le)), le;
1791
- }, y = s.slice(u, f).map(m), M = c.slice(u, b).map(m), C = y.length, $ = M.length, A = $ + 1, R = new Uint32Array((C + 1) * A);
1792
- for (let H = C - 1; H >= 0; H--)
1793
- for (let U = $ - 1; U >= 0; U--)
1794
- R[H * A + U] = y[H] === M[U] ? R[(H + 1) * A + U + 1] + 1 : Math.max(R[(H + 1) * A + U], R[H * A + U + 1]);
1801
+ function E(c, s, u, f, b) {
1802
+ const w = /* @__PURE__ */ new Map(), v = (W) => {
1803
+ const U = N(W);
1804
+ let ce = w.get(U);
1805
+ return ce === void 0 && (ce = w.size, w.set(U, ce)), ce;
1806
+ }, y = c.slice(u, f).map(v), k = s.slice(u, b).map(v), D = y.length, L = k.length, A = L + 1, P = new Uint32Array((D + 1) * A);
1807
+ for (let W = D - 1; W >= 0; W--)
1808
+ for (let U = L - 1; U >= 0; U--)
1809
+ P[W * A + U] = y[W] === k[U] ? P[(W + 1) * A + U + 1] + 1 : Math.max(P[(W + 1) * A + U], P[W * A + U + 1]);
1795
1810
  const V = [];
1796
- let G = 0, K = 0;
1797
- for (; G < C && K < $; )
1798
- y[G] === M[K] ? (V.push([u + G, u + K]), G++, K++) : R[(G + 1) * A + K] >= R[G * A + K + 1] ? G++ : K++;
1811
+ let G = 0, J = 0;
1812
+ for (; G < D && J < L; )
1813
+ y[G] === k[J] ? (V.push([u + G, u + J]), G++, J++) : P[(G + 1) * A + J] >= P[G * A + J + 1] ? G++ : J++;
1799
1814
  return V;
1800
1815
  }
1801
- function P(s, c) {
1802
- const u = c.map(() => -1);
1816
+ function j(c, s) {
1817
+ const u = s.map(() => -1);
1803
1818
  let f = 0;
1804
- for (; f < s.length && f < c.length && s[f].isEqualNode(c[f]); )
1819
+ for (; f < c.length && f < s.length && c[f].isEqualNode(s[f]); )
1805
1820
  u[f] = f, f++;
1806
- let b = s.length, v = c.length;
1807
- for (; b > f && v > f && s[b - 1].isEqualNode(c[v - 1]); )
1808
- b--, v--, u[v] = b;
1809
- const m = b - f, y = v - f;
1810
- if (m === 0 || y === 0)
1821
+ let b = c.length, w = s.length;
1822
+ for (; b > f && w > f && c[b - 1].isEqualNode(s[w - 1]); )
1823
+ b--, w--, u[w] = b;
1824
+ const v = b - f, y = w - f;
1825
+ if (v === 0 || y === 0)
1811
1826
  return u;
1812
- const M = (m > 1 || y > 1) && m * y <= l ? S(s, c, f, b, v) : [];
1813
- M.push([b, v]);
1814
- let C = f, $ = f;
1815
- for (const [A, R] of M) {
1816
- for (; C < A && $ < R; ) {
1817
- if (s[C].tagName === c[$].tagName) {
1818
- u[$++] = C++;
1827
+ const k = (v > 1 || y > 1) && v * y <= l ? E(c, s, f, b, w) : [];
1828
+ k.push([b, w]);
1829
+ let D = f, L = f;
1830
+ for (const [A, P] of k) {
1831
+ for (; D < A && L < P; ) {
1832
+ if (c[D].tagName === s[L].tagName) {
1833
+ u[L++] = D++;
1819
1834
  continue;
1820
1835
  }
1821
- let V = C + 1;
1822
- for (; V < A && s[V].tagName !== c[$].tagName; )
1836
+ let V = D + 1;
1837
+ for (; V < A && c[V].tagName !== s[L].tagName; )
1823
1838
  V++;
1824
- V < A ? C = V : $++;
1839
+ V < A ? D = V : L++;
1825
1840
  }
1826
- A < b && (u[R] = A), C = A + 1, $ = R + 1;
1841
+ A < b && (u[P] = A), D = A + 1, L = P + 1;
1827
1842
  }
1828
1843
  return u;
1829
1844
  }
1830
- function B(s, c) {
1831
- if (x(s) || x(c))
1832
- throw d(`<${c.tagName.toLowerCase()}> needs a full page load`);
1833
- return { next: c, replace: !0 };
1845
+ function C(c, s) {
1846
+ if (x(c) || x(s))
1847
+ throw h(`<${s.tagName.toLowerCase()}> needs a full page load`);
1848
+ return { next: s, replace: !0 };
1834
1849
  }
1835
- function I(s, c, u) {
1836
- O(c, u) || p.push({ live: s, old: c, next: u });
1837
- const f = Array.from(c.children), b = Array.from(u.children);
1850
+ function $(c, s, u) {
1851
+ B(s, u) || p.push({ live: c, old: s, next: u });
1852
+ const f = Array.from(s.children), b = Array.from(u.children);
1838
1853
  if (f.length !== b.length)
1839
1854
  return !1;
1840
- let v = null;
1841
- for (let m = 0; m < f.length; m++)
1842
- if (!f[m].isEqualNode(b[m]) && (v = v ?? q(s, f), !v || !I(v[m].inner, f[m], b[m])))
1855
+ let w = null;
1856
+ for (let v = 0; v < f.length; v++)
1857
+ if (!f[v].isEqualNode(b[v]) && (w = w ?? Y(c, f), !w || !$(w[v].inner, f[v], b[v])))
1843
1858
  return !1;
1844
1859
  return !0;
1845
1860
  }
1846
- function se(s, c, u) {
1847
- if (c.isEqualNode(u) || _(c) && _(u))
1848
- return { next: u, outer: s.outer };
1849
- if (c.tagName === u.tagName && T(c) && T(u)) {
1850
- const f = J(s.inner, c, u);
1861
+ function se(c, s, u) {
1862
+ if (s.isEqualNode(u) || _(s) && _(u))
1863
+ return { next: u, outer: c.outer };
1864
+ if (s.tagName === u.tagName && I(s) && I(u)) {
1865
+ const f = q(c.inner, s, u);
1851
1866
  if (f)
1852
- return O(c, u) || p.push({ live: s.inner, old: c, next: u }), { next: u, outer: s.outer, sub: f };
1853
- } else if (g(c) === g(u)) {
1867
+ return B(s, u) || p.push({ live: c.inner, old: s, next: u }), { next: u, outer: c.outer, sub: f };
1868
+ } else if (g(s) === g(u)) {
1854
1869
  const f = p.length;
1855
- if (I(s.inner, c, u)) {
1856
- if (x(c))
1857
- throw d(
1870
+ if ($(c.inner, s, u)) {
1871
+ if (x(s))
1872
+ throw h(
1858
1873
  "attributes changed inside an element that needs a full page load"
1859
1874
  );
1860
- return { next: u, outer: s.outer };
1875
+ return { next: u, outer: c.outer };
1861
1876
  }
1862
1877
  p.length = f;
1863
1878
  }
1864
- return { ...B(c, u), outer: s.outer };
1879
+ return { ...C(s, u), outer: c.outer };
1865
1880
  }
1866
- function J(s, c, u) {
1867
- const f = Array.from(c.children), b = Array.from(u.children), v = q(s, f);
1868
- if (!v)
1881
+ function q(c, s, u) {
1882
+ const f = Array.from(s.children), b = Array.from(u.children), w = Y(c, f);
1883
+ if (!w)
1869
1884
  return null;
1870
- const m = P(f, b), y = f.map(() => !1), M = [];
1871
- b.forEach(($, A) => {
1872
- const R = m[A];
1873
- if (R === -1) {
1874
- if (x($))
1875
- throw d(
1876
- `new <${$.tagName.toLowerCase()}> needs a full page load`
1885
+ const v = j(f, b), y = f.map(() => !1), k = [];
1886
+ b.forEach((L, A) => {
1887
+ const P = v[A];
1888
+ if (P === -1) {
1889
+ if (x(L))
1890
+ throw h(
1891
+ `new <${L.tagName.toLowerCase()}> needs a full page load`
1877
1892
  );
1878
- M.push({ next: $ });
1893
+ k.push({ next: L });
1879
1894
  return;
1880
1895
  }
1881
- y[R] = !0, M.push(se(v[R], f[R], $));
1896
+ y[P] = !0, k.push(se(w[P], f[P], L));
1882
1897
  });
1883
- const C = [];
1884
- return f.forEach(($, A) => {
1898
+ const D = [];
1899
+ return f.forEach((L, A) => {
1885
1900
  if (!y[A]) {
1886
- if (x($))
1887
- throw d(
1888
- `removing <${$.tagName.toLowerCase()}> needs a full page load`
1901
+ if (x(L))
1902
+ throw h(
1903
+ `removing <${L.tagName.toLowerCase()}> needs a full page load`
1889
1904
  );
1890
- C.push(v[A].outer);
1905
+ D.push(w[A].outer);
1891
1906
  }
1892
1907
  }), {
1893
- live: s,
1894
- first: v.length ? v[0].outer : null,
1895
- items: M,
1896
- removed: C
1908
+ live: c,
1909
+ first: w.length ? w[0].outer : null,
1910
+ items: k,
1911
+ removed: D
1897
1912
  };
1898
1913
  }
1899
1914
  function ae() {
1900
- const s = Array.from(t.head.children), c = Array.from(n.head.children);
1901
- if (s.length !== c.length)
1902
- throw d("the page head changed");
1915
+ const c = Array.from(t.head.children), s = Array.from(n.head.children);
1916
+ if (c.length !== s.length)
1917
+ throw h("the page head changed");
1903
1918
  let u = null;
1904
- for (let f = 0; f < s.length; f++) {
1905
- const b = s[f], v = c[f];
1906
- if (!b.isEqualNode(v)) {
1907
- if (b.tagName === "TITLE" && v.tagName === "TITLE")
1908
- u = v.textContent ?? "";
1909
- else if (b.tagName !== "META" || v.tagName !== "META")
1910
- throw d("the page head changed");
1919
+ for (let f = 0; f < c.length; f++) {
1920
+ const b = c[f], w = s[f];
1921
+ if (!b.isEqualNode(w)) {
1922
+ if (b.tagName === "TITLE" && w.tagName === "TITLE")
1923
+ u = w.textContent ?? "";
1924
+ else if (b.tagName !== "META" || w.tagName !== "META")
1925
+ throw h("the page head changed");
1911
1926
  }
1912
1927
  }
1913
1928
  return u;
1914
1929
  }
1915
- function ce(s) {
1916
- const { live: c, old: u, next: f } = s;
1917
- for (const m of Array.from(u.attributes))
1918
- m.name !== "class" && !f.hasAttributeNS(m.namespaceURI, m.localName) && c.removeAttributeNS(m.namespaceURI, m.localName);
1919
- for (const m of Array.from(f.attributes))
1920
- m.name !== "class" && u.getAttributeNS(m.namespaceURI, m.localName) !== m.value && c.setAttributeNS(m.namespaceURI, m.name, m.value);
1921
- const b = Array.from(u.classList), v = Array.from(f.classList);
1922
- for (const m of b)
1923
- v.indexOf(m) === -1 && c.classList.remove(m);
1924
- for (const m of v)
1925
- b.indexOf(m) === -1 && c.classList.add(m);
1930
+ function ge(c) {
1931
+ const { live: s, old: u, next: f } = c;
1932
+ for (const v of Array.from(u.attributes))
1933
+ v.name !== "class" && !f.hasAttributeNS(v.namespaceURI, v.localName) && s.removeAttributeNS(v.namespaceURI, v.localName);
1934
+ for (const v of Array.from(f.attributes))
1935
+ v.name !== "class" && u.getAttributeNS(v.namespaceURI, v.localName) !== v.value && s.setAttributeNS(v.namespaceURI, v.name, v.value);
1936
+ const b = Array.from(u.classList), w = Array.from(f.classList);
1937
+ for (const v of b)
1938
+ w.indexOf(v) === -1 && s.classList.remove(v);
1939
+ for (const v of w)
1940
+ b.indexOf(v) === -1 && s.classList.add(v);
1926
1941
  }
1927
- const ne = [], W = [];
1928
- function Z(s) {
1929
- let c = null;
1930
- for (const u of s.items) {
1942
+ const re = [], Z = [];
1943
+ function H(c) {
1944
+ let s = null;
1945
+ for (const u of c.items) {
1931
1946
  if (!u.outer || u.replace) {
1932
1947
  const f = e.importNode(u.next, !0);
1933
- u.outer ? (u.outer.replaceWith(f), W.push(u.outer)) : c ? c.after(f) : s.first ? s.first.before(f) : s.live.appendChild(f), ne.push(f), c = f;
1948
+ u.outer ? (u.outer.replaceWith(f), Z.push(u.outer)) : s ? s.after(f) : c.first ? c.first.before(f) : c.live.appendChild(f), re.push(f), s = f;
1934
1949
  continue;
1935
1950
  }
1936
- u.sub && Z(u.sub), c = u.outer;
1951
+ u.sub && H(u.sub), s = u.outer;
1937
1952
  }
1938
- for (const u of s.removed)
1939
- u.remove(), W.push(u);
1953
+ for (const u of c.removed)
1954
+ u.remove(), Z.push(u);
1940
1955
  }
1941
1956
  try {
1942
- const s = ae(), c = {
1957
+ const c = ae(), s = {
1943
1958
  live: e.documentElement,
1944
1959
  old: t.documentElement,
1945
1960
  next: n.documentElement
1946
1961
  };
1947
- if (O(c.old, c.next) || p.push(c), !e.body || !T(t.body) || !T(n.body))
1948
- throw d("the page body is not patchable");
1949
- const u = J(e.body, t.body, n.body);
1962
+ if (B(s.old, s.next) || p.push(s), !e.body || !I(t.body) || !I(n.body))
1963
+ throw h("the page body is not patchable");
1964
+ const u = q(e.body, t.body, n.body);
1950
1965
  if (!u)
1951
- throw d("the live page no longer matches the previous render");
1952
- return O(t.body, n.body) || p.push({ live: e.body, old: t.body, next: n.body }), p.forEach(ce), Z(u), s !== null && e.title !== s && (e.title = s), { ok: !0, added: ne, removed: W, attributeUpdates: p.length };
1953
- } catch (s) {
1954
- if (L(s))
1966
+ throw h("the live page no longer matches the previous render");
1967
+ return B(t.body, n.body) || p.push({ live: e.body, old: t.body, next: n.body }), p.forEach(ge), H(u), c !== null && e.title !== c && (e.title = c), { ok: !0, added: re, removed: Z, attributeUpdates: p.length };
1968
+ } catch (c) {
1969
+ if (T(c))
1955
1970
  return {
1956
1971
  ok: !1,
1957
- reason: s.bail,
1972
+ reason: c.bail,
1958
1973
  added: [],
1959
1974
  removed: [],
1960
1975
  attributeUpdates: 0
1961
1976
  };
1962
- throw s;
1977
+ throw c;
1963
1978
  }
1964
1979
  }
1965
- function Sr(e, t) {
1980
+ function Ar(e, t) {
1966
1981
  const n = e.MathJax, r = n && n.startup;
1967
1982
  if (!n || !r || !r.promise || typeof n.typesetPromise != "function")
1968
1983
  return Promise.resolve();
@@ -1981,49 +1996,50 @@ function Sr(e, t) {
1981
1996
  );
1982
1997
  return r.promise = a, a;
1983
1998
  }
1984
- function Cr() {
1999
+ function Br() {
1985
2000
  return [
1986
2001
  "<script>",
1987
- `window[${JSON.stringify(Er)}] = {`,
1988
- ` patchDocument: ${xr.toString()},`,
1989
- ` typeset: ${Sr.toString()}`,
2002
+ `window[${JSON.stringify(Tr)}] = {`,
2003
+ ` patchDocument: ${Ir.toString()},`,
2004
+ ` typeset: ${Ar.toString()}`,
1990
2005
  "};",
1991
2006
  "<\/script>"
1992
2007
  ].join(`
1993
2008
  `);
1994
2009
  }
1995
2010
  export {
1996
- Er as LIVE_PATCH_GLOBAL,
1997
- Tt as PREVIEW_BANNER_STORAGE_KEY,
1998
- dt as PREVIEW_THEME_MESSAGE,
1999
- rn as PRINT_PREVIEW_GLOBAL,
2000
- zn as SourceCache,
2001
- dr as defaultSourceCache,
2002
- rr as defaultXslDir,
2003
- Mn as detectRenderTarget,
2004
- _r as findSourceMapEntry,
2005
- mn as forcePortablePublication,
2006
- Rt as injectPreviewBanner,
2007
- un as injectPrintPreview,
2008
- kn as injectRevealBridge,
2009
- Bn as injectThemeBridge,
2010
- ir as isJspiAvailable,
2011
- kr as isPreviewTheme,
2012
- $r as isRevealView,
2013
- tt as listPrintouts,
2014
- Cr as livePatchScript,
2015
- Rr as measureDocument,
2016
- Xt as openBornHiddenKnowls,
2017
- xr as patchDocument,
2018
- $t as previewBannerScript,
2019
- Nr as previewThemeMessage,
2020
- on as printPreviewBridgeScript,
2021
- Pr as renderHtml,
2022
- In as revealBridgeScript,
2023
- nn as rootPrintoutId,
2024
- Ar as setAssetsBase,
2025
- Lr as setMountReader,
2026
- On as themeBridgeScript,
2027
- Sr as typesetPatch,
2028
- re as xpathStringLiteral
2011
+ Tr as LIVE_PATCH_GLOBAL,
2012
+ At as PREVIEW_BANNER_STORAGE_KEY,
2013
+ pt as PREVIEW_THEME_MESSAGE,
2014
+ sn as PRINT_PREVIEW_GLOBAL,
2015
+ Kn as SourceCache,
2016
+ mr as defaultSourceCache,
2017
+ sr as defaultXslDir,
2018
+ jn as detectRenderTarget,
2019
+ Pr as findSourceMapEntry,
2020
+ Nr as forcePortablePublication,
2021
+ rt as forcePreviewPublication,
2022
+ Ct as injectPreviewBanner,
2023
+ dn as injectPrintPreview,
2024
+ Pn as injectRevealBridge,
2025
+ Fn as injectThemeBridge,
2026
+ ar as isJspiAvailable,
2027
+ Cr as isPreviewTheme,
2028
+ Rr as isRevealView,
2029
+ nt as listPrintouts,
2030
+ Br as livePatchScript,
2031
+ Or as measureDocument,
2032
+ Gt as openBornHiddenKnowls,
2033
+ Ir as patchDocument,
2034
+ kt as previewBannerScript,
2035
+ Dr as previewThemeMessage,
2036
+ an as printPreviewBridgeScript,
2037
+ Mr as renderHtml,
2038
+ _n as revealBridgeScript,
2039
+ on as rootPrintoutId,
2040
+ $r as setAssetsBase,
2041
+ kr as setMountReader,
2042
+ Un as themeBridgeScript,
2043
+ Ar as typesetPatch,
2044
+ ie as xpathStringLiteral
2029
2045
  };