@pretextbook/pretext-html 0.15.0 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/assets/upstream.json +2 -2
  2. package/assets/xsl/entities.ent +14 -1
  3. package/assets/xsl/latex/pretext-latex-texstyle.xsl +5 -2
  4. package/assets/xsl/localizations/README.md +1 -1
  5. package/assets/xsl/localizations/af-ZA.xml +5 -6
  6. package/assets/xsl/localizations/bg-BG.xml +5 -6
  7. package/assets/xsl/localizations/ca-ES.xml +5 -6
  8. package/assets/xsl/localizations/cs-CZ.xml +5 -6
  9. package/assets/xsl/localizations/de-DE.xml +108 -108
  10. package/assets/xsl/localizations/en-US.xml +18 -17
  11. package/assets/xsl/localizations/es-ES.xml +5 -6
  12. package/assets/xsl/localizations/fi-FI.xml +5 -6
  13. package/assets/xsl/localizations/fr-CA.xml +5 -6
  14. package/assets/xsl/localizations/fr-FR.xml +5 -6
  15. package/assets/xsl/localizations/hu-HU.xml +5 -6
  16. package/assets/xsl/localizations/it-IT.xml +7 -7
  17. package/assets/xsl/localizations/ku-CKB.xml +5 -6
  18. package/assets/xsl/localizations/nl-NL.xml +5 -6
  19. package/assets/xsl/localizations/pt-BR.xml +4 -5
  20. package/assets/xsl/localizations/pt-PT.xml +4 -5
  21. package/assets/xsl/localizations/zh-HANS.xml +5 -6
  22. package/assets/xsl/pretext-assembly.xsl +154 -29
  23. package/assets/xsl/pretext-beamer.xsl +112 -10
  24. package/assets/xsl/pretext-braille-preprint.xsl +22 -3
  25. package/assets/xsl/pretext-common.xsl +117 -42
  26. package/assets/xsl/pretext-epub.xsl +74 -87
  27. package/assets/xsl/pretext-fo.xsl +115 -41
  28. package/assets/xsl/pretext-html.xsl +333 -102
  29. package/assets/xsl/pretext-latex-classic.xsl +48 -35
  30. package/assets/xsl/pretext-latex-common.xsl +160 -98
  31. package/assets/xsl/pretext-latex.xsl +12 -10
  32. package/assets/xsl/pretext-markdown.xsl +5 -3
  33. package/assets/xsl/pretext-numbers.xsl +28 -2
  34. package/assets/xsl/pretext-revealjs.xsl +44 -2
  35. package/assets/xsl/pretext-runestone-static.xsl +27 -4
  36. package/assets/xsl/pretext-runestone.xsl +112 -0
  37. package/assets/xsl/pretext-text.xsl +21 -14
  38. package/assets/xsl/publisher-variables.xsl +187 -47
  39. package/assets/xsl/support/extract-math.xsl +22 -2
  40. package/assets/xsl/support/package-math.xsl +9 -8
  41. package/assets/xsl/utilities/report-publisher-variables.xsl +4 -0
  42. package/assets/xsl-bundle.json +1 -1
  43. package/dist/{cli-ox-z2TCZ.js → cli-DzlCZymu.js} +4 -4
  44. package/dist/cli.js +1 -1
  45. package/dist/html-static.d.ts +2 -2
  46. package/dist/index.browser.d.ts +2 -0
  47. package/dist/index.browser.js +858 -514
  48. package/dist/index.d.ts +2 -0
  49. package/dist/index.js +34 -29
  50. package/dist/live-patch.d.ts +100 -0
  51. package/dist/live-patch.js +346 -0
  52. package/package.json +9 -1
@@ -1,15 +1,15 @@
1
- import { fromXml as T } from "xast-util-from-xml";
2
- import { toXml as I } from "xast-util-to-xml";
3
- const W = "/";
4
- function pe(e) {
1
+ import { fromXml as X } from "xast-util-from-xml";
2
+ import { toXml as q } from "xast-util-to-xml";
3
+ const he = "/";
4
+ function Me(e) {
5
5
  if (!e)
6
6
  return ".";
7
7
  const n = e.startsWith("/"), t = e.length > 1 && e.endsWith("/"), r = [];
8
8
  for (const o of e.split("/"))
9
9
  if (!(!o || o === ".")) {
10
10
  if (o === "..") {
11
- const s = r[r.length - 1];
12
- r.length > 0 && s !== ".." ? r.pop() : n || r.push("..");
11
+ const l = r[r.length - 1];
12
+ r.length > 0 && l !== ".." ? r.pop() : n || r.push("..");
13
13
  continue;
14
14
  }
15
15
  r.push(o);
@@ -17,7 +17,7 @@ function pe(e) {
17
17
  let i = r.join("/");
18
18
  return n && (i = `/${i}`), i ? (t && !i.endsWith("/") && (i += "/"), i) : n ? "/" : ".";
19
19
  }
20
- function h(...e) {
20
+ function I(...e) {
21
21
  let n = "";
22
22
  for (let r = e.length - 1; r >= 0; r--) {
23
23
  const i = e[r];
@@ -25,42 +25,42 @@ function h(...e) {
25
25
  break;
26
26
  }
27
27
  n.startsWith("/") || (n = `/${n}`);
28
- const t = pe(n);
28
+ const t = Me(n);
29
29
  return t.length > 1 && t.endsWith("/") ? t.slice(0, -1) : t;
30
30
  }
31
- function Ne(...e) {
31
+ function at(...e) {
32
32
  const n = e.filter(Boolean).join("/");
33
- return n ? pe(n) : ".";
33
+ return n ? Me(n) : ".";
34
34
  }
35
- function E(e) {
35
+ function H(e) {
36
36
  const n = e.replace(/\/+$/, "");
37
37
  if (!n)
38
38
  return e.startsWith("/") ? "/" : ".";
39
39
  const t = n.lastIndexOf("/");
40
40
  return t < 0 ? "." : t === 0 ? "/" : n.slice(0, t);
41
41
  }
42
- function j(e, n) {
43
- const t = h(e).split("/").filter(Boolean), r = h(n).split("/").filter(Boolean);
42
+ function ue(e, n) {
43
+ const t = I(e).split("/").filter(Boolean), r = I(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 Fe = "ptxPreviewBannerDismissed", We = "About live preview";
50
- function te(e) {
49
+ const ct = "ptxPreviewBannerDismissed", lt = "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 Ue(e) {
53
+ function ut(e) {
54
54
  return [
55
55
  '<div id="ptx-preview-banner" class="ptx-preview-banner" role="note">',
56
- ` <span class="ptx-preview-banner-text">${te(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>${te(We)}</button>`
59
+ `<button type="button" id="ptx-preview-banner-restore" class="ptx-preview-banner-restore" hidden>${Te(lt)}</button>`
60
60
  ].join(`
61
61
  `);
62
62
  }
63
- function He() {
63
+ function dt() {
64
64
  return [
65
65
  "<style>",
66
66
  ".ptx-preview-banner {",
@@ -129,11 +129,11 @@ function He() {
129
129
  ].join(`
130
130
  `);
131
131
  }
132
- function Ve() {
132
+ function ft() {
133
133
  return [
134
134
  "<script>",
135
135
  "(function () {",
136
- " var KEY = " + JSON.stringify(Fe) + ";",
136
+ " var KEY = " + JSON.stringify(ct) + ";",
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 Ve() {
170
170
  ].join(`
171
171
  `);
172
172
  }
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;
173
+ const pt = "<!--ptx-preview-banner-->", ht = "<!--/ptx-preview-banner-->", mt = /\n?<!--ptx-preview-banner-->[\s\S]*?<!--\/ptx-preview-banner-->/;
174
+ function wt(e, n) {
175
+ const t = mt.exec(e), r = t ? e.slice(0, t.index) + e.slice(t.index + t[0].length) : e;
176
176
  if (!/<body[^>]*>/i.test(r))
177
177
  return r;
178
178
  const i = `
179
- ${Xe}
180
- ${He()}
181
- ${Ue(n.message)}
182
- ${Ve()}
183
- ${Je}`;
179
+ ${pt}
180
+ ${dt()}
181
+ ${ut(n.message)}
182
+ ${ft()}
183
+ ${ht}`;
184
184
  return r.replace(/<body([^>]*)>/i, `<body$1>${i}`);
185
185
  }
186
- const Ge = "https://cdn.jsdelivr.net/npm/@pretextbook/pretext-html@0.15.0/assets";
187
- let he;
188
- function Dn(e) {
189
- he = e.replace(/\/+$/, "");
186
+ const gt = "https://cdn.jsdelivr.net/npm/@pretextbook/pretext-html@0.16.1/assets";
187
+ let Ce;
188
+ function nr(e) {
189
+ Ce = e.replace(/\/+$/, "");
190
190
  }
191
- function M() {
192
- return he ?? Ge;
191
+ function se() {
192
+ return Ce ?? gt;
193
193
  }
194
- function me(e, n) {
194
+ function Oe(e, n) {
195
195
  return `${e.replace(/\/+$/, "")}/${n.replace(/^\/+/, "")}`;
196
196
  }
197
- const ne = /* @__PURE__ */ new Map();
198
- function Ye(e) {
197
+ const Se = /* @__PURE__ */ new Map();
198
+ function vt(e) {
199
199
  return `${e.replace(/\/+$/, "")}-bundle.json`;
200
200
  }
201
- function qe(e) {
202
- let n = ne.get(e);
201
+ function bt(e) {
202
+ let n = Se.get(e);
203
203
  return n || (n = (async () => {
204
204
  try {
205
- const t = await fetch(Ye(e));
205
+ const t = await fetch(vt(e));
206
206
  if (!t.ok)
207
207
  return /* @__PURE__ */ new Map();
208
208
  const r = await t.json();
@@ -210,14 +210,14 @@ function qe(e) {
210
210
  } catch {
211
211
  return /* @__PURE__ */ new Map();
212
212
  }
213
- })(), ne.set(e, n)), n;
213
+ })(), Se.set(e, n)), n;
214
214
  }
215
- function Ze(e) {
216
- return e === me(M(), "xsl");
215
+ function Et(e) {
216
+ return e === Oe(se(), "xsl");
217
217
  }
218
- async function we(e, n) {
219
- if (Ze(e)) {
220
- const o = (await qe(e)).get(n.replace(/^\/+/, ""));
218
+ async function Be(e, n) {
219
+ if (Et(e)) {
220
+ const o = (await bt(e)).get(n.replace(/^\/+/, ""));
221
221
  if (o !== void 0)
222
222
  return new TextEncoder().encode(o);
223
223
  }
@@ -241,7 +241,7 @@ async function we(e, n) {
241
241
  return;
242
242
  }
243
243
  }
244
- async function B(e) {
244
+ async function ce(e) {
245
245
  if (/^[a-z][a-z0-9+.-]*:\/\//i.test(e))
246
246
  try {
247
247
  const n = await fetch(e);
@@ -250,42 +250,42 @@ async function B(e) {
250
250
  return;
251
251
  }
252
252
  }
253
- const ve = "2.51.0", Qe = "8.2.9", et = [
254
- "prefix-runtime.5ef53875c58b216b.bundle.js",
253
+ const je = "2.55.0", yt = "8.3.3", xt = [
254
+ "prefix-runtime.dd07797f77620576.bundle.js",
255
255
  "prefix-926.5c7038c8ef173faf.bundle.js",
256
- "prefix-runestone.c5ba0ffa5f963084.bundle.js"
257
- ], tt = [
256
+ "prefix-runestone.11d27cdc38930c2c.bundle.js"
257
+ ], Tt = [
258
258
  "prefix-926.229729d09512acc9.css",
259
- "prefix-runestone.efe427683fc41f98.css"
260
- ], nt = "born-hidden-knowl", rt = /<details\b([^>]*)>(\s*)(?:<summary\b([^>]*)>)?/g;
261
- function it(e) {
259
+ "prefix-runestone.347e2ecdeacfed99.css"
260
+ ], St = "born-hidden-knowl", At = /<details\b([^>]*)>(\s*)(?:<summary\b([^>]*)>)?/g;
261
+ function It(e) {
262
262
  const n = /\bclass="([^"]*)"/.exec(e);
263
263
  return n ? n[1].trim().split(/\s+/) : [];
264
264
  }
265
- function ot(e) {
265
+ function Lt(e) {
266
266
  return /(^|\s)open(\s|=|$)/.test(e);
267
267
  }
268
- function re(e) {
269
- return ot(e) ? e : ` open${e}`;
268
+ function Ae(e) {
269
+ return Lt(e) ? e : ` open${e}`;
270
270
  }
271
- function st(e) {
271
+ function _t(e) {
272
272
  return e.replace(
273
- rt,
273
+ At,
274
274
  (n, t, r, i) => {
275
- if (!it(t).includes(nt))
275
+ if (!It(t).includes(St))
276
276
  return n;
277
- const o = `<details${re(t)}>`;
278
- return i === void 0 ? `${o}${r}` : `${o}${r}<summary${re(i)}>`;
277
+ const o = `<details${Ae(t)}>`;
278
+ return i === void 0 ? `${o}${r}` : `${o}${r}<summary${Ae(i)}>`;
279
279
  }
280
280
  );
281
281
  }
282
- const J = /* @__PURE__ */ new Map(), ge = /* @__PURE__ */ new Map();
283
- let U, ct = 0, be = we;
284
- function Ln(e) {
285
- be = e;
282
+ const be = /* @__PURE__ */ new Map(), Ue = /* @__PURE__ */ new Map();
283
+ let me, $t = 0, Fe = Be;
284
+ function rr(e) {
285
+ Fe = e;
286
286
  }
287
- function at(e, n) {
288
- const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, r = ge.get(t);
287
+ function Rt(e, n) {
288
+ const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, r = Ue.get(t);
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 at(e, n) {
294
294
  } catch {
295
295
  i = "";
296
296
  }
297
- const o = J.get(i);
298
- return o !== void 0 ? dt(o, t) : U(e, n);
297
+ const o = be.get(i);
298
+ return o !== void 0 ? Nt(o, t) : me(e, n);
299
299
  }
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);
300
+ const kt = '<?xml version="1.0"?><pretext-preview-missing-file/>';
301
+ async function Nt(e, n) {
302
+ const t = decodeURIComponent(new URL(n).pathname), r = await Fe(e, t);
303
303
  if (r === void 0)
304
- return new Response(lt, { status: 200 });
304
+ return new Response(kt, { 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 xe() {
309
- U || (U = globalThis.fetch, globalThis.fetch = at);
308
+ function We() {
309
+ me || (me = globalThis.fetch, globalThis.fetch = Rt);
310
310
  }
311
- function Ee(e) {
312
- xe();
313
- const n = `mnt${++ct}.ptx.invalid`;
314
- return J.set(n, e), `http://${n}`;
311
+ function He(e) {
312
+ We();
313
+ const n = `mnt${++$t}.ptx.invalid`;
314
+ return be.set(n, e), `http://${n}`;
315
315
  }
316
- function ut(e) {
317
- J.delete(new URL(e).host);
316
+ function Pt(e) {
317
+ be.delete(new URL(e).host);
318
318
  }
319
- function ft(e, n) {
320
- xe(), ge.set(e, n);
319
+ function Dt(e, n) {
320
+ We(), Ue.set(e, n);
321
321
  }
322
- const pt = /<a\b[^>]*\bdata-printout="[^"]*"[^>]*>/gi;
323
- function D(e, n) {
322
+ const Mt = /<a\b[^>]*\bdata-printout="[^"]*"[^>]*>/gi;
323
+ function ie(e, n) {
324
324
  const t = new RegExp(`\\b${n}="([^"]*)"`, "i").exec(e);
325
- return t ? ht(t[1]) : void 0;
325
+ return t ? Ct(t[1]) : void 0;
326
326
  }
327
- function ht(e) {
327
+ function Ct(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 mt(e, n, t) {
330
+ function Ot(e, n, t) {
331
331
  const r = [e, n].filter(Boolean).join(" ");
332
332
  return r && t ? `${r}: ${t}` : r || t;
333
333
  }
334
- function ye(e) {
334
+ function Ve(e) {
335
335
  const n = [], t = /* @__PURE__ */ new Set();
336
- for (const [r] of e.matchAll(pt)) {
337
- const i = D(r, "data-printout");
336
+ for (const [r] of e.matchAll(Mt)) {
337
+ const i = ie(r, "data-printout");
338
338
  if (!i || t.has(i))
339
339
  continue;
340
340
  t.add(i);
341
- const o = D(r, "data-printout-type") ?? "", s = D(r, "data-printout-number") ?? "", c = D(r, "data-printout-title") ?? "";
341
+ const o = ie(r, "data-printout-type") ?? "", l = ie(r, "data-printout-number") ?? "", u = ie(r, "data-printout-title") ?? "";
342
342
  n.push({
343
343
  id: i,
344
344
  type: o,
345
- number: s,
346
- title: c,
347
- label: mt(o, s, c)
345
+ number: l,
346
+ title: u,
347
+ label: Ot(o, l, u)
348
348
  });
349
349
  }
350
350
  return n;
351
351
  }
352
- const wt = /* @__PURE__ */ new Set([
352
+ const Bt = /* @__PURE__ */ new Set([
353
353
  "worksheet",
354
354
  "handout",
355
355
  "project",
@@ -357,17 +357,17 @@ const wt = /* @__PURE__ */ new Set([
357
357
  "exploration",
358
358
  "investigation"
359
359
  ]);
360
- function vt(e, n) {
361
- if (!(!n || !wt.has(n)))
360
+ function jt(e, n) {
361
+ if (!(!n || !Bt.has(n)))
362
362
  return e[0]?.id;
363
363
  }
364
- const gt = "__ptxPrintPreview";
365
- function bt(e) {
364
+ const Ut = "__ptxPrintPreview";
365
+ function Ft(e) {
366
366
  const n = JSON.stringify(e ?? null);
367
367
  return [
368
368
  "<script>",
369
369
  "(function () {",
370
- " var KEY = " + JSON.stringify(gt) + ";",
370
+ " var KEY = " + JSON.stringify(Ut) + ";",
371
371
  " window[KEY] = " + n + ";",
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 bt(e) {
402
402
  ].join(`
403
403
  `);
404
404
  }
405
- function xt() {
405
+ function Wt() {
406
406
  return [
407
407
  "<style>",
408
408
  ":root {",
@@ -422,19 +422,19 @@ function xt() {
422
422
  ].join(`
423
423
  `);
424
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);
425
+ const Ht = "<!--ptx-print-preview-->", Vt = "<!--/ptx-print-preview-->", Xt = /\n?<!--ptx-print-preview-->[\s\S]*?<!--\/ptx-print-preview-->/;
426
+ function Jt(e, n) {
427
+ const t = Xt.exec(e), r = t ? e.slice(0, t.index) + e.slice(t.index + t[0].length) : e, i = /<head[^>]*>/i.exec(r);
428
428
  if (!i)
429
429
  return r;
430
- const o = n && ye(r).some((a) => a.id === n) ? n : void 0, s = `
431
- ${Et}
432
- ${bt(o)}
433
- ${o ? `${xt()}
434
- ` : ""}${yt}`, c = i.index + i[0].length;
435
- return r.slice(0, c) + s + r.slice(c);
436
- }
437
- const H = `<?xml version="1.0" encoding="UTF-8"?>
430
+ const o = n && Ve(r).some((m) => m.id === n) ? n : void 0, l = `
431
+ ${Ht}
432
+ ${Ft(o)}
433
+ ${o ? `${Wt()}
434
+ ` : ""}${Vt}`, u = i.index + i[0].length;
435
+ return r.slice(0, u) + l + r.slice(u);
436
+ }
437
+ const we = `<?xml version="1.0" encoding="UTF-8"?>
438
438
  <publication>
439
439
  <source>
440
440
  <directories external="../assets" generated="../generated-assets" />
@@ -446,82 +446,82 @@ const H = `<?xml version="1.0" encoding="UTF-8"?>
446
446
  <platform portable="yes"/>
447
447
  </html>
448
448
  </publication>
449
- `, $t = ["theme", "style", "shell"];
450
- function x(e, n) {
449
+ `, zt = ["theme", "style", "shell"];
450
+ function W(e, n) {
451
451
  for (const t of e.children)
452
452
  if (t.type === "element" && t.name === n)
453
453
  return t;
454
454
  }
455
- function y(e, n) {
456
- let t = x(e, n);
455
+ function V(e, n) {
456
+ let t = W(e, n);
457
457
  return t || (t = { type: "element", name: n, attributes: {}, children: [] }, e.children.push(t)), t;
458
458
  }
459
- function _t(e, n) {
460
- const t = x(e, "css");
461
- if (t && $t.some((i) => t.attributes?.[i]))
459
+ function Gt(e, n) {
460
+ const t = W(e, "css");
461
+ if (t && zt.some((i) => t.attributes?.[i]))
462
462
  return;
463
- const r = t ?? y(e, "css");
463
+ const r = t ?? V(e, "css");
464
464
  r.attributes = { ...r.attributes, theme: n };
465
465
  }
466
- function kt(e, n) {
467
- const t = x(e, "appearance");
466
+ function Kt(e, n) {
467
+ const t = W(e, "appearance");
468
468
  if (t?.attributes?.theme)
469
469
  return;
470
- const r = t ?? y(e, "appearance");
470
+ const r = t ?? V(e, "appearance");
471
471
  r.attributes = { ...r.attributes, theme: n };
472
472
  }
473
- function It(e) {
474
- const n = y(e, "resources");
473
+ function Yt(e) {
474
+ const n = V(e, "resources");
475
475
  n.attributes = {
476
476
  ...n.attributes,
477
477
  host: "cdn",
478
478
  math: "online"
479
479
  };
480
480
  }
481
- function Rt(e, n = {}) {
481
+ function qt(e, n = {}) {
482
482
  const t = n.cssTheme?.trim(), r = n.revealTheme?.trim(), i = n.target === "slides";
483
483
  if (!e && !t && !i)
484
- return H;
485
- const o = T(e ?? H), s = x(o, "publication");
486
- if (!s)
484
+ return we;
485
+ const o = X(e ?? we), l = W(o, "publication");
486
+ if (!l)
487
487
  throw new Error(
488
488
  "Invalid publication file: no root <publication> element found"
489
489
  );
490
- const c = y(s, "html"), a = y(c, "platform");
491
- if (a.attributes = { ...a.attributes, portable: "yes" }, t && _t(c, t), i) {
492
- const d = y(s, "revealjs");
493
- It(d), r && kt(d, r);
490
+ const u = V(l, "html"), m = V(u, "platform");
491
+ if (m.attributes = { ...m.attributes, portable: "yes" }, t && Gt(u, t), i) {
492
+ const f = V(l, "revealjs");
493
+ Yt(f), r && Kt(f, r);
494
494
  }
495
- return I(o);
495
+ return q(o);
496
496
  }
497
- function ie(e) {
497
+ function Ie(e) {
498
498
  if (!(e === void 0 || e === "" || e.startsWith("/")))
499
499
  return e.endsWith("/") ? e : `${e}/`;
500
500
  }
501
- function Pt(e) {
502
- const n = T(e ?? H), t = x(n, "publication"), r = t && x(t, "source"), i = r && x(r, "directories"), o = ie(
501
+ function Zt(e) {
502
+ const n = X(e ?? we), t = W(n, "publication"), r = t && W(t, "source"), i = r && W(r, "directories"), o = Ie(
503
503
  i?.attributes?.external ?? void 0
504
- ), s = ie(
504
+ ), l = Ie(
505
505
  i?.attributes?.generated ?? void 0
506
506
  );
507
507
  return {
508
508
  external: o,
509
- generated: s,
510
- managed: o !== void 0 && s !== void 0
509
+ generated: l,
510
+ managed: o !== void 0 && l !== void 0
511
511
  };
512
512
  }
513
- function Mn(e) {
513
+ function ir(e) {
514
514
  return e === "slides" || e === "scroll";
515
515
  }
516
- const Te = 960, Se = 700, Dt = 1, Lt = 0.04;
517
- function Mt(e) {
518
- const n = typeof e == "number" && isFinite(e) ? e : Dt, t = Math.min(1, Math.max(0.25, n));
516
+ const Xe = 960, Je = 700, Qt = 1, en = 0.04;
517
+ function tn(e) {
518
+ const n = typeof e == "number" && isFinite(e) ? e : Qt, t = Math.min(1, Math.max(0.25, n));
519
519
  return {
520
- width: Math.round(Te / t),
521
- height: Math.round(Se / t)
520
+ width: Math.round(Xe / t),
521
+ height: Math.round(Je / t)
522
522
  };
523
523
  }
524
- function At(e) {
524
+ function nn(e) {
525
525
  return {
526
526
  view: "scroll",
527
527
  scrollLayout: "compact",
@@ -531,11 +531,11 @@ function At(e) {
531
531
  controls: !1,
532
532
  controlsTutorial: !1,
533
533
  hash: !1,
534
- ...Mt(e.zoom),
535
- margin: Lt
534
+ ...tn(e.zoom),
535
+ margin: en
536
536
  };
537
537
  }
538
- function Bt() {
538
+ function rn() {
539
539
  return {
540
540
  // Explicitly null rather than absent: the same page may have been
541
541
  // delivered in scroll view a moment ago, and an embedder that re-injects
@@ -547,11 +547,11 @@ function Bt() {
547
547
  // size with a percentage width renders its text far larger, relative to
548
548
  // the slide, than the same deck will on a projector. No zoom margin
549
549
  // though — presenting means filling whatever it is shown in.
550
- width: Te,
551
- height: Se
550
+ width: Xe,
551
+ height: Je
552
552
  };
553
553
  }
554
- const Ot = [
554
+ const on = [
555
555
  "<style>",
556
556
  ".reveal-viewport.reveal-scroll .scroll-page section {",
557
557
  " box-shadow: inset 0 0 0 calc(1px / var(--slide-scale, 1))",
@@ -559,14 +559,14 @@ const Ot = [
559
559
  "}",
560
560
  "</style>"
561
561
  ].join(`
562
- `), jt = [
562
+ `), sn = [
563
563
  " var paused = document.querySelectorAll('.reveal .fragment');",
564
564
  " for (var i = 0; i < paused.length; i++) {",
565
565
  " paused[i].classList.remove('fragment');",
566
566
  " }"
567
567
  ];
568
- function Ct(e, n = {}) {
569
- const t = e === "scroll" ? At(n) : Bt();
568
+ function an(e, n = {}) {
569
+ const t = e === "scroll" ? nn(n) : rn();
570
570
  return [
571
571
  "<script>",
572
572
  "(function () {",
@@ -594,7 +594,7 @@ function Ct(e, n = {}) {
594
594
  // Inside the wrapper rather than at top level: this script sits in <head>,
595
595
  // where the slides have not been parsed yet, but the deck calls initialize
596
596
  // from the end of the document, by which time they have.
597
- ...e === "scroll" ? jt : [],
597
+ ...e === "scroll" ? sn : [],
598
598
  " return initialize(merged);",
599
599
  " };",
600
600
  "})();",
@@ -602,71 +602,71 @@ function Ct(e, n = {}) {
602
602
  ].join(`
603
603
  `);
604
604
  }
605
- const Nt = /<script\b[^>]*\bsrc=["'][^"']*\breveal\.js["'][^>]*>\s*<\/script>/i, Ft = "<!--ptx-reveal-view-->", Wt = "<!--/ptx-reveal-view-->", Ut = /\n?<!--ptx-reveal-view-->[\s\S]*?<!--\/ptx-reveal-view-->/;
606
- function Ht(e, n, t = {}) {
607
- const r = Ut.exec(e), i = r ? e.slice(0, r.index) + e.slice(r.index + r[0].length) : e, o = Nt.exec(i);
605
+ const cn = /<script\b[^>]*\bsrc=["'][^"']*\breveal\.js["'][^>]*>\s*<\/script>/i, ln = "<!--ptx-reveal-view-->", un = "<!--/ptx-reveal-view-->", dn = /\n?<!--ptx-reveal-view-->[\s\S]*?<!--\/ptx-reveal-view-->/;
606
+ function fn(e, n, t = {}) {
607
+ const r = dn.exec(e), i = r ? e.slice(0, r.index) + e.slice(r.index + r[0].length) : e, o = cn.exec(i);
608
608
  if (!o)
609
609
  return i;
610
- const s = o.index + o[0].length, c = `
611
- ${Ft}
612
- ${Ot}
613
- ${Ct(n, t)}
614
- ${Wt}`;
615
- return i.slice(0, s) + c + i.slice(s);
616
- }
617
- const $e = "http://www.w3.org/2001/XInclude", oe = 64;
618
- async function Vt(e, n, t) {
619
- return e.includes("include") ? (await z(e, n, t)).content : e;
620
- }
621
- async function z(e, n, t) {
622
- const r = T(e), i = {
623
- projectDir: h(t),
624
- stack: [h(n)]
625
- }, o = await R(
610
+ const l = o.index + o[0].length, u = `
611
+ ${ln}
612
+ ${on}
613
+ ${an(n, t)}
614
+ ${un}`;
615
+ return i.slice(0, l) + u + i.slice(l);
616
+ }
617
+ const ze = "http://www.w3.org/2001/XInclude", Le = 64;
618
+ async function pn(e, n, t) {
619
+ return e.includes("include") ? (await Ee(e, n, t)).content : e;
620
+ }
621
+ async function Ee(e, n, t) {
622
+ const r = X(e), i = {
623
+ projectDir: I(t),
624
+ stack: [I(n)]
625
+ }, o = await Z(
626
626
  r,
627
- E(h(n)),
627
+ H(I(n)),
628
628
  { "": "" },
629
629
  i
630
630
  );
631
- return { tree: r, content: o ? I(r) : e };
631
+ return { tree: r, content: o ? q(r) : e };
632
632
  }
633
- function Xt(e) {
633
+ function hn(e) {
634
634
  return e.data?.ptxIncludedFile;
635
635
  }
636
- function Jt(e, n) {
636
+ function mn(e, n) {
637
637
  const t = e.data ?? (e.data = {});
638
638
  t.ptxIncludedFile = n;
639
639
  }
640
- function A(e, n) {
640
+ function ae(e, n) {
641
641
  let t = e;
642
642
  for (const [r, i] of Object.entries(n.attributes))
643
643
  (r === "xmlns" || r.startsWith("xmlns:")) && (t === e && (t = { ...e }), t[r === "xmlns" ? "" : r.slice(6)] = i ?? "");
644
644
  return t;
645
645
  }
646
- function _e(e, n) {
646
+ function Ge(e, n) {
647
647
  const t = e.name.indexOf(":"), r = t === -1 ? "" : e.name.slice(0, t);
648
- return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && n[r] === $e;
648
+ return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && n[r] === ze;
649
649
  }
650
- async function R(e, n, t, r) {
650
+ async function Z(e, n, t, r) {
651
651
  let i = !1;
652
652
  for (let o = 0; o < e.children.length; o++) {
653
- const s = e.children[o];
654
- if (s.type !== "element")
653
+ const l = e.children[o];
654
+ if (l.type !== "element")
655
655
  continue;
656
- const c = A(t, s);
657
- if (_e(s, c)) {
658
- const a = await ke(
659
- s,
656
+ const u = ae(t, l);
657
+ if (Ge(l, u)) {
658
+ const m = await Ke(
659
+ l,
660
660
  n,
661
- c,
661
+ u,
662
662
  r
663
663
  );
664
- e.children.splice(o, 1, ...a), o += a.length - 1, i = !0;
665
- } else await R(s, n, c, r) && (i = !0);
664
+ e.children.splice(o, 1, ...m), o += m.length - 1, i = !0;
665
+ } else await Z(l, n, u, r) && (i = !0);
666
666
  }
667
667
  return i;
668
668
  }
669
- async function ke(e, n, t, r) {
669
+ async function Ke(e, n, t, r) {
670
670
  const i = r.stack[r.stack.length - 1];
671
671
  if (e.attributes.xpointer)
672
672
  throw new Error(
@@ -675,83 +675,83 @@ async function ke(e, n, t, r) {
675
675
  const o = e.attributes.href;
676
676
  if (!o)
677
677
  throw new Error(`xi:include without href (in ${i})`);
678
- let s = o;
678
+ let l = o;
679
679
  try {
680
- s = decodeURIComponent(o);
680
+ l = decodeURIComponent(o);
681
681
  } catch {
682
682
  }
683
- const c = h(n, s);
684
- if (c !== r.projectDir && !c.startsWith(r.projectDir + W))
683
+ const u = I(n, l);
684
+ if (u !== r.projectDir && !u.startsWith(r.projectDir + he))
685
685
  throw new Error(
686
686
  `xi:include escapes the project directory: ${o} (in ${i})`
687
687
  );
688
- if (r.stack.includes(c))
688
+ if (r.stack.includes(u))
689
689
  throw new Error(
690
- `Circular xi:include: ${[...r.stack, c].join(" -> ")}`
690
+ `Circular xi:include: ${[...r.stack, u].join(" -> ")}`
691
691
  );
692
- if (r.stack.length >= oe)
693
- throw new Error(`xi:include nesting exceeds ${oe} levels`);
694
- const a = await B(c);
695
- if (a === void 0) {
696
- const p = Kt(e, t);
697
- if (p)
698
- return await R(p, n, t, r), p.children;
692
+ if (r.stack.length >= Le)
693
+ throw new Error(`xi:include nesting exceeds ${Le} levels`);
694
+ const m = await ce(u);
695
+ if (m === void 0) {
696
+ const w = gn(e, t);
697
+ if (w)
698
+ return await Z(w, n, t, r), w.children;
699
699
  throw new Error(`xi:include target not found: ${o} (in ${i})`);
700
700
  }
701
701
  if (e.attributes.parse === "text")
702
- return [{ type: "text", value: a }];
703
- let d;
702
+ return [{ type: "text", value: m }];
703
+ let f;
704
704
  try {
705
- d = T(a);
706
- } catch (p) {
705
+ f = X(m);
706
+ } catch (w) {
707
707
  throw new Error(
708
- `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.)`
708
+ `Could not parse xi:include target ${u} as XML: ${w instanceof Error ? w.message : w}. (Included files must be well-formed, with a single root element.)`
709
709
  );
710
710
  }
711
- r.stack.push(c);
711
+ r.stack.push(u);
712
712
  try {
713
- await R(d, E(c), { "": "" }, r);
713
+ await Z(f, H(u), { "": "" }, r);
714
714
  } finally {
715
715
  r.stack.pop();
716
716
  }
717
- const u = d.children.filter(
718
- (p) => p.type === "element"
717
+ const v = f.children.filter(
718
+ (w) => w.type === "element"
719
719
  );
720
- for (const p of u)
721
- Jt(p, c);
722
- return u;
720
+ for (const w of v)
721
+ mn(w, u);
722
+ return v;
723
723
  }
724
- function se(e) {
724
+ function _e(e) {
725
725
  return e.name === "docinfo";
726
726
  }
727
- async function zt(e, n, t) {
727
+ async function wn(e, n, t) {
728
728
  try {
729
- const i = T(e).children.find(
730
- (d) => d.type === "element"
729
+ const i = X(e).children.find(
730
+ (f) => f.type === "element"
731
731
  );
732
732
  if (!i)
733
733
  return;
734
- const o = h(n), s = E(o), c = {
735
- projectDir: h(t),
734
+ const o = I(n), l = H(o), u = {
735
+ projectDir: I(t),
736
736
  stack: [o]
737
- }, a = A({ "": "" }, i);
738
- for (const d of i.children) {
739
- if (d.type !== "element")
737
+ }, m = ae({ "": "" }, i);
738
+ for (const f of i.children) {
739
+ if (f.type !== "element")
740
740
  continue;
741
- const u = A(a, d);
742
- if (se(d))
743
- return await R(d, s, u, c), I(d);
744
- if (_e(d, u)) {
745
- const f = (await ke(
746
- d,
747
- s,
748
- u,
749
- c
741
+ const v = ae(m, f);
742
+ if (_e(f))
743
+ return await Z(f, l, v, u), q(f);
744
+ if (Ge(f, v)) {
745
+ const b = (await Ke(
746
+ f,
747
+ l,
748
+ v,
749
+ u
750
750
  )).find(
751
- (w) => w.type === "element" && se(w)
751
+ (y) => y.type === "element" && _e(y)
752
752
  );
753
- if (f)
754
- return I(f);
753
+ if (b)
754
+ return q(b);
755
755
  continue;
756
756
  }
757
757
  break;
@@ -761,78 +761,78 @@ async function zt(e, n, t) {
761
761
  return;
762
762
  }
763
763
  }
764
- function Kt(e, n) {
764
+ function gn(e, n) {
765
765
  for (const t of e.children) {
766
766
  if (t.type !== "element")
767
767
  continue;
768
- const r = A(n, t), i = t.name.indexOf(":"), o = i === -1 ? "" : t.name.slice(0, i);
769
- if ((i === -1 ? t.name : t.name.slice(i + 1)) === "fallback" && r[o] === $e)
768
+ const r = ae(n, t), i = t.name.indexOf(":"), o = i === -1 ? "" : t.name.slice(0, i);
769
+ if ((i === -1 ? t.name : t.name.slice(i + 1)) === "fallback" && r[o] === ze)
770
770
  return t;
771
771
  }
772
772
  }
773
- function Ie(e) {
773
+ function Ye(e) {
774
774
  return typeof e == "object" && e !== null && e.type === "element";
775
775
  }
776
- function Gt(e) {
776
+ function vn(e) {
777
777
  return /^(pf|xhtml):/.test(e.name);
778
778
  }
779
- function Yt(e, n, t) {
780
- const r = [], i = e.children.find(Ie);
779
+ function bn(e, n, t) {
780
+ const r = [], i = e.children.find(Ye);
781
781
  if (i) {
782
782
  const o = t?.parentId ?? "root";
783
- Re(i, o, t?.position ?? 1, n, o, r);
783
+ qe(i, o, t?.position ?? 1, n, o, r);
784
784
  }
785
785
  return r;
786
786
  }
787
- function Re(e, n, t, r, i, o) {
788
- const s = Xt(e) ?? r;
789
- let c, a;
790
- if (Gt(e))
791
- a = "root";
787
+ function qe(e, n, t, r, i, o) {
788
+ const l = hn(e) ?? r;
789
+ let u, m;
790
+ if (vn(e))
791
+ m = "root";
792
792
  else {
793
- const u = e.attributes.label ?? e.attributes["xml:id"];
794
- c = u ?? `${n}-${t}`, o.push({
795
- id: c,
796
- file: s,
793
+ const v = e.attributes.label ?? e.attributes["xml:id"];
794
+ u = v ?? `${n}-${t}`, o.push({
795
+ id: u,
796
+ file: l,
797
797
  line: e.position?.start.line ?? 1,
798
798
  column: e.position?.start.column ?? 1,
799
799
  endLine: e.position?.end.line ?? e.position?.start.line ?? 1,
800
800
  parent: i
801
- }), a = c;
801
+ }), m = u;
802
802
  }
803
- let d = 0;
804
- for (const u of e.children)
805
- Ie(u) && (d += 1, Re(
806
- u,
807
- a,
808
- d,
809
- s,
810
- c ?? i,
803
+ let f = 0;
804
+ for (const v of e.children)
805
+ Ye(v) && (f += 1, qe(
806
+ v,
807
+ m,
808
+ f,
809
+ l,
810
+ u ?? i,
811
811
  o
812
812
  ));
813
813
  }
814
- function An(e, n) {
814
+ function or(e, n) {
815
815
  let t;
816
816
  for (const r of e)
817
817
  r.line <= n && (t = r);
818
818
  return t ?? e[0];
819
819
  }
820
- function qt(e) {
820
+ function En(e) {
821
821
  const n = e.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!\[CDATA\[[\s\S]*?\]\]>/g, " ");
822
822
  return /<\s*slide(?:show)?[\s/>]/.test(n) ? "slides" : "html";
823
823
  }
824
- const Pe = "pretext-html:set-theme";
825
- function Bn(e) {
824
+ const Ze = "pretext-html:set-theme";
825
+ function sr(e) {
826
826
  return e === "dark" || e === "light" || e === "system";
827
827
  }
828
- function On(e) {
829
- return { type: Pe, theme: e };
828
+ function ar(e) {
829
+ return { type: Ze, theme: e };
830
830
  }
831
- function Zt(e) {
831
+ function yn(e) {
832
832
  return [
833
833
  "<script>",
834
834
  "(function () {",
835
- " var CFG = " + JSON.stringify({ msg: Pe, initial: e }) + ";",
835
+ " var CFG = " + JSON.stringify({ msg: Ze, initial: e }) + ";",
836
836
  // Where the last requested theme is remembered so it survives an in-place
837
837
  // document rewrite (same Window) and outranks the baked initial value.
838
838
  " var KEY = '__ptxPreviewTheme';",
@@ -902,12 +902,12 @@ function Zt(e) {
902
902
  ].join(`
903
903
  `);
904
904
  }
905
- function Qt(e, n) {
906
- const t = Zt(n);
905
+ function xn(e, n) {
906
+ const t = yn(n);
907
907
  return /<head[^>]*>/i.test(e) ? e.replace(/<head([^>]*)>/i, `<head$1>
908
908
  ${t}`) : e;
909
909
  }
910
- const De = /* @__PURE__ */ new Set([
910
+ const Qe = /* @__PURE__ */ new Set([
911
911
  "colophon",
912
912
  "biography",
913
913
  "dedication",
@@ -927,69 +927,69 @@ const De = /* @__PURE__ */ new Set([
927
927
  "glossary",
928
928
  "worksheet",
929
929
  "handout"
930
- ]), Le = /* @__PURE__ */ new Set([
930
+ ]), et = /* @__PURE__ */ new Set([
931
931
  "book",
932
932
  "article",
933
933
  "slideshow",
934
934
  "letter",
935
935
  "memo"
936
- ]), Me = /* @__PURE__ */ new Set([
937
- ...Le,
938
- ...De,
936
+ ]), tt = /* @__PURE__ */ new Set([
937
+ ...et,
938
+ ...Qe,
939
939
  "part",
940
940
  "frontmatter",
941
941
  "backmatter"
942
- ]), en = /* @__PURE__ */ new Set(["docinfo"]), Ae = /* @__PURE__ */ new Set([
942
+ ]), Tn = /* @__PURE__ */ new Set(["docinfo"]), nt = /* @__PURE__ */ new Set([
943
943
  "title",
944
944
  "shorttitle",
945
945
  "plaintitle",
946
946
  "subtitle",
947
947
  "caption"
948
948
  ]);
949
- function g(e) {
949
+ function O(e) {
950
950
  return e.type === "element";
951
951
  }
952
- function Be(e) {
952
+ function rt(e) {
953
953
  return e.attributes["xml:id"] ?? void 0;
954
954
  }
955
- function V(e, n) {
955
+ function ge(e, n) {
956
956
  for (const t of e.children) {
957
- if (!g(t)) continue;
958
- if (Be(t) === n) return t;
959
- const r = V(t, n);
957
+ if (!O(t)) continue;
958
+ if (rt(t) === n) return t;
959
+ const r = ge(t, n);
960
960
  if (r) return r;
961
961
  }
962
962
  }
963
- function L(e, n) {
963
+ function oe(e, n) {
964
964
  for (const t of e.children) {
965
- if (!g(t)) continue;
965
+ if (!O(t)) continue;
966
966
  if (t === n) return [t];
967
- const r = L(t, n);
967
+ const r = oe(t, n);
968
968
  if (r) return [t, ...r];
969
969
  }
970
970
  }
971
- function tn(e, n) {
971
+ function Sn(e, n) {
972
972
  let t = 0;
973
973
  for (const [r, i] of e.entries()) {
974
974
  const o = r === 0 ? void 0 : e[r - 1];
975
- Le.has(i.name) ? t = 0 : i.name === "frontmatter" || i.name === "backmatter" || i.name === "part" ? t = o?.name === "book" && n ? 1 : 0 : De.has(i.name) && (t += 1);
975
+ et.has(i.name) ? t = 0 : i.name === "frontmatter" || i.name === "backmatter" || i.name === "part" ? t = o?.name === "book" && n ? 1 : 0 : Qe.has(i.name) && (t += 1);
976
976
  }
977
977
  return t;
978
978
  }
979
- function Oe(e) {
980
- if (!Ae.has(e.name)) {
981
- e.children = e.children.filter(g);
979
+ function it(e) {
980
+ if (!nt.has(e.name)) {
981
+ e.children = e.children.filter(O);
982
982
  for (const n of e.children)
983
- Oe(n);
983
+ it(n);
984
984
  }
985
985
  }
986
- function X(e, n) {
986
+ function ve(e, n) {
987
987
  const t = [];
988
988
  for (const r of e.children)
989
- g(r) && (n.has(r) || en.has(r.name) || Ae.has(r.name) ? t.push(r) : Me.has(r.name) && (X(r, n), t.push(r)));
989
+ O(r) && (n.has(r) || Tn.has(r.name) || nt.has(r.name) ? t.push(r) : tt.has(r.name) && (ve(r, n), t.push(r)));
990
990
  e.children = t;
991
991
  }
992
- function nn(e) {
992
+ function An(e) {
993
993
  const n = /* @__PURE__ */ new Set(), t = (r) => {
994
994
  if (r.name === "xref") {
995
995
  const i = [
@@ -998,69 +998,69 @@ function nn(e) {
998
998
  r.attributes.last
999
999
  ];
1000
1000
  for (const o of i)
1001
- for (const s of o?.split(/[\s,]+/) ?? [])
1002
- s && n.add(s);
1001
+ for (const l of o?.split(/[\s,]+/) ?? [])
1002
+ l && n.add(l);
1003
1003
  }
1004
1004
  for (const i of r.children)
1005
- g(i) && t(i);
1005
+ O(i) && t(i);
1006
1006
  };
1007
1007
  return t(e), n;
1008
1008
  }
1009
- function rn(e, n, t) {
1009
+ function In(e, n, t) {
1010
1010
  const r = (i) => {
1011
- for (const [o, s] of i.children.entries())
1012
- if (g(s)) {
1013
- if (Be(s) === n)
1011
+ for (const [o, l] of i.children.entries())
1012
+ if (O(l)) {
1013
+ if (rt(l) === n)
1014
1014
  return i.children[o] = t, !0;
1015
- if (r(s)) return !0;
1015
+ if (r(l)) return !0;
1016
1016
  }
1017
1017
  return !1;
1018
1018
  };
1019
1019
  return r(e);
1020
1020
  }
1021
- function on(e, n) {
1022
- const t = V(e, n);
1021
+ function Ln(e, n) {
1022
+ const t = ge(e, n);
1023
1023
  if (!t) return;
1024
- const r = L(e, t);
1024
+ const r = oe(e, t);
1025
1025
  if (!r) return;
1026
1026
  const i = r.filter(
1027
- (f) => f.name !== "pretext" && f.name !== "mathbook"
1028
- ), o = i[0], s = o?.name === "book" && o.children.some(
1029
- (f) => g(f) && f.name === "part"
1030
- ), c = tn(i, s), a = new Set(r), d = nn(t), u = /* @__PURE__ */ new Set();
1031
- if (d.size > 0)
1032
- for (const f of d) {
1033
- const w = V(e, f);
1034
- if (!w || w === t) continue;
1035
- const P = L(e, w);
1036
- if (!P) continue;
1037
- const b = [...P].reverse().find((v) => Me.has(v.name));
1038
- if (b && b !== t) {
1039
- u.add(b);
1040
- for (const v of L(e, b) ?? [])
1041
- a.add(v);
1027
+ (b) => b.name !== "pretext" && b.name !== "mathbook"
1028
+ ), o = i[0], l = o?.name === "book" && o.children.some(
1029
+ (b) => O(b) && b.name === "part"
1030
+ ), u = Sn(i, l), m = new Set(r), f = An(t), v = /* @__PURE__ */ new Set();
1031
+ if (f.size > 0)
1032
+ for (const b of f) {
1033
+ const y = ge(e, b);
1034
+ if (!y || y === t) continue;
1035
+ const B = oe(e, y);
1036
+ if (!B) continue;
1037
+ const $ = [...B].reverse().find((k) => tt.has(k.name));
1038
+ if ($ && $ !== t) {
1039
+ v.add($);
1040
+ for (const k of oe(e, $) ?? [])
1041
+ m.add(k);
1042
1042
  }
1043
1043
  }
1044
- for (const f of r) {
1045
- if (f === t) break;
1046
- X(f, a);
1044
+ for (const b of r) {
1045
+ if (b === t) break;
1046
+ ve(b, m);
1047
1047
  }
1048
- for (const f of u)
1049
- Oe(f);
1050
- const p = e.children.find(g);
1051
- return p && !r.includes(p) && X(p, a), { content: I(e), divisionId: n, level: c };
1048
+ for (const b of v)
1049
+ it(b);
1050
+ const w = e.children.find(O);
1051
+ return w && !r.includes(w) && ve(w, m), { content: q(e), divisionId: n, level: u };
1052
1052
  }
1053
- const sn = "This live preview shows a single division, so links into the rest of the document do not work here.", cn = /<a\b([^>]*)>/g, an = /\sid="([^"]*)"/g, C = /\shref="([^"]*)"/, ln = /\\href\{([^{}]*)\}/g, ce = /\stitle="([^"]*)"/;
1054
- function dn(e) {
1053
+ const _n = "This live preview shows a single division, so links into the rest of the document do not work here.", $n = /<a\b([^>]*)>/g, Rn = /\sid="([^"]*)"/g, de = /\shref="([^"]*)"/, kn = /\\href\{([^{}]*)\}/g, $e = /\stitle="([^"]*)"/;
1054
+ function Nn(e) {
1055
1055
  const n = /* @__PURE__ */ new Set();
1056
- for (const t of e.matchAll(an))
1056
+ for (const t of e.matchAll(Rn))
1057
1057
  n.add(t[1]);
1058
1058
  return n;
1059
1059
  }
1060
- function un(e) {
1060
+ function Pn(e) {
1061
1061
  return e.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1062
1062
  }
1063
- function ae(e, n) {
1063
+ function Re(e, n) {
1064
1064
  if (e.startsWith("#") || e === "") return { kind: "keep" };
1065
1065
  if (/^[a-z][a-z0-9+.-]*:/i.test(e) || e.startsWith("//"))
1066
1066
  return { kind: "keep" };
@@ -1069,73 +1069,73 @@ function ae(e, n) {
1069
1069
  const r = e.slice(t + 1);
1070
1070
  return n.has(r) && r !== "" ? { kind: "same-page", id: r } : { kind: "off-page" };
1071
1071
  }
1072
- function fn(e, n = {}) {
1073
- const t = n.offPageMessage ?? sn, r = dn(e);
1074
- return e.replace(cn, (o, s) => {
1075
- const c = C.exec(s);
1076
- if (!c) return o;
1077
- const a = ae(c[1], r);
1078
- if (a.kind === "keep") return o;
1079
- if (a.kind === "same-page")
1080
- return `<a${s.replace(C, ` href="#${a.id}"`)}>`;
1081
- const d = ce.exec(s), u = un(t), p = d ? `${d[1]} — ${u}` : u;
1082
- return `<a${s.replace(C, "").replace(ce, "")} title="${p}" aria-disabled="true" style="cursor:default">`;
1083
- }).replace(ln, (o, s) => {
1084
- const c = ae(s, r);
1085
- return c.kind === "same-page" ? `\\href{#${c.id}}` : o;
1072
+ function Dn(e, n = {}) {
1073
+ const t = n.offPageMessage ?? _n, r = Nn(e);
1074
+ return e.replace($n, (o, l) => {
1075
+ const u = de.exec(l);
1076
+ if (!u) return o;
1077
+ const m = Re(u[1], r);
1078
+ if (m.kind === "keep") return o;
1079
+ if (m.kind === "same-page")
1080
+ return `<a${l.replace(de, ` href="#${m.id}"`)}>`;
1081
+ const f = $e.exec(l), v = Pn(t), w = f ? `${f[1]} — ${v}` : v;
1082
+ return `<a${l.replace(de, "").replace($e, "")} title="${w}" aria-disabled="true" style="cursor:default">`;
1083
+ }).replace(kn, (o, l) => {
1084
+ const u = Re(l, r);
1085
+ return u.kind === "same-page" ? `\\href{#${u.id}}` : o;
1086
1086
  });
1087
1087
  }
1088
- function pn() {
1089
- return me(M(), "xsl");
1088
+ function Mn() {
1089
+ return Oe(se(), "xsl");
1090
1090
  }
1091
- function hn() {
1091
+ function Cn() {
1092
1092
  return "Suspending" in WebAssembly;
1093
1093
  }
1094
- function mn() {
1095
- if (!hn())
1094
+ function On() {
1095
+ if (!Cn())
1096
1096
  throw new Error(
1097
1097
  "WebAssembly JSPI is not enabled. Run Node with --experimental-wasm-jspi (or use the pretext-html CLI, which re-launches itself with the flag)."
1098
1098
  );
1099
1099
  }
1100
- function k(e) {
1100
+ function Y(e) {
1101
1101
  return e.includes("'") ? e.includes('"') ? `concat(${e.split("'").map((t) => `'${t}'`).join(`, "'", `)})` : `"${e}"` : `'${e}'`;
1102
1102
  }
1103
- function wn(e) {
1103
+ function Bn(e) {
1104
1104
  return e.replace(
1105
1105
  /from '\.\/(https:\/\/[^']+)'/g,
1106
1106
  (n, t) => `from '${t}'`
1107
1107
  );
1108
1108
  }
1109
- const vn = `https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@${ve}/dist/`, gn = {
1110
- "cli.version": ve,
1109
+ const jn = `https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@${je}/dist/`, Un = {
1110
+ "cli.version": je,
1111
1111
  // Colon-delimited: pretext-runestone.xsl splits them with str:tokenize.
1112
- "rs-js": et.join(":"),
1113
- "rs-css": tt.join(":"),
1114
- "rs-version": Qe
1112
+ "rs-js": xt.join(":"),
1113
+ "rs-css": Tt.join(":"),
1114
+ "rs-version": yt
1115
1115
  };
1116
- function bn(e) {
1116
+ function Fn(e) {
1117
1117
  return e.replace(
1118
1118
  /(<link\b[^>]*\bhref=["'])_static\//gi,
1119
- `$1${vn}_static/`
1119
+ `$1${jn}_static/`
1120
1120
  );
1121
1121
  }
1122
- function xn(e) {
1122
+ function Wn(e) {
1123
1123
  return e.slice(0, 65536).replace(/<\?[\s\S]*?\?>/g, " ").replace(/<!--[\s\S]*?-->/g, " ").replace(/<!DOCTYPE[^>]*>/gi, " ").match(/<\s*([A-Za-z][\w:-]*)/)?.[1];
1124
1124
  }
1125
- async function le(e) {
1126
- const n = await B(e);
1125
+ async function ke(e) {
1126
+ const n = await ce(e);
1127
1127
  if (n === void 0)
1128
1128
  throw new Error(
1129
1129
  `Could not read ${e}. (In the browser build only absolute URLs are readable — pass sourceContent instead of relying on sourcePath.)`
1130
1130
  );
1131
1131
  return n;
1132
1132
  }
1133
- async function En(e, n) {
1134
- const t = h(e), r = await B(t);
1133
+ async function Hn(e, n) {
1134
+ const t = I(e), r = await ce(t);
1135
1135
  if (r !== void 0)
1136
- return zt(r, t, n);
1136
+ return wn(r, t, n);
1137
1137
  }
1138
- function yn(e, n, t, r) {
1138
+ function Vn(e, n, t, r) {
1139
1139
  const i = e.replace(/^\uFEFF/, "").replace(/<\?xml[\s\S]*?\?>/, "").replace(/<!DOCTYPE[^>]*>/i, ""), o = t === "slides" ? "slideshow" : n === "chapter" || n === "part" ? "book" : "article";
1140
1140
  return `<pretext>
1141
1141
  ${r?.trim() ? `${r.trim()}
@@ -1146,230 +1146,574 @@ ${i}
1146
1146
  </pretext>
1147
1147
  `;
1148
1148
  }
1149
- async function Tn(e, n, t, r) {
1150
- const i = T(e).children.find(
1151
- (u) => u.type === "element"
1149
+ async function Xn(e, n, t, r) {
1150
+ const i = X(e).children.find(
1151
+ (v) => v.type === "element"
1152
1152
  ), o = i?.attributes["xml:id"];
1153
1153
  if (!i || !o) return;
1154
- const s = h(n), c = r ?? await B(s);
1155
- if (c === void 0) return;
1156
- let a;
1154
+ const l = I(n), u = r ?? await ce(l);
1155
+ if (u === void 0) return;
1156
+ let m;
1157
1157
  try {
1158
- a = (await z(c, s, t)).tree;
1158
+ m = (await Ee(u, l, t)).tree;
1159
1159
  } catch {
1160
1160
  return;
1161
1161
  }
1162
- if (!rn(a, o, i)) return;
1163
- const d = on(a, o);
1164
- if (d)
1165
- return { ...d, tree: a };
1162
+ if (!In(m, o, i)) return;
1163
+ const f = Ln(m, o);
1164
+ if (f)
1165
+ return { ...f, tree: m };
1166
1166
  }
1167
- let je = !1;
1168
- function Sn(e) {
1167
+ let ot = !1;
1168
+ function Jn(e) {
1169
1169
  return e instanceof Error && /\bAborted\(/.test(e.message);
1170
1170
  }
1171
- function $n(e) {
1171
+ function zn(e) {
1172
1172
  return e instanceof Error && /memory access|out of bounds/i.test(e.message);
1173
1173
  }
1174
- function _n() {
1175
- if (je)
1174
+ function Gn() {
1175
+ if (ot)
1176
1176
  throw new Error(
1177
1177
  "The WebAssembly renderer aborted earlier in this process and cannot be reused. Restart the process (or reload the page) to render again."
1178
1178
  );
1179
1179
  }
1180
- function de(e) {
1181
- if (Sn(e))
1182
- throw je = !0, new Error(
1180
+ function Ne(e) {
1181
+ if (Jn(e))
1182
+ throw ot = !0, new Error(
1183
1183
  "The WebAssembly renderer aborted and cannot be reused. Restart the process (or reload the page) to render again.",
1184
1184
  { cause: e }
1185
1185
  );
1186
- if ($n(e))
1186
+ if (zn(e))
1187
1187
  throw new Error(
1188
1188
  "The WebAssembly renderer hit a memory fault. Most often the document is too large for this build's stack — whole-book builds are a known limitation, so try a smaller document, or see the README about rebuilding libxslt-wasm with a larger stack. The same fault also results from running two renders concurrently against the shared libxslt state.",
1189
1189
  { cause: e }
1190
1190
  );
1191
1191
  }
1192
- let N;
1193
- async function Ce() {
1194
- return N || (N = (async () => {
1192
+ let fe;
1193
+ async function st() {
1194
+ return fe || (fe = (async () => {
1195
1195
  const [e, n] = await Promise.all([
1196
1196
  import("@pretextbook/libxslt-wasm"),
1197
1197
  import("@pretextbook/libxslt-wasm/exslt")
1198
1198
  ]);
1199
1199
  return n.registerAll(), e;
1200
- })()), N;
1200
+ })()), fe;
1201
1201
  }
1202
- const F = /* @__PURE__ */ new Map(), kn = {
1202
+ const pe = /* @__PURE__ */ new Map(), Kn = {
1203
1203
  html: "preview-html.xsl",
1204
1204
  slides: "preview-revealjs.xsl"
1205
1205
  };
1206
- async function In(e, n) {
1207
- const t = kn[n], r = `${n}\0${e}`;
1208
- let i = F.get(r);
1206
+ async function Yn(e, n) {
1207
+ const t = Kn[n], r = `${n}\0${e}`;
1208
+ let i = pe.get(r);
1209
1209
  return i || (i = (async () => {
1210
- const { XmlDocument: o, XsltStylesheet: s } = await Ce(), c = Ee(e), a = await we(M(), `/${t}`);
1211
- if (a === void 0)
1210
+ const { XmlDocument: o, XsltStylesheet: l } = await st(), u = He(e), m = await Be(se(), `/${t}`);
1211
+ if (m === void 0)
1212
1212
  throw new Error(
1213
- `Could not read ${t} from ${M()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
1213
+ `Could not read ${t} from ${se()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
1214
1214
  );
1215
- const d = new TextDecoder().decode(a), u = await o.fromString(d, {
1216
- url: `${c}/${t}`,
1215
+ const f = new TextDecoder().decode(m), v = await o.fromString(f, {
1216
+ url: `${u}/${t}`,
1217
1217
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
1218
1218
  });
1219
- return s.fromXmlDocument(u);
1220
- })(), F.set(r, i), i.catch(() => F.delete(r))), i;
1221
- }
1222
- let ue = Promise.resolve();
1223
- function jn(e) {
1224
- const n = ue.then(
1225
- () => fe(e),
1226
- () => fe(e)
1219
+ return l.fromXmlDocument(v);
1220
+ })(), pe.set(r, i), i.catch(() => pe.delete(r))), i;
1221
+ }
1222
+ let Pe = Promise.resolve();
1223
+ function cr(e) {
1224
+ const n = Pe.then(
1225
+ () => De(e),
1226
+ () => De(e)
1227
1227
  );
1228
- return ue = n.catch(() => {
1228
+ return Pe = n.catch(() => {
1229
1229
  }), n;
1230
1230
  }
1231
- async function fe(e) {
1232
- mn(), _n();
1233
- const { XmlDocument: n } = await Ce(), t = h(e.sourcePath), r = h(
1234
- e.projectDir ?? E(t)
1235
- ), i = e.sourceContent ?? await le(t), o = j(r, t);
1231
+ async function De(e) {
1232
+ On(), Gn();
1233
+ const { XmlDocument: n } = await st(), t = I(e.sourcePath), r = I(
1234
+ e.projectDir ?? H(t)
1235
+ ), i = e.sourceContent ?? await ke(t), o = ue(r, t);
1236
1236
  if (o.startsWith(".."))
1237
1237
  throw new Error(
1238
1238
  `sourcePath (${t}) must live inside projectDir (${r})`
1239
1239
  );
1240
- const s = j(
1240
+ const l = ue(
1241
1241
  r,
1242
- h(e.mainSourcePath ?? t)
1243
- ), c = s.startsWith("..") ? o : s, a = Ee(r);
1242
+ I(e.mainSourcePath ?? t)
1243
+ ), u = l.startsWith("..") ? o : l, m = He(r);
1244
1244
  try {
1245
- let d, u = `${a}/__pretext-preview-publication.xml`;
1245
+ let f, v = `${m}/__pretext-preview-publication.xml`;
1246
1246
  if (e.publicationPath) {
1247
- const l = h(e.publicationPath);
1248
- d = await le(l);
1249
- const m = j(r, l);
1250
- m.startsWith("..") || (u = `${a}/${m.split(W).join("/")}`);
1247
+ const h = I(e.publicationPath);
1248
+ f = await ke(h);
1249
+ const S = ue(r, h);
1250
+ S.startsWith("..") || (v = `${m}/${S.split(he).join("/")}`);
1251
1251
  }
1252
- let p, f;
1252
+ let w, b;
1253
1253
  if (e.sourceMap) {
1254
- const l = await z(
1254
+ const h = await Ee(
1255
1255
  i,
1256
1256
  t,
1257
1257
  r
1258
1258
  );
1259
- p = l.tree, f = l.content;
1259
+ w = h.tree, b = h.content;
1260
1260
  } else
1261
- f = await Vt(
1261
+ b = await pn(
1262
1262
  i,
1263
1263
  t,
1264
1264
  r
1265
1265
  );
1266
- const w = e.target ?? qt(f), P = await In(e.xslDir ?? pn(), w), b = Rt(d, {
1266
+ const y = e.target ?? En(b), B = await Yn(e.xslDir ?? Mn(), y), $ = qt(f, {
1267
1267
  cssTheme: e.cssTheme,
1268
1268
  revealTheme: e.revealTheme,
1269
- target: w
1269
+ target: y
1270
1270
  });
1271
- ft(u, b);
1272
- const v = Pt(b), K = E(h(r, c)), G = v.external !== void 0 && v.generated !== void 0 ? {
1273
- external: h(K, v.external),
1274
- generated: h(K, v.generated)
1275
- } : void 0, S = xn(f);
1276
- let Y = { parentId: "root", position: 1 }, $, q = t;
1277
- if (S !== "pretext" && S !== "mathbook") {
1271
+ Dt(v, $);
1272
+ const k = Zt($), J = H(I(r, u)), z = k.external !== void 0 && k.generated !== void 0 ? {
1273
+ external: I(J, k.external),
1274
+ generated: I(J, k.generated)
1275
+ } : void 0, N = Wn(b);
1276
+ let G = { parentId: "root", position: 1 }, j, Q = t;
1277
+ if (N !== "pretext" && N !== "mathbook") {
1278
1278
  if (!e.fragment)
1279
1279
  throw new Error(
1280
- `The document root is <${S ?? "?"}>, not <pretext> — this looks like an xi:included fragment. Render the project's main source file instead, or pass the fragment option.`
1280
+ `The document root is <${N ?? "?"}>, not <pretext> — this looks like an xi:included fragment. Render the project's main source file instead, or pass the fragment option.`
1281
1281
  );
1282
1282
  if (e.contextSourcePath || e.contextSourceContent) {
1283
- const l = e.contextSourcePath ?? Ne(E(t), "__pretext-preview-context.ptx"), m = await Tn(
1284
- f,
1285
- l,
1283
+ const h = e.contextSourcePath ?? at(H(t), "__pretext-preview-context.ptx"), S = await Xn(
1284
+ b,
1285
+ h,
1286
1286
  r,
1287
1287
  e.contextSourceContent
1288
1288
  );
1289
- m && (f = m.content, p = e.sourceMap ? m.tree : void 0, q = h(l), $ = { divisionId: m.divisionId, level: m.level });
1289
+ S && (b = S.content, w = e.sourceMap ? S.tree : void 0, Q = I(h), j = { divisionId: S.divisionId, level: S.level });
1290
1290
  }
1291
- if (!$) {
1292
- const l = e.docinfo ?? (e.docinfoSourcePath ? await En(e.docinfoSourcePath, r) : void 0);
1293
- f = yn(
1294
- f,
1295
- S,
1296
- w,
1297
- l
1298
- ), Y = { parentId: l?.trim() ? "root-1-2" : "root-1-1", position: 2 };
1291
+ if (!j) {
1292
+ const h = e.docinfo ?? (e.docinfoSourcePath ? await Hn(e.docinfoSourcePath, r) : void 0);
1293
+ b = Vn(
1294
+ b,
1295
+ N,
1296
+ y,
1297
+ h
1298
+ ), G = { parentId: h?.trim() ? "root-1-2" : "root-1-1", position: 2 };
1299
1299
  }
1300
1300
  }
1301
- const Z = p ? Yt(p, q, Y) : void 0, Q = await n.fromString(f, {
1302
- url: `${a}/${c.split(W).join("/")}`,
1301
+ const ee = w ? bn(w, Q, G) : void 0, te = await n.fromString(b, {
1302
+ url: `${m}/${u.split(he).join("/")}`,
1303
1303
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
1304
- }), _ = {
1305
- publisher: k(u)
1304
+ }), M = {
1305
+ publisher: Y(v)
1306
1306
  };
1307
- for (const [l, m] of Object.entries(gn))
1308
- _[l] = k(m);
1309
- $ && (_.subtree = k($.divisionId), _["subtree-level"] = k(String($.level)));
1310
- for (const [l, m] of Object.entries(e.stringParams ?? {}))
1311
- _[l] = k(m);
1312
- let O;
1307
+ for (const [h, S] of Object.entries(Un))
1308
+ M[h] = Y(S);
1309
+ j && (M.subtree = Y(j.divisionId), M["subtree-level"] = Y(String(j.level)));
1310
+ for (const [h, S] of Object.entries(e.stringParams ?? {}))
1311
+ M[h] = Y(S);
1312
+ let K;
1313
1313
  try {
1314
- O = await P.apply(Q, _);
1315
- } catch (l) {
1316
- throw de(l), new Error(
1314
+ K = await B.apply(te, M);
1315
+ } catch (h) {
1316
+ throw Ne(h), new Error(
1317
1317
  "PreTeXt XSLT transform failed; see the PTX:ERROR/PTX:FATAL messages on stderr for details.",
1318
- { cause: l }
1318
+ { cause: h }
1319
1319
  );
1320
1320
  } finally {
1321
- Q.delete();
1321
+ te.delete();
1322
1322
  }
1323
1323
  try {
1324
- let l = wn(O.toHtmlString());
1325
- l = fn(l, {
1324
+ let h = Bn(K.toHtmlString());
1325
+ h = Dn(h, {
1326
1326
  ...e.offPageMessage !== void 0 ? { offPageMessage: e.offPageMessage } : {}
1327
- }), (e.openKnowls ?? !0) && (l = st(l)), w === "slides" ? (l = bn(l), l = Ht(l, e.revealView ?? "scroll", {
1327
+ }), (e.openKnowls ?? !0) && (h = _t(h)), y === "slides" ? (h = Fn(h), h = fn(h, e.revealView ?? "scroll", {
1328
1328
  zoom: e.revealZoom
1329
- })) : e.theme && (l = Qt(l, e.theme)), e.previewBanner && (l = Ke(l, e.previewBanner));
1330
- const m = w === "slides" ? [] : ye(l), ee = vt(m, S);
1331
- return e.printPreview && (l = St(l, e.printPreview)), {
1332
- html: l,
1333
- target: w,
1334
- printouts: m,
1335
- ...Z ? { sourceMap: Z } : {},
1336
- ...G ? { assetDirs: G } : {},
1337
- ...ee ? { rootPrintout: ee } : {}
1329
+ })) : e.theme && (h = xn(h, e.theme)), e.previewBanner && (h = wt(h, e.previewBanner));
1330
+ const S = y === "slides" ? [] : Ve(h), ne = jt(S, N);
1331
+ return e.printPreview && (h = Jt(h, e.printPreview)), {
1332
+ html: h,
1333
+ target: y,
1334
+ printouts: S,
1335
+ ...ee ? { sourceMap: ee } : {},
1336
+ ...z ? { assetDirs: z } : {},
1337
+ ...ne ? { rootPrintout: ne } : {}
1338
1338
  };
1339
- } catch (l) {
1340
- throw de(l), l;
1339
+ } catch (h) {
1340
+ throw Ne(h), h;
1341
1341
  } finally {
1342
- O.delete();
1342
+ K.delete();
1343
1343
  }
1344
1344
  } finally {
1345
- ut(a);
1345
+ Pt(m);
1346
+ }
1347
+ }
1348
+ const qn = "__ptxLivePatch";
1349
+ function Zn(e, n, t) {
1350
+ const r = "script, #latex-macros, [data-component], .ptx-runestone-container", i = /* @__PURE__ */ new Set([
1351
+ "BODY",
1352
+ "MAIN",
1353
+ "DIV",
1354
+ "SECTION",
1355
+ "ARTICLE",
1356
+ "ASIDE",
1357
+ "NAV",
1358
+ "HEADER",
1359
+ "FOOTER",
1360
+ "DETAILS",
1361
+ "FIGURE",
1362
+ "UL",
1363
+ "OL",
1364
+ "LI",
1365
+ "DL",
1366
+ "BLOCKQUOTE",
1367
+ "TABLE",
1368
+ "THEAD",
1369
+ "TBODY",
1370
+ "TFOOT",
1371
+ "TR"
1372
+ ]), o = /* @__PURE__ */ new Set([
1373
+ "A",
1374
+ "ABBR",
1375
+ "B",
1376
+ "BDI",
1377
+ "BDO",
1378
+ "BR",
1379
+ "BUTTON",
1380
+ "CITE",
1381
+ "CODE",
1382
+ "DATA",
1383
+ "DEL",
1384
+ "DFN",
1385
+ "EM",
1386
+ "I",
1387
+ "IMG",
1388
+ "INPUT",
1389
+ "INS",
1390
+ "KBD",
1391
+ "LABEL",
1392
+ "MARK",
1393
+ "Q",
1394
+ "S",
1395
+ "SAMP",
1396
+ "SELECT",
1397
+ "SMALL",
1398
+ "SPAN",
1399
+ "STRONG",
1400
+ "SUB",
1401
+ "SUP",
1402
+ "SVG",
1403
+ "TEXTAREA",
1404
+ "TIME",
1405
+ "U",
1406
+ "VAR",
1407
+ "WBR"
1408
+ ]), l = ["clipboardable"], u = 25e4, m = 3, f = [], v = /* @__PURE__ */ new Map();
1409
+ function w(s) {
1410
+ return { bail: s };
1411
+ }
1412
+ function b(s) {
1413
+ return typeof s == "object" && s !== null && typeof s.bail == "string";
1414
+ }
1415
+ function y(s) {
1416
+ return s.matches(r) || s.querySelector(r) !== null;
1417
+ }
1418
+ function B(s) {
1419
+ return s.tagName === "SCRIPT" && !s.hasAttribute("src") && (s.textContent ?? "").indexOf("ptx_lunr_docs") !== -1;
1420
+ }
1421
+ function $(s) {
1422
+ if (!i.has(s.tagName) || s.matches(".process-math") || // Never looked inside: a change anywhere in one is a change to it.
1423
+ s.matches(r))
1424
+ return !1;
1425
+ for (const a of Array.from(s.childNodes))
1426
+ if (a.nodeType === m && /\S/.test(a.nodeValue ?? ""))
1427
+ return !1;
1428
+ if (s.tagName === "DIV" || s.tagName === "LI") {
1429
+ for (const a of Array.from(s.children))
1430
+ if (o.has(a.tagName.toUpperCase()))
1431
+ return !1;
1432
+ }
1433
+ return !0;
1434
+ }
1435
+ function k(s) {
1436
+ return l.indexOf(s) !== -1;
1437
+ }
1438
+ function J(s, a) {
1439
+ if (s.tagName !== a.tagName)
1440
+ return !1;
1441
+ const c = a.getAttribute("id");
1442
+ if (c !== null && s.getAttribute("id") !== c)
1443
+ return !1;
1444
+ for (const d of Array.from(a.classList))
1445
+ if (!k(d))
1446
+ return s.classList.contains(d);
1447
+ return !0;
1346
1448
  }
1449
+ function z(s, a) {
1450
+ const c = Array.from(s.children), d = [];
1451
+ let E = 0;
1452
+ for (const g of a) {
1453
+ let p = null;
1454
+ for (; !p && E < c.length; ) {
1455
+ const x = c[E++];
1456
+ J(x, g) ? p = { inner: x, outer: x } : x.tagName === "DIV" && l.some((R) => x.classList.contains(R)) && x.firstElementChild && J(x.firstElementChild, g) && (p = { inner: x.firstElementChild, outer: x });
1457
+ }
1458
+ if (!p)
1459
+ return null;
1460
+ d.push(p);
1461
+ }
1462
+ return d;
1463
+ }
1464
+ function N(s, a) {
1465
+ if (s.attributes.length !== a.attributes.length)
1466
+ return !1;
1467
+ for (const c of Array.from(s.attributes))
1468
+ if (a.getAttributeNS(c.namespaceURI, c.localName) !== c.value)
1469
+ return !1;
1470
+ return !0;
1471
+ }
1472
+ function G(s) {
1473
+ return s.outerHTML.replace(/<([A-Za-z][^\s/>]*)\s[^>]*>/g, "<$1>");
1474
+ }
1475
+ function j(s) {
1476
+ let a = v.get(s);
1477
+ return a === void 0 && (a = s.outerHTML.replace(/<span class="codenumber">[^<]*<\/span>/g, "").replace(/<([A-Za-z][^\s/>]*)\s[^>]*>/g, "<$1>"), v.set(s, a)), a;
1478
+ }
1479
+ function Q(s, a, c, d, E) {
1480
+ const g = /* @__PURE__ */ new Map(), p = (D) => {
1481
+ const P = j(D);
1482
+ let re = g.get(P);
1483
+ return re === void 0 && (re = g.size, g.set(P, re)), re;
1484
+ }, x = s.slice(c, d).map(p), R = a.slice(c, E).map(p), _ = x.length, A = R.length, T = A + 1, L = new Uint32Array((_ + 1) * T);
1485
+ for (let D = _ - 1; D >= 0; D--)
1486
+ for (let P = A - 1; P >= 0; P--)
1487
+ L[D * T + P] = x[D] === R[P] ? L[(D + 1) * T + P + 1] + 1 : Math.max(L[(D + 1) * T + P], L[D * T + P + 1]);
1488
+ const C = [];
1489
+ let U = 0, F = 0;
1490
+ for (; U < _ && F < A; )
1491
+ x[U] === R[F] ? (C.push([c + U, c + F]), U++, F++) : L[(U + 1) * T + F] >= L[U * T + F + 1] ? U++ : F++;
1492
+ return C;
1493
+ }
1494
+ function ee(s, a) {
1495
+ const c = a.map(() => -1);
1496
+ let d = 0;
1497
+ for (; d < s.length && d < a.length && s[d].isEqualNode(a[d]); )
1498
+ c[d] = d, d++;
1499
+ let E = s.length, g = a.length;
1500
+ for (; E > d && g > d && s[E - 1].isEqualNode(a[g - 1]); )
1501
+ E--, g--, c[g] = E;
1502
+ const p = E - d, x = g - d;
1503
+ if (p === 0 || x === 0)
1504
+ return c;
1505
+ const R = (p > 1 || x > 1) && p * x <= u ? Q(s, a, d, E, g) : [];
1506
+ R.push([E, g]);
1507
+ let _ = d, A = d;
1508
+ for (const [T, L] of R) {
1509
+ for (; _ < T && A < L; ) {
1510
+ if (s[_].tagName === a[A].tagName) {
1511
+ c[A++] = _++;
1512
+ continue;
1513
+ }
1514
+ let C = _ + 1;
1515
+ for (; C < T && s[C].tagName !== a[A].tagName; )
1516
+ C++;
1517
+ C < T ? _ = C : A++;
1518
+ }
1519
+ T < E && (c[L] = T), _ = T + 1, A = L + 1;
1520
+ }
1521
+ return c;
1522
+ }
1523
+ function te(s, a) {
1524
+ if (y(s) || y(a))
1525
+ throw w(`<${a.tagName.toLowerCase()}> needs a full page load`);
1526
+ return { next: a, replace: !0 };
1527
+ }
1528
+ function M(s, a, c) {
1529
+ N(a, c) || f.push({ live: s, old: a, next: c });
1530
+ const d = Array.from(a.children), E = Array.from(c.children);
1531
+ if (d.length !== E.length)
1532
+ return !1;
1533
+ let g = null;
1534
+ for (let p = 0; p < d.length; p++)
1535
+ if (!d[p].isEqualNode(E[p]) && (g = g ?? z(s, d), !g || !M(g[p].inner, d[p], E[p])))
1536
+ return !1;
1537
+ return !0;
1538
+ }
1539
+ function K(s, a, c) {
1540
+ if (a.isEqualNode(c) || B(a) && B(c))
1541
+ return { next: c, outer: s.outer };
1542
+ if (a.tagName === c.tagName && $(a) && $(c)) {
1543
+ const d = h(s.inner, a, c);
1544
+ if (d)
1545
+ return N(a, c) || f.push({ live: s.inner, old: a, next: c }), { next: c, outer: s.outer, sub: d };
1546
+ } else if (G(a) === G(c)) {
1547
+ const d = f.length;
1548
+ if (M(s.inner, a, c)) {
1549
+ if (y(a))
1550
+ throw w(
1551
+ "attributes changed inside an element that needs a full page load"
1552
+ );
1553
+ return { next: c, outer: s.outer };
1554
+ }
1555
+ f.length = d;
1556
+ }
1557
+ return { ...te(a, c), outer: s.outer };
1558
+ }
1559
+ function h(s, a, c) {
1560
+ const d = Array.from(a.children), E = Array.from(c.children), g = z(s, d);
1561
+ if (!g)
1562
+ return null;
1563
+ const p = ee(d, E), x = d.map(() => !1), R = [];
1564
+ E.forEach((A, T) => {
1565
+ const L = p[T];
1566
+ if (L === -1) {
1567
+ if (y(A))
1568
+ throw w(
1569
+ `new <${A.tagName.toLowerCase()}> needs a full page load`
1570
+ );
1571
+ R.push({ next: A });
1572
+ return;
1573
+ }
1574
+ x[L] = !0, R.push(K(g[L], d[L], A));
1575
+ });
1576
+ const _ = [];
1577
+ return d.forEach((A, T) => {
1578
+ if (!x[T]) {
1579
+ if (y(A))
1580
+ throw w(
1581
+ `removing <${A.tagName.toLowerCase()}> needs a full page load`
1582
+ );
1583
+ _.push(g[T].outer);
1584
+ }
1585
+ }), {
1586
+ live: s,
1587
+ first: g.length ? g[0].outer : null,
1588
+ items: R,
1589
+ removed: _
1590
+ };
1591
+ }
1592
+ function S() {
1593
+ const s = Array.from(n.head.children), a = Array.from(t.head.children);
1594
+ if (s.length !== a.length)
1595
+ throw w("the page head changed");
1596
+ let c = null;
1597
+ for (let d = 0; d < s.length; d++) {
1598
+ const E = s[d], g = a[d];
1599
+ if (!E.isEqualNode(g)) {
1600
+ if (E.tagName === "TITLE" && g.tagName === "TITLE")
1601
+ c = g.textContent ?? "";
1602
+ else if (E.tagName !== "META" || g.tagName !== "META")
1603
+ throw w("the page head changed");
1604
+ }
1605
+ }
1606
+ return c;
1607
+ }
1608
+ function ne(s) {
1609
+ const { live: a, old: c, next: d } = s;
1610
+ for (const p of Array.from(c.attributes))
1611
+ p.name !== "class" && !d.hasAttributeNS(p.namespaceURI, p.localName) && a.removeAttributeNS(p.namespaceURI, p.localName);
1612
+ for (const p of Array.from(d.attributes))
1613
+ p.name !== "class" && c.getAttributeNS(p.namespaceURI, p.localName) !== p.value && a.setAttributeNS(p.namespaceURI, p.name, p.value);
1614
+ const E = Array.from(c.classList), g = Array.from(d.classList);
1615
+ for (const p of E)
1616
+ g.indexOf(p) === -1 && a.classList.remove(p);
1617
+ for (const p of g)
1618
+ E.indexOf(p) === -1 && a.classList.add(p);
1619
+ }
1620
+ const ye = [], le = [];
1621
+ function xe(s) {
1622
+ let a = null;
1623
+ for (const c of s.items) {
1624
+ if (!c.outer || c.replace) {
1625
+ const d = e.importNode(c.next, !0);
1626
+ c.outer ? (c.outer.replaceWith(d), le.push(c.outer)) : a ? a.after(d) : s.first ? s.first.before(d) : s.live.appendChild(d), ye.push(d), a = d;
1627
+ continue;
1628
+ }
1629
+ c.sub && xe(c.sub), a = c.outer;
1630
+ }
1631
+ for (const c of s.removed)
1632
+ c.remove(), le.push(c);
1633
+ }
1634
+ try {
1635
+ const s = S(), a = {
1636
+ live: e.documentElement,
1637
+ old: n.documentElement,
1638
+ next: t.documentElement
1639
+ };
1640
+ if (N(a.old, a.next) || f.push(a), !e.body || !$(n.body) || !$(t.body))
1641
+ throw w("the page body is not patchable");
1642
+ const c = h(e.body, n.body, t.body);
1643
+ if (!c)
1644
+ throw w("the live page no longer matches the previous render");
1645
+ return N(n.body, t.body) || f.push({ live: e.body, old: n.body, next: t.body }), f.forEach(ne), xe(c), s !== null && e.title !== s && (e.title = s), { ok: !0, added: ye, removed: le, attributeUpdates: f.length };
1646
+ } catch (s) {
1647
+ if (b(s))
1648
+ return {
1649
+ ok: !1,
1650
+ reason: s.bail,
1651
+ added: [],
1652
+ removed: [],
1653
+ attributeUpdates: 0
1654
+ };
1655
+ throw s;
1656
+ }
1657
+ }
1658
+ function Qn(e, n) {
1659
+ const t = e.MathJax, r = t && t.startup;
1660
+ if (!t || !r || !r.promise || typeof t.typesetPromise != "function")
1661
+ return Promise.resolve();
1662
+ const i = [];
1663
+ for (const u of n.added)
1664
+ u.matches(".process-math") ? i.push(u) : i.push(...Array.from(u.querySelectorAll(".process-math")));
1665
+ const o = n.removed;
1666
+ if (i.length === 0 && o.length === 0)
1667
+ return Promise.resolve();
1668
+ const l = r.promise.then(() => (o.length && typeof t.typesetClear == "function" && t.typesetClear(o), i.length && t.typesetPromise ? t.typesetPromise(i) : void 0)).then(
1669
+ () => {
1670
+ },
1671
+ (u) => {
1672
+ console.error("pretext-html: typesetting a live patch failed", u);
1673
+ }
1674
+ );
1675
+ return r.promise = l, l;
1676
+ }
1677
+ function lr() {
1678
+ return [
1679
+ "<script>",
1680
+ `window[${JSON.stringify(qn)}] = {`,
1681
+ ` patchDocument: ${Zn.toString()},`,
1682
+ ` typeset: ${Qn.toString()}`,
1683
+ "};",
1684
+ "<\/script>"
1685
+ ].join(`
1686
+ `);
1347
1687
  }
1348
1688
  export {
1349
- Fe as PREVIEW_BANNER_STORAGE_KEY,
1350
- Pe as PREVIEW_THEME_MESSAGE,
1351
- gt as PRINT_PREVIEW_GLOBAL,
1352
- pn as defaultXslDir,
1353
- qt as detectRenderTarget,
1354
- An as findSourceMapEntry,
1355
- Rt as forcePortablePublication,
1356
- Ke as injectPreviewBanner,
1357
- St as injectPrintPreview,
1358
- Ht as injectRevealBridge,
1359
- Qt as injectThemeBridge,
1360
- hn as isJspiAvailable,
1361
- Bn as isPreviewTheme,
1362
- Mn as isRevealView,
1363
- ye as listPrintouts,
1364
- st as openBornHiddenKnowls,
1365
- Ve as previewBannerScript,
1366
- On as previewThemeMessage,
1367
- bt as printPreviewBridgeScript,
1368
- jn as renderHtml,
1369
- Ct as revealBridgeScript,
1370
- vt as rootPrintoutId,
1371
- Dn as setAssetsBase,
1372
- Ln as setMountReader,
1373
- Zt as themeBridgeScript,
1374
- k as xpathStringLiteral
1689
+ qn as LIVE_PATCH_GLOBAL,
1690
+ ct as PREVIEW_BANNER_STORAGE_KEY,
1691
+ Ze as PREVIEW_THEME_MESSAGE,
1692
+ Ut as PRINT_PREVIEW_GLOBAL,
1693
+ Mn as defaultXslDir,
1694
+ En as detectRenderTarget,
1695
+ or as findSourceMapEntry,
1696
+ qt as forcePortablePublication,
1697
+ wt as injectPreviewBanner,
1698
+ Jt as injectPrintPreview,
1699
+ fn as injectRevealBridge,
1700
+ xn as injectThemeBridge,
1701
+ Cn as isJspiAvailable,
1702
+ sr as isPreviewTheme,
1703
+ ir as isRevealView,
1704
+ Ve as listPrintouts,
1705
+ lr as livePatchScript,
1706
+ _t as openBornHiddenKnowls,
1707
+ Zn as patchDocument,
1708
+ ft as previewBannerScript,
1709
+ ar as previewThemeMessage,
1710
+ Ft as printPreviewBridgeScript,
1711
+ cr as renderHtml,
1712
+ an as revealBridgeScript,
1713
+ jt as rootPrintoutId,
1714
+ nr as setAssetsBase,
1715
+ rr as setMountReader,
1716
+ yn as themeBridgeScript,
1717
+ Qn as typesetPatch,
1718
+ Y as xpathStringLiteral
1375
1719
  };