@pretextbook/pretext-html 0.16.0 → 0.17.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.
Files changed (60) hide show
  1. package/README.md +77 -3
  2. package/assets/preview-html.xsl +56 -0
  3. package/assets/upstream.json +2 -2
  4. package/assets/xsl/entities.ent +14 -1
  5. package/assets/xsl/latex/pretext-latex-texstyle.xsl +5 -2
  6. package/assets/xsl/localizations/README.md +1 -1
  7. package/assets/xsl/localizations/af-ZA.xml +5 -6
  8. package/assets/xsl/localizations/bg-BG.xml +5 -6
  9. package/assets/xsl/localizations/ca-ES.xml +5 -6
  10. package/assets/xsl/localizations/cs-CZ.xml +5 -6
  11. package/assets/xsl/localizations/de-DE.xml +108 -108
  12. package/assets/xsl/localizations/en-US.xml +18 -17
  13. package/assets/xsl/localizations/es-ES.xml +5 -6
  14. package/assets/xsl/localizations/fi-FI.xml +5 -6
  15. package/assets/xsl/localizations/fr-CA.xml +5 -6
  16. package/assets/xsl/localizations/fr-FR.xml +5 -6
  17. package/assets/xsl/localizations/hu-HU.xml +5 -6
  18. package/assets/xsl/localizations/it-IT.xml +7 -7
  19. package/assets/xsl/localizations/ku-CKB.xml +5 -6
  20. package/assets/xsl/localizations/nl-NL.xml +5 -6
  21. package/assets/xsl/localizations/pt-BR.xml +4 -5
  22. package/assets/xsl/localizations/pt-PT.xml +4 -5
  23. package/assets/xsl/localizations/zh-HANS.xml +5 -6
  24. package/assets/xsl/pretext-assembly.xsl +154 -29
  25. package/assets/xsl/pretext-beamer.xsl +112 -10
  26. package/assets/xsl/pretext-braille-preprint.xsl +22 -3
  27. package/assets/xsl/pretext-common.xsl +117 -42
  28. package/assets/xsl/pretext-epub.xsl +74 -87
  29. package/assets/xsl/pretext-fo.xsl +115 -41
  30. package/assets/xsl/pretext-html.xsl +333 -102
  31. package/assets/xsl/pretext-latex-classic.xsl +48 -35
  32. package/assets/xsl/pretext-latex-common.xsl +160 -98
  33. package/assets/xsl/pretext-latex.xsl +12 -10
  34. package/assets/xsl/pretext-markdown.xsl +5 -3
  35. package/assets/xsl/pretext-numbers.xsl +28 -2
  36. package/assets/xsl/pretext-revealjs.xsl +44 -2
  37. package/assets/xsl/pretext-runestone-static.xsl +27 -4
  38. package/assets/xsl/pretext-runestone.xsl +112 -0
  39. package/assets/xsl/pretext-text.xsl +21 -14
  40. package/assets/xsl/publisher-variables.xsl +187 -47
  41. package/assets/xsl/support/extract-math.xsl +22 -2
  42. package/assets/xsl/support/package-math.xsl +9 -8
  43. package/assets/xsl/utilities/report-publisher-variables.xsl +4 -0
  44. package/assets/xsl-bundle.json +1 -1
  45. package/dist/cli-C0JwLhuv.js +1456 -0
  46. package/dist/cli.js +3 -3
  47. package/dist/html-static.d.ts +2 -2
  48. package/dist/index.browser.d.ts +9 -4
  49. package/dist/index.browser.js +1151 -841
  50. package/dist/index.d.ts +9 -3
  51. package/dist/index.js +50 -46
  52. package/dist/publication.d.ts +21 -0
  53. package/dist/renderer.d.ts +134 -13
  54. package/dist/skeleton.d.ts +68 -7
  55. package/dist/source-cache.d.ts +36 -0
  56. package/dist/sourcemap.d.ts +11 -1
  57. package/dist/subtree.d.ts +79 -0
  58. package/dist/xinclude.d.ts +40 -3
  59. package/package.json +1 -1
  60. package/dist/cli-ox-z2TCZ.js +0 -1145
@@ -1,66 +1,66 @@
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) {
1
+ import { fromXml as oe } from "xast-util-from-xml";
2
+ import { toXml as te } from "xast-util-to-xml";
3
+ const Ie = "/";
4
+ function ze(e) {
5
5
  if (!e)
6
6
  return ".";
7
- const n = e.startsWith("/"), t = e.length > 1 && e.endsWith("/"), r = [];
7
+ const t = e.startsWith("/"), n = 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 l = r[r.length - 1];
12
- r.length > 0 && l !== ".." ? r.pop() : n || r.push("..");
11
+ const a = r[r.length - 1];
12
+ r.length > 0 && a !== ".." ? r.pop() : t || r.push("..");
13
13
  continue;
14
14
  }
15
15
  r.push(o);
16
16
  }
17
17
  let i = r.join("/");
18
- return n && (i = `/${i}`), i ? (t && !i.endsWith("/") && (i += "/"), i) : n ? "/" : ".";
18
+ return t && (i = `/${i}`), i ? (n && !i.endsWith("/") && (i += "/"), i) : t ? "/" : ".";
19
19
  }
20
- function I(...e) {
21
- let n = "";
20
+ function E(...e) {
21
+ let t = "";
22
22
  for (let r = e.length - 1; r >= 0; r--) {
23
23
  const i = e[r];
24
- if (i && (n = n ? `${i}/${n}` : i, i.startsWith("/")))
24
+ if (i && (t = t ? `${i}/${t}` : i, i.startsWith("/")))
25
25
  break;
26
26
  }
27
- n.startsWith("/") || (n = `/${n}`);
28
- const t = Me(n);
29
- return t.length > 1 && t.endsWith("/") ? t.slice(0, -1) : t;
27
+ t.startsWith("/") || (t = `/${t}`);
28
+ const n = ze(t);
29
+ return n.length > 1 && n.endsWith("/") ? n.slice(0, -1) : n;
30
30
  }
31
- function at(...e) {
32
- const n = e.filter(Boolean).join("/");
33
- return n ? Me(n) : ".";
31
+ function St(...e) {
32
+ const t = e.filter(Boolean).join("/");
33
+ return t ? ze(t) : ".";
34
34
  }
35
- function H(e) {
36
- const n = e.replace(/\/+$/, "");
37
- if (!n)
35
+ function Y(e) {
36
+ const t = e.replace(/\/+$/, "");
37
+ if (!t)
38
38
  return e.startsWith("/") ? "/" : ".";
39
- const t = n.lastIndexOf("/");
40
- return t < 0 ? "." : t === 0 ? "/" : n.slice(0, t);
39
+ const n = t.lastIndexOf("/");
40
+ return n < 0 ? "." : n === 0 ? "/" : t.slice(0, n);
41
41
  }
42
- function ue(e, n) {
43
- const t = I(e).split("/").filter(Boolean), r = I(n).split("/").filter(Boolean);
42
+ function ye(e, t) {
43
+ const n = E(e).split("/").filter(Boolean), r = E(t).split("/").filter(Boolean);
44
44
  let i = 0;
45
- for (; i < t.length && i < r.length && t[i] === r[i]; )
45
+ for (; i < n.length && i < r.length && n[i] === r[i]; )
46
46
  i += 1;
47
- return [...new Array(t.length - i).fill(".."), ...r.slice(i)].join("/");
47
+ return [...new Array(n.length - i).fill(".."), ...r.slice(i)].join("/");
48
48
  }
49
- const ct = "ptxPreviewBannerDismissed", lt = "About live preview";
50
- function Te(e) {
49
+ const Tt = "ptxPreviewBannerDismissed", It = "About live preview";
50
+ function Ce(e) {
51
51
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
52
52
  }
53
- function ut(e) {
53
+ function At(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">${Ce(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(lt)}</button>`
59
+ `<button type="button" id="ptx-preview-banner-restore" class="ptx-preview-banner-restore" hidden>${Ce(It)}</button>`
60
60
  ].join(`
61
61
  `);
62
62
  }
63
- function dt() {
63
+ function Lt() {
64
64
  return [
65
65
  "<style>",
66
66
  ".ptx-preview-banner {",
@@ -129,11 +129,11 @@ function dt() {
129
129
  ].join(`
130
130
  `);
131
131
  }
132
- function ft() {
132
+ function $t() {
133
133
  return [
134
134
  "<script>",
135
135
  "(function () {",
136
- " var KEY = " + JSON.stringify(ct) + ";",
136
+ " var KEY = " + JSON.stringify(Tt) + ";",
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,67 +170,67 @@ function ft() {
170
170
  ].join(`
171
171
  `);
172
172
  }
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;
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;
176
176
  if (!/<body[^>]*>/i.test(r))
177
177
  return r;
178
178
  const i = `
179
- ${pt}
180
- ${dt()}
181
- ${ut(n.message)}
182
- ${ft()}
183
- ${ht}`;
179
+ ${_t}
180
+ ${Lt()}
181
+ ${At(t.message)}
182
+ ${$t()}
183
+ ${kt}`;
184
184
  return r.replace(/<body([^>]*)>/i, `<body$1>${i}`);
185
185
  }
186
- const gt = "https://cdn.jsdelivr.net/npm/@pretextbook/pretext-html@0.16.0/assets";
187
- let Ce;
188
- function nr(e) {
189
- Ce = e.replace(/\/+$/, "");
186
+ const Pt = "https://cdn.jsdelivr.net/npm/@pretextbook/pretext-html@0.17.0/assets";
187
+ let Je;
188
+ function Ar(e) {
189
+ Je = e.replace(/\/+$/, "");
190
190
  }
191
- function se() {
192
- return Ce ?? gt;
191
+ function fe() {
192
+ return Je ?? Pt;
193
193
  }
194
- function Oe(e, n) {
195
- return `${e.replace(/\/+$/, "")}/${n.replace(/^\/+/, "")}`;
194
+ function Ge(e, t) {
195
+ return `${e.replace(/\/+$/, "")}/${t.replace(/^\/+/, "")}`;
196
196
  }
197
- const Se = /* @__PURE__ */ new Map();
198
- function vt(e) {
197
+ const De = /* @__PURE__ */ new Map();
198
+ function Ct(e) {
199
199
  return `${e.replace(/\/+$/, "")}-bundle.json`;
200
200
  }
201
- function bt(e) {
202
- let n = Se.get(e);
203
- return n || (n = (async () => {
201
+ function Dt(e) {
202
+ let t = De.get(e);
203
+ return t || (t = (async () => {
204
204
  try {
205
- const t = await fetch(vt(e));
206
- if (!t.ok)
205
+ const n = await fetch(Ct(e));
206
+ if (!n.ok)
207
207
  return /* @__PURE__ */ new Map();
208
- const r = await t.json();
208
+ const r = await n.json();
209
209
  return new Map(Object.entries(r));
210
210
  } catch {
211
211
  return /* @__PURE__ */ new Map();
212
212
  }
213
- })(), Se.set(e, n)), n;
213
+ })(), De.set(e, t)), t;
214
214
  }
215
- function Et(e) {
216
- return e === Oe(se(), "xsl");
215
+ function Mt(e) {
216
+ return e === Ge(fe(), "xsl");
217
217
  }
218
- async function Be(e, n) {
219
- if (Et(e)) {
220
- const o = (await bt(e)).get(n.replace(/^\/+/, ""));
218
+ async function Ke(e, t) {
219
+ if (Mt(e)) {
220
+ const o = (await Dt(e)).get(t.replace(/^\/+/, ""));
221
221
  if (o !== void 0)
222
222
  return new TextEncoder().encode(o);
223
223
  }
224
- const t = `${e.replace(/\/+$/, "")}/`;
224
+ const n = `${e.replace(/\/+$/, "")}/`;
225
225
  let r;
226
226
  try {
227
- r = new URL(n.replace(/^\/+/, ""), t);
227
+ r = new URL(t.replace(/^\/+/, ""), n);
228
228
  } catch {
229
229
  return;
230
230
  }
231
- if (!r.href.startsWith(t)) {
231
+ if (!r.href.startsWith(n)) {
232
232
  console.error(
233
- `pretext-html: refusing to serve ${n} from outside ${e}`
233
+ `pretext-html: refusing to serve ${t} from outside ${e}`
234
234
  );
235
235
  return;
236
236
  }
@@ -241,115 +241,115 @@ async function Be(e, n) {
241
241
  return;
242
242
  }
243
243
  }
244
- async function ce(e) {
244
+ async function Ot(e) {
245
245
  if (/^[a-z][a-z0-9+.-]*:\/\//i.test(e))
246
246
  try {
247
- const n = await fetch(e);
248
- return n.ok ? await n.text() : void 0;
247
+ const t = await fetch(e);
248
+ return t.ok ? await t.text() : void 0;
249
249
  } catch {
250
250
  return;
251
251
  }
252
252
  }
253
- const je = "2.51.0", yt = "8.2.9", xt = [
254
- "prefix-runtime.5ef53875c58b216b.bundle.js",
253
+ const Ye = "2.55.0", Bt = "8.3.3", jt = [
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
+ ], Ut = [
258
258
  "prefix-926.229729d09512acc9.css",
259
- "prefix-runestone.efe427683fc41f98.css"
260
- ], St = "born-hidden-knowl", At = /<details\b([^>]*)>(\s*)(?:<summary\b([^>]*)>)?/g;
261
- function It(e) {
262
- const n = /\bclass="([^"]*)"/.exec(e);
263
- return n ? n[1].trim().split(/\s+/) : [];
259
+ "prefix-runestone.347e2ecdeacfed99.css"
260
+ ], Ft = "born-hidden-knowl", Wt = /<details\b([^>]*)>(\s*)(?:<summary\b([^>]*)>)?/g;
261
+ function Ht(e) {
262
+ const t = /\bclass="([^"]*)"/.exec(e);
263
+ return t ? t[1].trim().split(/\s+/) : [];
264
264
  }
265
- function Lt(e) {
265
+ function Vt(e) {
266
266
  return /(^|\s)open(\s|=|$)/.test(e);
267
267
  }
268
- function Ae(e) {
269
- return Lt(e) ? e : ` open${e}`;
268
+ function Me(e) {
269
+ return Vt(e) ? e : ` open${e}`;
270
270
  }
271
- function _t(e) {
271
+ function Xt(e) {
272
272
  return e.replace(
273
- At,
274
- (n, t, r, i) => {
275
- if (!It(t).includes(St))
276
- return n;
277
- const o = `<details${Ae(t)}>`;
278
- return i === void 0 ? `${o}${r}` : `${o}${r}<summary${Ae(i)}>`;
273
+ Wt,
274
+ (t, n, r, i) => {
275
+ if (!Ht(n).includes(Ft))
276
+ return t;
277
+ const o = `<details${Me(n)}>`;
278
+ return i === void 0 ? `${o}${r}` : `${o}${r}<summary${Me(i)}>`;
279
279
  }
280
280
  );
281
281
  }
282
- const be = /* @__PURE__ */ new Map(), Ue = /* @__PURE__ */ new Map();
283
- let me, $t = 0, Fe = Be;
284
- function rr(e) {
285
- Fe = e;
282
+ const _e = /* @__PURE__ */ new Map(), qe = /* @__PURE__ */ new Map();
283
+ let Ae, zt = 0, Ze = Ke;
284
+ function Lr(e) {
285
+ Ze = e;
286
286
  }
287
- function Rt(e, n) {
288
- const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, r = Ue.get(t);
287
+ function Jt(e, t) {
288
+ const n = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, r = qe.get(n);
289
289
  if (r !== void 0)
290
290
  return Promise.resolve(new Response(r, { status: 200 }));
291
291
  let i;
292
292
  try {
293
- i = new URL(t).host;
293
+ i = new URL(n).host;
294
294
  } catch {
295
295
  i = "";
296
296
  }
297
- const o = be.get(i);
298
- return o !== void 0 ? Nt(o, t) : me(e, n);
297
+ const o = _e.get(i);
298
+ return o !== void 0 ? Kt(o, n) : Ae(e, t);
299
299
  }
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);
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);
303
303
  if (r === void 0)
304
- return new Response(kt, { status: 200 });
304
+ return new Response(Gt, { 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 We() {
309
- me || (me = globalThis.fetch, globalThis.fetch = Rt);
308
+ function Qe() {
309
+ Ae || (Ae = globalThis.fetch, globalThis.fetch = Jt);
310
310
  }
311
- function He(e) {
312
- We();
313
- const n = `mnt${++$t}.ptx.invalid`;
314
- return be.set(n, e), `http://${n}`;
311
+ function et(e) {
312
+ Qe();
313
+ const t = `mnt${++zt}.ptx.invalid`;
314
+ return _e.set(t, e), `http://${t}`;
315
315
  }
316
- function Pt(e) {
317
- be.delete(new URL(e).host);
316
+ function Yt(e) {
317
+ _e.delete(new URL(e).host);
318
318
  }
319
- function Dt(e, n) {
320
- We(), Ue.set(e, n);
319
+ function qt(e, t) {
320
+ Qe(), qe.set(e, t);
321
321
  }
322
- const Mt = /<a\b[^>]*\bdata-printout="[^"]*"[^>]*>/gi;
323
- function ie(e, n) {
324
- const t = new RegExp(`\\b${n}="([^"]*)"`, "i").exec(e);
325
- return t ? Ct(t[1]) : void 0;
322
+ const Zt = /<a\b[^>]*\bdata-printout="[^"]*"[^>]*>/gi;
323
+ function ue(e, t) {
324
+ const n = new RegExp(`\\b${t}="([^"]*)"`, "i").exec(e);
325
+ return n ? Qt(n[1]) : void 0;
326
326
  }
327
- function Ct(e) {
327
+ function Qt(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 Ot(e, n, t) {
331
- const r = [e, n].filter(Boolean).join(" ");
332
- return r && t ? `${r}: ${t}` : r || t;
330
+ function en(e, t, n) {
331
+ const r = [e, t].filter(Boolean).join(" ");
332
+ return r && n ? `${r}: ${n}` : r || n;
333
333
  }
334
- function Ve(e) {
335
- const n = [], t = /* @__PURE__ */ new Set();
336
- for (const [r] of e.matchAll(Mt)) {
337
- const i = ie(r, "data-printout");
338
- if (!i || t.has(i))
334
+ function tt(e) {
335
+ const t = [], n = /* @__PURE__ */ new Set();
336
+ for (const [r] of e.matchAll(Zt)) {
337
+ const i = ue(r, "data-printout");
338
+ if (!i || n.has(i))
339
339
  continue;
340
- t.add(i);
341
- const o = ie(r, "data-printout-type") ?? "", l = ie(r, "data-printout-number") ?? "", u = ie(r, "data-printout-title") ?? "";
342
- n.push({
340
+ n.add(i);
341
+ const o = ue(r, "data-printout-type") ?? "", a = ue(r, "data-printout-number") ?? "", l = ue(r, "data-printout-title") ?? "";
342
+ t.push({
343
343
  id: i,
344
344
  type: o,
345
- number: l,
346
- title: u,
347
- label: Ot(o, l, u)
345
+ number: a,
346
+ title: l,
347
+ label: en(o, a, l)
348
348
  });
349
349
  }
350
- return n;
350
+ return t;
351
351
  }
352
- const Bt = /* @__PURE__ */ new Set([
352
+ const tn = /* @__PURE__ */ new Set([
353
353
  "worksheet",
354
354
  "handout",
355
355
  "project",
@@ -357,18 +357,18 @@ const Bt = /* @__PURE__ */ new Set([
357
357
  "exploration",
358
358
  "investigation"
359
359
  ]);
360
- function jt(e, n) {
361
- if (!(!n || !Bt.has(n)))
360
+ function nn(e, t) {
361
+ if (!(!t || !tn.has(t)))
362
362
  return e[0]?.id;
363
363
  }
364
- const Ut = "__ptxPrintPreview";
365
- function Ft(e) {
366
- const n = JSON.stringify(e ?? null);
364
+ const rn = "__ptxPrintPreview";
365
+ function on(e) {
366
+ const t = JSON.stringify(e ?? null);
367
367
  return [
368
368
  "<script>",
369
369
  "(function () {",
370
- " var KEY = " + JSON.stringify(Ut) + ";",
371
- " window[KEY] = " + n + ";",
370
+ " var KEY = " + JSON.stringify(rn) + ";",
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
374
374
  // checks it in both isDarkMode and setDarkMode, the only two places that
@@ -402,7 +402,7 @@ function Ft(e) {
402
402
  ].join(`
403
403
  `);
404
404
  }
405
- function Wt() {
405
+ function sn() {
406
406
  return [
407
407
  "<style>",
408
408
  ":root {",
@@ -422,19 +422,19 @@ function Wt() {
422
422
  ].join(`
423
423
  `);
424
424
  }
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);
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);
428
428
  if (!i)
429
429
  return r;
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"?>
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;
435
+ return r.slice(0, l) + a + r.slice(l);
436
+ }
437
+ const de = `<?xml version="1.0" encoding="UTF-8"?>
438
438
  <publication>
439
439
  <source>
440
440
  <directories external="../assets" generated="../generated-assets" />
@@ -446,82 +446,102 @@ const we = `<?xml version="1.0" encoding="UTF-8"?>
446
446
  <platform portable="yes"/>
447
447
  </html>
448
448
  </publication>
449
- `, zt = ["theme", "style", "shell"];
450
- function W(e, n) {
451
- for (const t of e.children)
452
- if (t.type === "element" && t.name === n)
453
- return t;
454
- }
455
- function V(e, n) {
456
- let t = W(e, n);
457
- return t || (t = { type: "element", name: n, attributes: {}, children: [] }, e.children.push(t)), t;
458
- }
459
- function Gt(e, n) {
460
- const t = W(e, "css");
461
- if (t && zt.some((i) => t.attributes?.[i]))
449
+ `, fn = ["theme", "style", "shell"];
450
+ function j(e, t) {
451
+ for (const n of e.children)
452
+ if (n.type === "element" && n.name === t)
453
+ return n;
454
+ }
455
+ function ee(e, t) {
456
+ let n = j(e, t);
457
+ return n || (n = { type: "element", name: t, attributes: {}, children: [] }, e.children.push(n)), n;
458
+ }
459
+ function dn(e, t) {
460
+ const n = j(e, "css");
461
+ if (n && fn.some((i) => n.attributes?.[i]))
462
462
  return;
463
- const r = t ?? V(e, "css");
464
- r.attributes = { ...r.attributes, theme: n };
463
+ const r = n ?? ee(e, "css");
464
+ r.attributes = { ...r.attributes, theme: t };
465
465
  }
466
- function Kt(e, n) {
467
- const t = W(e, "appearance");
468
- if (t?.attributes?.theme)
466
+ function hn(e, t) {
467
+ const n = j(e, "appearance");
468
+ if (n?.attributes?.theme)
469
469
  return;
470
- const r = t ?? V(e, "appearance");
471
- r.attributes = { ...r.attributes, theme: n };
470
+ const r = n ?? ee(e, "appearance");
471
+ r.attributes = { ...r.attributes, theme: t };
472
472
  }
473
- function Yt(e) {
474
- const n = V(e, "resources");
475
- n.attributes = {
476
- ...n.attributes,
473
+ function pn(e) {
474
+ const t = ee(e, "resources");
475
+ t.attributes = {
476
+ ...t.attributes,
477
477
  host: "cdn",
478
478
  math: "online"
479
479
  };
480
480
  }
481
- function qt(e, n = {}) {
482
- const t = n.cssTheme?.trim(), r = n.revealTheme?.trim(), i = n.target === "slides";
483
- if (!e && !t && !i)
484
- return we;
485
- const o = X(e ?? we), l = W(o, "publication");
486
- if (!l)
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");
486
+ if (!a)
487
487
  throw new Error(
488
488
  "Invalid publication file: no root <publication> element found"
489
489
  );
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);
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);
494
494
  }
495
- return q(o);
495
+ return te(o);
496
496
  }
497
- function Ie(e) {
497
+ function Oe(e) {
498
498
  if (!(e === void 0 || e === "" || e.startsWith("/")))
499
499
  return e.endsWith("/") ? e : `${e}/`;
500
500
  }
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(
501
+ function Be(e) {
502
+ const t = e?.attributes?.level;
503
+ if (t == null || t === "") return;
504
+ const n = Number(t);
505
+ return Number.isFinite(n) && n >= 0 ? n : void 0;
506
+ }
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");
509
+ 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));
514
+ }
515
+ return {
516
+ tocLevel: Be(i),
517
+ numberingLevel: a,
518
+ maxNumberingLevel: l
519
+ };
520
+ }
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(
503
523
  i?.attributes?.external ?? void 0
504
- ), l = Ie(
524
+ ), a = Oe(
505
525
  i?.attributes?.generated ?? void 0
506
526
  );
507
527
  return {
508
528
  external: o,
509
- generated: l,
510
- managed: o !== void 0 && l !== void 0
529
+ generated: a,
530
+ managed: o !== void 0 && a !== void 0
511
531
  };
512
532
  }
513
- function ir(e) {
533
+ function $r(e) {
514
534
  return e === "slides" || e === "scroll";
515
535
  }
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));
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));
519
539
  return {
520
- width: Math.round(Xe / t),
521
- height: Math.round(Je / t)
540
+ width: Math.round(nt / n),
541
+ height: Math.round(rt / n)
522
542
  };
523
543
  }
524
- function nn(e) {
544
+ function En(e) {
525
545
  return {
526
546
  view: "scroll",
527
547
  scrollLayout: "compact",
@@ -531,11 +551,11 @@ function nn(e) {
531
551
  controls: !1,
532
552
  controlsTutorial: !1,
533
553
  hash: !1,
534
- ...tn(e.zoom),
535
- margin: en
554
+ ...yn(e.zoom),
555
+ margin: gn
536
556
  };
537
557
  }
538
- function rn() {
558
+ function xn() {
539
559
  return {
540
560
  // Explicitly null rather than absent: the same page may have been
541
561
  // delivered in scroll view a moment ago, and an embedder that re-injects
@@ -547,11 +567,11 @@ function rn() {
547
567
  // size with a percentage width renders its text far larger, relative to
548
568
  // the slide, than the same deck will on a projector. No zoom margin
549
569
  // though — presenting means filling whatever it is shown in.
550
- width: Xe,
551
- height: Je
570
+ width: nt,
571
+ height: rt
552
572
  };
553
573
  }
554
- const on = [
574
+ const Sn = [
555
575
  "<style>",
556
576
  ".reveal-viewport.reveal-scroll .scroll-page section {",
557
577
  " box-shadow: inset 0 0 0 calc(1px / var(--slide-scale, 1))",
@@ -559,18 +579,18 @@ const on = [
559
579
  "}",
560
580
  "</style>"
561
581
  ].join(`
562
- `), sn = [
582
+ `), Tn = [
563
583
  " var paused = document.querySelectorAll('.reveal .fragment');",
564
584
  " for (var i = 0; i < paused.length; i++) {",
565
585
  " paused[i].classList.remove('fragment');",
566
586
  " }"
567
587
  ];
568
- function an(e, n = {}) {
569
- const t = e === "scroll" ? nn(n) : rn();
588
+ function In(e, t = {}) {
589
+ const n = e === "scroll" ? En(t) : xn();
570
590
  return [
571
591
  "<script>",
572
592
  "(function () {",
573
- " var OVERRIDES = " + JSON.stringify(t) + ";",
593
+ " var OVERRIDES = " + JSON.stringify(n) + ";",
574
594
  // Nothing to wrap if reveal.js failed to load (offline, CDN blocked). The
575
595
  // deck is broken either way, but throwing here would replace the browser's
576
596
  // useful network error with a confusing one from an injected script.
@@ -594,7 +614,7 @@ function an(e, n = {}) {
594
614
  // Inside the wrapper rather than at top level: this script sits in <head>,
595
615
  // where the slides have not been parsed yet, but the deck calls initialize
596
616
  // from the end of the document, by which time they have.
597
- ...e === "scroll" ? sn : [],
617
+ ...e === "scroll" ? Tn : [],
598
618
  " return initialize(merged);",
599
619
  " };",
600
620
  "})();",
@@ -602,71 +622,82 @@ function an(e, n = {}) {
602
622
  ].join(`
603
623
  `);
604
624
  }
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);
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);
608
628
  if (!o)
609
629
  return i;
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
- r,
627
- H(I(n)),
630
+ const a = o.index + o[0].length, l = `
631
+ ${Ln}
632
+ ${Sn}
633
+ ${In(t, n)}
634
+ ${$n}`;
635
+ return i.slice(0, a) + l + i.slice(a);
636
+ }
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);
640
+ }
641
+ function ke(e, t, n) {
642
+ return e.cache ? e.cache.parse(t, n) : oe(n);
643
+ }
644
+ async function Ne(e, t, n, r = {}) {
645
+ const i = E(t), o = ke(r, i, e), a = {
646
+ ...r,
647
+ projectDir: E(n),
648
+ stack: [i],
649
+ files: [i],
650
+ bytes: e.length
651
+ }, l = await ie(
652
+ o,
653
+ Y(i),
628
654
  { "": "" },
629
- i
655
+ a
630
656
  );
631
- return { tree: r, content: o ? q(r) : e };
657
+ return {
658
+ tree: o,
659
+ content: l ? te(o) : e,
660
+ files: a.files,
661
+ bytes: a.bytes
662
+ };
632
663
  }
633
- function hn(e) {
664
+ function ot(e) {
634
665
  return e.data?.ptxIncludedFile;
635
666
  }
636
- function mn(e, n) {
637
- const t = e.data ?? (e.data = {});
638
- t.ptxIncludedFile = n;
667
+ function st(e, t) {
668
+ const n = e.data ?? (e.data = {});
669
+ n.ptxIncludedFile = t;
639
670
  }
640
- function ae(e, n) {
641
- let t = e;
642
- for (const [r, i] of Object.entries(n.attributes))
643
- (r === "xmlns" || r.startsWith("xmlns:")) && (t === e && (t = { ...e }), t[r === "xmlns" ? "" : r.slice(6)] = i ?? "");
644
- return t;
671
+ function he(e, t) {
672
+ let n = e;
673
+ for (const [r, i] of Object.entries(t.attributes))
674
+ (r === "xmlns" || r.startsWith("xmlns:")) && (n === e && (n = { ...e }), n[r === "xmlns" ? "" : r.slice(6)] = i ?? "");
675
+ return n;
645
676
  }
646
- function Ge(e, n) {
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] === ze;
677
+ function at(e, t) {
678
+ 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;
649
680
  }
650
- async function Z(e, n, t, r) {
681
+ async function ie(e, t, n, r) {
651
682
  let i = !1;
652
683
  for (let o = 0; o < e.children.length; o++) {
653
- const l = e.children[o];
654
- if (l.type !== "element")
684
+ const a = e.children[o];
685
+ if (a.type !== "element")
655
686
  continue;
656
- const u = ae(t, l);
657
- if (Ge(l, u)) {
658
- const m = await Ke(
687
+ const l = he(n, a);
688
+ if (at(a, l)) {
689
+ const h = await ct(
690
+ a,
691
+ t,
659
692
  l,
660
- n,
661
- u,
662
693
  r
663
694
  );
664
- e.children.splice(o, 1, ...m), o += m.length - 1, i = !0;
665
- } else await Z(l, n, u, r) && (i = !0);
695
+ e.children.splice(o, 1, ...h), o += h.length - 1, i = !0;
696
+ } else await ie(a, t, l, r) && (i = !0);
666
697
  }
667
698
  return i;
668
699
  }
669
- async function Ke(e, n, t, r) {
700
+ async function ct(e, t, n, r) {
670
701
  const i = r.stack[r.stack.length - 1];
671
702
  if (e.attributes.xpointer)
672
703
  throw new Error(
@@ -675,83 +706,86 @@ async function Ke(e, n, t, r) {
675
706
  const o = e.attributes.href;
676
707
  if (!o)
677
708
  throw new Error(`xi:include without href (in ${i})`);
678
- let l = o;
709
+ let a = o;
679
710
  try {
680
- l = decodeURIComponent(o);
711
+ a = decodeURIComponent(o);
681
712
  } catch {
682
713
  }
683
- const u = I(n, l);
684
- if (u !== r.projectDir && !u.startsWith(r.projectDir + he))
714
+ const l = E(t, a);
715
+ if (l !== r.projectDir && !l.startsWith(r.projectDir + Ie))
685
716
  throw new Error(
686
717
  `xi:include escapes the project directory: ${o} (in ${i})`
687
718
  );
688
- if (r.stack.includes(u))
719
+ if (r.stack.includes(l))
689
720
  throw new Error(
690
- `Circular xi:include: ${[...r.stack, u].join(" -> ")}`
721
+ `Circular xi:include: ${[...r.stack, l].join(" -> ")}`
691
722
  );
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;
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;
699
730
  throw new Error(`xi:include target not found: ${o} (in ${i})`);
700
731
  }
701
- if (e.attributes.parse === "text")
702
- return [{ type: "text", value: m }];
703
- let f;
732
+ if (r.files.includes(l) || r.files.push(l), r.bytes += h.length, e.attributes.parse === "text")
733
+ return [{ type: "text", value: h }];
734
+ let p;
704
735
  try {
705
- f = X(m);
706
- } catch (w) {
736
+ p = ke(r, l, h);
737
+ } catch (d) {
707
738
  throw new Error(
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.)`
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.)`
709
740
  );
710
741
  }
711
- r.stack.push(u);
742
+ r.stack.push(l);
712
743
  try {
713
- await Z(f, H(u), { "": "" }, r);
744
+ await ie(p, Y(l), { "": "" }, r);
714
745
  } finally {
715
746
  r.stack.pop();
716
747
  }
717
- const v = f.children.filter(
718
- (w) => w.type === "element"
748
+ const w = p.children.filter(
749
+ (d) => d.type === "element"
719
750
  );
720
- for (const w of v)
721
- mn(w, u);
722
- return v;
751
+ for (const d of w)
752
+ st(d, l);
753
+ return w;
723
754
  }
724
- function _e(e) {
755
+ function Ue(e) {
725
756
  return e.name === "docinfo";
726
757
  }
727
- async function wn(e, n, t) {
758
+ async function Nn(e, t, n, r = {}) {
728
759
  try {
729
- const i = X(e).children.find(
730
- (f) => f.type === "element"
760
+ const i = E(t), a = ke(r, i, e).children.find(
761
+ (w) => w.type === "element"
731
762
  );
732
- if (!i)
763
+ if (!a)
733
764
  return;
734
- const o = I(n), l = H(o), u = {
735
- projectDir: I(t),
736
- stack: [o]
737
- }, m = ae({ "": "" }, i);
738
- for (const f of i.children) {
739
- if (f.type !== "element")
765
+ const l = Y(i), h = {
766
+ ...r,
767
+ projectDir: E(n),
768
+ stack: [i],
769
+ files: [i],
770
+ bytes: e.length
771
+ }, p = he({ "": "" }, a);
772
+ for (const w of a.children) {
773
+ if (w.type !== "element")
740
774
  continue;
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,
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,
747
781
  l,
748
- v,
749
- u
782
+ d,
783
+ h
750
784
  )).find(
751
- (y) => y.type === "element" && _e(y)
785
+ (_) => _.type === "element" && Ue(_)
752
786
  );
753
- if (b)
754
- return q(b);
787
+ if (x)
788
+ return te(x);
755
789
  continue;
756
790
  }
757
791
  break;
@@ -761,78 +795,94 @@ async function wn(e, n, t) {
761
795
  return;
762
796
  }
763
797
  }
764
- function gn(e, n) {
765
- for (const t of e.children) {
766
- if (t.type !== "element")
798
+ function Rn(e, t) {
799
+ for (const n of e.children) {
800
+ if (n.type !== "element")
767
801
  continue;
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
- return t;
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)
804
+ return n;
771
805
  }
772
806
  }
773
- function Ye(e) {
807
+ function lt(e) {
774
808
  return typeof e == "object" && e !== null && e.type === "element";
775
809
  }
776
- function vn(e) {
810
+ function Pn(e) {
777
811
  return /^(pf|xhtml):/.test(e.name);
778
812
  }
779
- function bn(e, n, t) {
780
- const r = [], i = e.children.find(Ye);
813
+ function Cn(e, t, n) {
814
+ const r = [];
815
+ return ut(e, t, n, (i, o, a, l) => {
816
+ r.push({
817
+ id: o,
818
+ file: a,
819
+ line: i.position?.start.line ?? 1,
820
+ column: i.position?.start.column ?? 1,
821
+ endLine: i.position?.end.line ?? i.position?.start.line ?? 1,
822
+ parent: l
823
+ });
824
+ }), r;
825
+ }
826
+ function Dn(e, t, n) {
827
+ let r;
828
+ return ut(e, "", n, (i, o) => {
829
+ if (i === t)
830
+ return r = o, !1;
831
+ }), r;
832
+ }
833
+ function ut(e, t, n, r) {
834
+ const i = e.children.find(lt);
781
835
  if (i) {
782
- const o = t?.parentId ?? "root";
783
- qe(i, o, t?.position ?? 1, n, o, r);
836
+ const o = n?.parentId ?? "root";
837
+ ft(i, o, n?.position ?? 1, t, o, r);
784
838
  }
785
- return r;
786
839
  }
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";
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";
792
845
  else {
793
- const v = e.attributes.label ?? e.attributes["xml:id"];
794
- u = v ?? `${n}-${t}`, o.push({
795
- id: u,
796
- file: l,
797
- line: e.position?.start.line ?? 1,
798
- column: e.position?.start.column ?? 1,
799
- endLine: e.position?.end.line ?? e.position?.start.line ?? 1,
800
- parent: i
801
- }), m = u;
846
+ const w = e.attributes.label ?? e.attributes["xml:id"];
847
+ if (l = w ?? `${t}-${n}`, o(e, l, a, i) === !1)
848
+ return !1;
849
+ h = l;
802
850
  }
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,
851
+ let p = 0;
852
+ for (const w of e.children)
853
+ if (lt(w) && (p += 1, !ft(
854
+ w,
855
+ h,
856
+ p,
857
+ a,
858
+ l ?? i,
811
859
  o
812
- ));
860
+ )))
861
+ return !1;
862
+ return !0;
813
863
  }
814
- function or(e, n) {
815
- let t;
864
+ function _r(e, t) {
865
+ let n;
816
866
  for (const r of e)
817
- r.line <= n && (t = r);
818
- return t ?? e[0];
867
+ r.line <= t && (n = r);
868
+ return n ?? e[0];
819
869
  }
820
- function En(e) {
821
- const n = e.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!\[CDATA\[[\s\S]*?\]\]>/g, " ");
822
- return /<\s*slide(?:show)?[\s/>]/.test(n) ? "slides" : "html";
870
+ function Mn(e) {
871
+ const t = e.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!\[CDATA\[[\s\S]*?\]\]>/g, " ");
872
+ return /<\s*slide(?:show)?[\s/>]/.test(t) ? "slides" : "html";
823
873
  }
824
- const Ze = "pretext-html:set-theme";
825
- function sr(e) {
874
+ const dt = "pretext-html:set-theme";
875
+ function kr(e) {
826
876
  return e === "dark" || e === "light" || e === "system";
827
877
  }
828
- function ar(e) {
829
- return { type: Ze, theme: e };
878
+ function Nr(e) {
879
+ return { type: dt, theme: e };
830
880
  }
831
- function yn(e) {
881
+ function On(e) {
832
882
  return [
833
883
  "<script>",
834
884
  "(function () {",
835
- " var CFG = " + JSON.stringify({ msg: Ze, initial: e }) + ";",
885
+ " var CFG = " + JSON.stringify({ msg: dt, initial: e }) + ";",
836
886
  // Where the last requested theme is remembered so it survives an in-place
837
887
  // document rewrite (same Window) and outranks the baked initial value.
838
888
  " var KEY = '__ptxPreviewTheme';",
@@ -902,12 +952,12 @@ function yn(e) {
902
952
  ].join(`
903
953
  `);
904
954
  }
905
- function xn(e, n) {
906
- const t = yn(n);
955
+ function Bn(e, t) {
956
+ const n = On(t);
907
957
  return /<head[^>]*>/i.test(e) ? e.replace(/<head([^>]*)>/i, `<head$1>
908
- ${t}`) : e;
958
+ ${n}`) : e;
909
959
  }
910
- const Qe = /* @__PURE__ */ new Set([
960
+ const ht = /* @__PURE__ */ new Set([
911
961
  "colophon",
912
962
  "biography",
913
963
  "dedication",
@@ -927,216 +977,446 @@ const Qe = /* @__PURE__ */ new Set([
927
977
  "glossary",
928
978
  "worksheet",
929
979
  "handout"
930
- ]), et = /* @__PURE__ */ new Set([
980
+ ]), pt = /* @__PURE__ */ new Set([
931
981
  "book",
932
982
  "article",
933
983
  "slideshow",
934
984
  "letter",
935
985
  "memo"
936
- ]), tt = /* @__PURE__ */ new Set([
937
- ...et,
938
- ...Qe,
986
+ ]), z = /* @__PURE__ */ new Set([
987
+ ...pt,
988
+ ...ht,
939
989
  "part",
990
+ "foreword",
940
991
  "frontmatter",
941
992
  "backmatter"
942
- ]), Tn = /* @__PURE__ */ new Set(["docinfo"]), nt = /* @__PURE__ */ new Set([
993
+ ]);
994
+ function ge(e) {
995
+ return z.has(e.name);
996
+ }
997
+ const jn = /* @__PURE__ */ new Set(["docinfo"]), mt = /* @__PURE__ */ new Set([
943
998
  "title",
944
999
  "shorttitle",
945
1000
  "plaintitle",
946
1001
  "subtitle",
947
1002
  "caption"
948
1003
  ]);
949
- function O(e) {
1004
+ function N(e) {
950
1005
  return e.type === "element";
951
1006
  }
952
- function rt(e) {
1007
+ function wt(e) {
953
1008
  return e.attributes["xml:id"] ?? void 0;
954
1009
  }
955
- function ge(e, n) {
956
- for (const t of e.children) {
957
- if (!O(t)) continue;
958
- if (rt(t) === n) return t;
959
- const r = ge(t, n);
1010
+ function pe(e, t) {
1011
+ for (const n of e.children) {
1012
+ if (!N(n)) continue;
1013
+ if (wt(n) === t) return n;
1014
+ const r = pe(n, t);
960
1015
  if (r) return r;
961
1016
  }
962
1017
  }
963
- function oe(e, n) {
964
- for (const t of e.children) {
965
- if (!O(t)) continue;
966
- if (t === n) return [t];
967
- const r = oe(t, n);
968
- if (r) return [t, ...r];
1018
+ function X(e, t) {
1019
+ for (const n of e.children) {
1020
+ if (!N(n)) continue;
1021
+ if (n === t) return [n];
1022
+ const r = X(n, t);
1023
+ if (r) return [n, ...r];
969
1024
  }
970
1025
  }
971
- function Sn(e, n) {
972
- let t = 0;
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;
1028
+ }
1029
+ function me(e, t) {
1030
+ let n = 0;
973
1031
  for (const [r, i] of e.entries()) {
974
1032
  const o = r === 0 ? void 0 : e[r - 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);
1033
+ n = vt(n, o?.name, i.name, t);
976
1034
  }
977
- return t;
1035
+ return n;
1036
+ }
1037
+ function Re(e) {
1038
+ return e?.name === "book" && e.children.some(
1039
+ (t) => N(t) && t.name === "part"
1040
+ );
1041
+ }
1042
+ function Q(e, t) {
1043
+ return e.children.some(
1044
+ (n) => N(n) && t.includes(n.name)
1045
+ );
1046
+ }
1047
+ function Un(e) {
1048
+ if (!e) return 0;
1049
+ const t = e.name;
1050
+ if (t === "book") {
1051
+ const n = Re(e), r = n ? e.children.some(
1052
+ (o) => N(o) && o.name === "part" && Q(o, ["chapter"])
1053
+ ) : Q(e, ["chapter"]), i = (n ? e.children.flatMap(
1054
+ (o) => N(o) && o.name === "part" ? o.children : []
1055
+ ) : e.children).some(
1056
+ (o) => N(o) && o.name === "chapter" && Q(o, ["section"])
1057
+ );
1058
+ return n && i ? 3 : n && r || i ? 2 : r ? 1 : 0;
1059
+ }
1060
+ if (t === "article") {
1061
+ const n = e.children.filter(
1062
+ (r) => N(r) && r.name === "section"
1063
+ );
1064
+ if (n.some((r) => Q(r, ["subsection"])))
1065
+ return 2;
1066
+ if (n.length > 0 || Q(e, ["worksheet", "handout"]))
1067
+ return 1;
1068
+ }
1069
+ return 0;
1070
+ }
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;
978
1073
  }
979
- function it(e) {
980
- if (!nt.has(e.name)) {
981
- e.children = e.children.filter(O);
982
- for (const n of e.children)
983
- it(n);
1074
+ function Pe(e) {
1075
+ if (!mt.has(e.name)) {
1076
+ e.children = e.children.filter(N);
1077
+ for (const t of e.children)
1078
+ Pe(t);
984
1079
  }
985
1080
  }
986
- function ve(e, n) {
987
- const t = [];
988
- for (const r of e.children)
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
- e.children = t;
991
- }
992
- function An(e) {
993
- const n = /* @__PURE__ */ new Set(), t = (r) => {
994
- if (r.name === "xref") {
995
- const i = [
996
- r.attributes.ref,
997
- r.attributes.first,
998
- r.attributes.last
999
- ];
1000
- for (const o of i)
1001
- for (const l of o?.split(/[\s,]+/) ?? [])
1002
- l && n.add(l);
1081
+ function Wn(e) {
1082
+ for (const t of e.children)
1083
+ N(t) && !z.has(t.name) && Pe(t);
1084
+ }
1085
+ function Hn(e, t = !1) {
1086
+ const n = /* @__PURE__ */ new Set(), r = (i) => {
1087
+ if (!(t && i !== e && z.has(i.name))) {
1088
+ if (i.name === "xref") {
1089
+ const o = [
1090
+ i.attributes.ref,
1091
+ i.attributes.first,
1092
+ i.attributes.last
1093
+ ];
1094
+ for (const a of o)
1095
+ for (const l of a?.split(/[\s,]+/) ?? [])
1096
+ l && n.add(l);
1097
+ }
1098
+ for (const o of i.children)
1099
+ N(o) && r(o);
1003
1100
  }
1004
- for (const i of r.children)
1005
- O(i) && t(i);
1006
1101
  };
1007
- return t(e), n;
1102
+ return r(e), n;
1008
1103
  }
1009
- function In(e, n, t) {
1104
+ function Vn(e, t, n) {
1010
1105
  const r = (i) => {
1011
- for (const [o, l] of i.children.entries())
1012
- if (O(l)) {
1013
- if (rt(l) === n)
1014
- return i.children[o] = t, !0;
1015
- if (r(l)) return !0;
1106
+ for (const [o, a] of i.children.entries())
1107
+ if (N(a)) {
1108
+ if (wt(a) === t)
1109
+ return i.children[o] = n, !0;
1110
+ if (r(a)) return !0;
1016
1111
  }
1017
1112
  return !1;
1018
1113
  };
1019
1114
  return r(e);
1020
1115
  }
1021
- function Ln(e, n) {
1022
- const t = ge(e, n);
1023
- if (!t) return;
1024
- const r = oe(e, t);
1116
+ function bt(e, t, n) {
1117
+ const r = n.contentKept.has(e), i = n.chain.has(e), o = [];
1118
+ for (const a of e.children) {
1119
+ if (!N(a)) {
1120
+ r && o.push(a);
1121
+ continue;
1122
+ }
1123
+ if (n.verbatim.has(a) || jn.has(a.name) || mt.has(a.name))
1124
+ o.push(a);
1125
+ else if (z.has(a.name)) {
1126
+ const l = vt(
1127
+ t,
1128
+ e.name,
1129
+ a.name,
1130
+ n.hasParts
1131
+ );
1132
+ (n.chain.has(a) || i || l <= n.tocLevel) && (bt(a, l, n), o.push(a));
1133
+ } else r && o.push(a);
1134
+ }
1135
+ e.children = o;
1136
+ }
1137
+ function Xn(e, t, n = {}) {
1138
+ const r = pe(e, t);
1025
1139
  if (!r) return;
1026
- const i = r.filter(
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);
1140
+ const i = X(e, r);
1141
+ if (!i) return;
1142
+ 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 = {
1151
+ verbatim: /* @__PURE__ */ new Set(),
1152
+ chain: new Set(i),
1153
+ contentKept: /* @__PURE__ */ new Set(),
1154
+ tocLevel: _,
1155
+ 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);
1165
+ return;
1166
+ }
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);
1173
+ }
1174
+ };
1175
+ for (const g of Hn(r, o)) {
1176
+ const k = pe(e, g);
1177
+ k && k !== r && q(k);
1178
+ }
1179
+ for (const g of [...T.chain]) {
1180
+ if (!z.has(g.name) || d(g) <= x)
1181
+ 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));
1042
1187
  }
1188
+ }
1189
+ const O = e.children.find(N);
1190
+ O && bt(O, 0, T);
1191
+ 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 };
1196
+ }
1197
+ class zn {
1198
+ entries = /* @__PURE__ */ new Map();
1199
+ maxEntries;
1200
+ /** Cumulative hit/miss counts, for diagnostics and tests. */
1201
+ hits = 0;
1202
+ misses = 0;
1203
+ constructor(t = {}) {
1204
+ this.maxEntries = Math.max(1, t.maxEntries ?? 1024);
1205
+ }
1206
+ /**
1207
+ * The parse of `content`, as a fresh tree the caller may mutate freely.
1208
+ * `key` names the file — a path — so that a changed file replaces its own
1209
+ * entry instead of accumulating one per version.
1210
+ *
1211
+ * Throws what `fromXml` throws for malformed content; nothing is cached
1212
+ * then.
1213
+ */
1214
+ parse(t, n) {
1215
+ const r = this.entries.get(t);
1216
+ if (r && r.content === n)
1217
+ return this.hits += 1, this.entries.delete(t), this.entries.set(t, r), Le(r.tree);
1218
+ this.misses += 1;
1219
+ const i = oe(n);
1220
+ for (this.entries.delete(t), this.entries.set(t, { content: n, tree: i }); this.entries.size > this.maxEntries; ) {
1221
+ const o = this.entries.keys().next().value;
1222
+ if (o === void 0) break;
1223
+ this.entries.delete(o);
1043
1224
  }
1044
- for (const b of r) {
1045
- if (b === t) break;
1046
- ve(b, m);
1225
+ return Le(i);
1226
+ }
1227
+ /** Number of files currently held. */
1228
+ get size() {
1229
+ return this.entries.size;
1230
+ }
1231
+ /** Drop one file (when the host knows it is gone), or everything. */
1232
+ invalidate(t) {
1233
+ t === void 0 ? this.entries.clear() : this.entries.delete(t);
1047
1234
  }
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
- }
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
- const n = /* @__PURE__ */ new Set();
1056
- for (const t of e.matchAll(Rn))
1057
- n.add(t[1]);
1058
- return n;
1059
1235
  }
1060
- function Pn(e) {
1236
+ function Le(e) {
1237
+ 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;
1239
+ }
1240
+ function we(e) {
1241
+ return typeof e == "object" && e !== null && e.type === "element";
1242
+ }
1243
+ function Jn(e) {
1244
+ 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);
1254
+ return o && i(o, t, []), r;
1255
+ }
1256
+ function Kn(e, t, n, r) {
1257
+ const i = Gn(e, t, n);
1258
+ 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);
1262
+ }
1263
+ return o ?? a ?? l;
1264
+ }
1265
+ function Yn(e, t, n) {
1266
+ let r;
1267
+ if (t.id !== void 0) {
1268
+ const d = pe(e, t.id), L = d && X(e, d);
1269
+ r = L && Jn(L);
1270
+ } else if (t.line !== void 0) {
1271
+ const d = E(n), L = E(t.file ?? n);
1272
+ r = Kn(e, d, L, t.line);
1273
+ }
1274
+ if (!r) return;
1275
+ const i = t.level ?? 1 / 0;
1276
+ let o = !1;
1277
+ 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;
1287
+ break;
1288
+ }
1289
+ }
1290
+ else w < i && (o = !0);
1291
+ return { element: r, id: gt(e, r), collapse: o };
1292
+ }
1293
+ function gt(e, t) {
1294
+ const n = t.attributes["xml:id"];
1295
+ if (n) return n;
1296
+ const r = Dn(e, t) ?? "root-1";
1297
+ return t.attributes["xml:id"] = r, r;
1298
+ }
1299
+ function ve(e) {
1300
+ let t = 0;
1301
+ for (const n of e.children)
1302
+ we(n) && (t += 1 + ve(n));
1303
+ return t;
1304
+ }
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) {
1307
+ const t = /* @__PURE__ */ new Set();
1308
+ for (const n of e.matchAll(Qn))
1309
+ t.add(n[1]);
1310
+ return t;
1311
+ }
1312
+ function xe(e) {
1061
1313
  return e.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1062
1314
  }
1063
- function Re(e, n) {
1315
+ function We(e, t) {
1064
1316
  if (e.startsWith("#") || e === "") return { kind: "keep" };
1065
1317
  if (/^[a-z][a-z0-9+.-]*:/i.test(e) || e.startsWith("//"))
1066
1318
  return { kind: "keep" };
1067
- const t = e.indexOf("#");
1068
- if (t === -1) return { kind: "off-page" };
1069
- const r = e.slice(t + 1);
1070
- return n.has(r) && r !== "" ? { kind: "same-page", id: r } : { kind: "off-page" };
1071
- }
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;
1319
+ const n = e.indexOf("#"), i = (n === -1 ? e : e.slice(0, n)).replace(/\.html?$/i, "");
1320
+ if (n === -1) return { kind: "off-page", division: i };
1321
+ const o = e.slice(n + 1);
1322
+ return t.has(o) && o !== "" ? { kind: "same-page", id: o } : { kind: "off-page", division: i, ...o ? { id: o } : {} };
1323
+ }
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);
1328
+ 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);
1337
+ return l.kind === "same-page" ? `\\href{#${l.id}}` : o;
1086
1338
  });
1087
1339
  }
1088
- function Mn() {
1089
- return Oe(se(), "xsl");
1340
+ function rr() {
1341
+ return Ge(fe(), "xsl");
1090
1342
  }
1091
- function Cn() {
1343
+ function ir() {
1092
1344
  return "Suspending" in WebAssembly;
1093
1345
  }
1094
- function On() {
1095
- if (!Cn())
1346
+ function or() {
1347
+ if (!ir())
1096
1348
  throw new Error(
1097
1349
  "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
1350
  );
1099
1351
  }
1100
- function Y(e) {
1101
- return e.includes("'") ? e.includes('"') ? `concat(${e.split("'").map((t) => `'${t}'`).join(`, "'", `)})` : `"${e}"` : `'${e}'`;
1352
+ function re(e) {
1353
+ return e.includes("'") ? e.includes('"') ? `concat(${e.split("'").map((n) => `'${n}'`).join(`, "'", `)})` : `"${e}"` : `'${e}'`;
1102
1354
  }
1103
- function Bn(e) {
1355
+ function sr(e) {
1104
1356
  return e.replace(
1105
1357
  /from '\.\/(https:\/\/[^']+)'/g,
1106
- (n, t) => `from '${t}'`
1358
+ (t, n) => `from '${n}'`
1107
1359
  );
1108
1360
  }
1109
- const jn = `https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@${je}/dist/`, Un = {
1110
- "cli.version": je,
1361
+ const ar = `https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@${Ye}/dist/`, cr = {
1362
+ "cli.version": Ye,
1111
1363
  // Colon-delimited: pretext-runestone.xsl splits them with str:tokenize.
1112
- "rs-js": xt.join(":"),
1113
- "rs-css": Tt.join(":"),
1114
- "rs-version": yt
1364
+ "rs-js": jt.join(":"),
1365
+ "rs-css": Ut.join(":"),
1366
+ "rs-version": Bt
1115
1367
  };
1116
- function Fn(e) {
1368
+ function lr(e) {
1117
1369
  return e.replace(
1118
1370
  /(<link\b[^>]*\bhref=["'])_static\//gi,
1119
- `$1${jn}_static/`
1371
+ `$1${ar}_static/`
1120
1372
  );
1121
1373
  }
1122
- function Wn(e) {
1374
+ function ur(e) {
1123
1375
  return e.slice(0, 65536).replace(/<\?[\s\S]*?\?>/g, " ").replace(/<!--[\s\S]*?-->/g, " ").replace(/<!DOCTYPE[^>]*>/gi, " ").match(/<\s*([A-Za-z][\w:-]*)/)?.[1];
1124
1376
  }
1125
- async function ke(e) {
1126
- const n = await ce(e);
1377
+ let fr;
1378
+ function dr() {
1379
+ return fr ??= new zn();
1380
+ }
1381
+ function yt(e) {
1382
+ const t = e.files ? new Map(
1383
+ Object.entries(e.files).map(([o, a]) => [
1384
+ E(o),
1385
+ a
1386
+ ])
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();
1388
+ return { readSource: r, cache: i };
1389
+ }
1390
+ async function $e(e, t) {
1391
+ const n = await be(e, t);
1127
1392
  if (n === void 0)
1128
1393
  throw new Error(
1129
- `Could not read ${e}. (In the browser build only absolute URLs are readable — pass sourceContent instead of relying on sourcePath.)`
1394
+ `Could not read ${t}. (In the browser build only absolute URLs are readable — pass sourceContent instead of relying on sourcePath.)`
1130
1395
  );
1131
1396
  return n;
1132
1397
  }
1133
- async function Hn(e, n) {
1134
- const t = I(e), r = await ce(t);
1135
- if (r !== void 0)
1136
- return wn(r, t, n);
1398
+ async function hr(e, t, n) {
1399
+ const r = E(e), i = await be(n, r);
1400
+ if (i !== void 0)
1401
+ return Nn(i, r, t, n);
1402
+ }
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(
1407
+ i,
1408
+ n,
1409
+ r,
1410
+ t
1411
+ );
1412
+ return {
1413
+ bytes: o.bytes,
1414
+ elements: ve(o.tree),
1415
+ files: o.files
1416
+ };
1137
1417
  }
1138
- function Vn(e, n, t, r) {
1139
- const i = e.replace(/^\uFEFF/, "").replace(/<\?xml[\s\S]*?\?>/, "").replace(/<!DOCTYPE[^>]*>/i, ""), o = t === "slides" ? "slideshow" : n === "chapter" || n === "part" ? "book" : "article";
1418
+ function pr(e, t, n, r) {
1419
+ const i = e.replace(/^\uFEFF/, "").replace(/<\?xml[\s\S]*?\?>/, "").replace(/<!DOCTYPE[^>]*>/i, ""), o = n === "slides" ? "slideshow" : t === "chapter" || t === "part" ? "book" : "article";
1140
1420
  return `<pretext>
1141
1421
  ${r?.trim() ? `${r.trim()}
1142
1422
  ` : ""}<${o}>
@@ -1146,207 +1426,234 @@ ${i}
1146
1426
  </pretext>
1147
1427
  `;
1148
1428
  }
1149
- async function Xn(e, n, t, r) {
1150
- const i = X(e).children.find(
1151
- (v) => v.type === "element"
1152
- ), o = i?.attributes["xml:id"];
1153
- if (!i || !o) return;
1154
- const l = I(n), u = r ?? await ce(l);
1155
- if (u === void 0) return;
1156
- let m;
1429
+ async function mr(e, t, n, r, i, o) {
1430
+ const a = e.attributes["xml:id"];
1431
+ 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;
1157
1435
  try {
1158
- m = (await Ee(u, l, t)).tree;
1436
+ ({ tree: p, files: w, bytes: d } = await Ne(
1437
+ h,
1438
+ l,
1439
+ r,
1440
+ o
1441
+ ));
1159
1442
  } catch {
1160
1443
  return;
1161
1444
  }
1162
- if (!In(m, o, i)) return;
1163
- const f = Ln(m, o);
1164
- if (f)
1165
- return { ...f, tree: m };
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 };
1166
1447
  }
1167
- let ot = !1;
1168
- function Jn(e) {
1448
+ let Et = !1;
1449
+ function wr(e) {
1169
1450
  return e instanceof Error && /\bAborted\(/.test(e.message);
1170
1451
  }
1171
- function zn(e) {
1452
+ function vr(e) {
1172
1453
  return e instanceof Error && /memory access|out of bounds/i.test(e.message);
1173
1454
  }
1174
- function Gn() {
1175
- if (ot)
1455
+ function br() {
1456
+ if (Et)
1176
1457
  throw new Error(
1177
1458
  "The WebAssembly renderer aborted earlier in this process and cannot be reused. Restart the process (or reload the page) to render again."
1178
1459
  );
1179
1460
  }
1180
- function Ne(e) {
1181
- if (Jn(e))
1182
- throw ot = !0, new Error(
1461
+ function He(e) {
1462
+ if (wr(e))
1463
+ throw Et = !0, new Error(
1183
1464
  "The WebAssembly renderer aborted and cannot be reused. Restart the process (or reload the page) to render again.",
1184
1465
  { cause: e }
1185
1466
  );
1186
- if (zn(e))
1467
+ if (vr(e))
1187
1468
  throw new Error(
1188
1469
  "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
1470
  { cause: e }
1190
1471
  );
1191
1472
  }
1192
- let fe;
1193
- async function st() {
1194
- return fe || (fe = (async () => {
1195
- const [e, n] = await Promise.all([
1473
+ let Se;
1474
+ async function xt() {
1475
+ return Se || (Se = (async () => {
1476
+ const [e, t] = await Promise.all([
1196
1477
  import("@pretextbook/libxslt-wasm"),
1197
1478
  import("@pretextbook/libxslt-wasm/exslt")
1198
1479
  ]);
1199
- return n.registerAll(), e;
1200
- })()), fe;
1480
+ return t.registerAll(), e;
1481
+ })()), Se;
1201
1482
  }
1202
- const pe = /* @__PURE__ */ new Map(), Kn = {
1483
+ const Te = /* @__PURE__ */ new Map(), gr = {
1203
1484
  html: "preview-html.xsl",
1204
1485
  slides: "preview-revealjs.xsl"
1205
1486
  };
1206
- async function Yn(e, n) {
1207
- const t = Kn[n], r = `${n}\0${e}`;
1208
- let i = pe.get(r);
1487
+ async function yr(e, t) {
1488
+ const n = gr[t], r = `${t}\0${e}`;
1489
+ let i = Te.get(r);
1209
1490
  return i || (i = (async () => {
1210
- const { XmlDocument: o, XsltStylesheet: l } = await st(), u = He(e), m = await Be(se(), `/${t}`);
1211
- if (m === void 0)
1491
+ const { XmlDocument: o, XsltStylesheet: a } = await xt(), l = et(e), h = await Ke(fe(), `/${n}`);
1492
+ if (h === void 0)
1212
1493
  throw new Error(
1213
- `Could not read ${t} from ${se()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
1494
+ `Could not read ${n} from ${fe()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
1214
1495
  );
1215
- const f = new TextDecoder().decode(m), v = await o.fromString(f, {
1216
- url: `${u}/${t}`,
1496
+ const p = new TextDecoder().decode(h), w = await o.fromString(p, {
1497
+ url: `${l}/${n}`,
1217
1498
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
1218
1499
  });
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)
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)
1227
1508
  );
1228
- return Pe = n.catch(() => {
1229
- }), n;
1230
- }
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
- if (o.startsWith(".."))
1509
+ return Ve = t.catch(() => {
1510
+ }), t;
1511
+ }
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)
1516
+ ), o = e.sourceContent ?? await $e(n, r), a = ye(i, r);
1517
+ if (a.startsWith(".."))
1237
1518
  throw new Error(
1238
- `sourcePath (${t}) must live inside projectDir (${r})`
1519
+ `sourcePath (${r}) must live inside projectDir (${i})`
1239
1520
  );
1240
- const l = ue(
1241
- r,
1242
- I(e.mainSourcePath ?? t)
1243
- ), u = l.startsWith("..") ? o : l, m = He(r);
1521
+ const l = ye(
1522
+ i,
1523
+ E(e.mainSourcePath ?? r)
1524
+ ), h = l.startsWith("..") ? a : l, p = et(i);
1244
1525
  try {
1245
- let f, v = `${m}/__pretext-preview-publication.xml`;
1526
+ let w, d = `${p}/__pretext-preview-publication.xml`;
1246
1527
  if (e.publicationPath) {
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("/")}`);
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("/")}`);
1251
1532
  }
1252
- let w, b;
1253
- if (e.sourceMap) {
1254
- const h = await Ee(
1255
- i,
1256
- t,
1257
- r
1258
- );
1259
- w = h.tree, b = h.content;
1260
- } else
1261
- b = await pn(
1262
- i,
1263
- t,
1264
- r
1265
- );
1266
- const y = e.target ?? En(b), B = await Yn(e.xslDir ?? Mn(), y), $ = qt(f, {
1533
+ const L = await Ne(
1534
+ o,
1535
+ r,
1536
+ i,
1537
+ n
1538
+ );
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, {
1267
1541
  cssTheme: e.cssTheme,
1268
1542
  revealTheme: e.revealTheme,
1269
- target: y
1543
+ target: D
1270
1544
  });
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") {
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)
1562
+ });
1563
+ return m ? (_ = m.content, I = {
1564
+ id: m.divisionId,
1565
+ level: m.level,
1566
+ collapsed: m.collapsed,
1567
+ children: m.collapsed ? v : []
1568
+ }, !0) : !1;
1569
+ };
1570
+ if (P !== "pretext" && P !== "mathbook") {
1278
1571
  if (!e.fragment)
1279
1572
  throw new Error(
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.`
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.`
1281
1574
  );
1575
+ let s = !1;
1282
1576
  if (e.contextSourcePath || e.contextSourceContent) {
1283
- const h = e.contextSourcePath ?? at(H(t), "__pretext-preview-context.ptx"), S = await Xn(
1284
- b,
1285
- h,
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,
1286
1581
  r,
1287
- e.contextSourceContent
1288
- );
1289
- S && (b = S.content, w = e.sourceMap ? S.tree : void 0, Q = I(h), j = { divisionId: S.divisionId, level: S.level });
1582
+ c,
1583
+ i,
1584
+ e.contextSourceContent,
1585
+ n
1586
+ ) : void 0;
1587
+ f && (s = !0, x = f.tree, T = f.files, F = f.bytes, se = E(c), ae(x, f.divisionId) || (_ = te(x)));
1290
1588
  }
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 };
1589
+ if (!s) {
1590
+ const c = e.docinfo ?? (e.docinfoSourcePath ? await hr(
1591
+ e.docinfoSourcePath,
1592
+ i,
1593
+ n
1594
+ ) : void 0);
1595
+ _ = pr(
1596
+ _,
1597
+ P,
1598
+ D,
1599
+ c
1600
+ ), B = { parentId: c?.trim() ? "root-1-2" : "root-1-1", position: 2 };
1299
1601
  }
1300
- }
1301
- const ee = w ? bn(w, Q, G) : void 0, te = await n.fromString(b, {
1302
- url: `${m}/${u.split(he).join("/")}`,
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("/")}`,
1303
1606
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
1304
- }), M = {
1305
- publisher: Y(v)
1607
+ }), W = {
1608
+ publisher: re(d)
1306
1609
  };
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;
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))
1614
+ ));
1615
+ for (const [s, c] of Object.entries(e.stringParams ?? {}))
1616
+ W[s] = re(c);
1617
+ let Z;
1313
1618
  try {
1314
- K = await B.apply(te, M);
1315
- } catch (h) {
1316
- throw Ne(h), new Error(
1619
+ Z = await q.apply(ne, W);
1620
+ } catch (s) {
1621
+ throw He(s), new Error(
1317
1622
  "PreTeXt XSLT transform failed; see the PTX:ERROR/PTX:FATAL messages on stderr for details.",
1318
- { cause: h }
1623
+ { cause: s }
1319
1624
  );
1320
1625
  } finally {
1321
- te.delete();
1626
+ ne.delete();
1322
1627
  }
1323
1628
  try {
1324
- let h = Bn(K.toHtmlString());
1325
- h = Dn(h, {
1629
+ let s = sr(Z.toHtmlString());
1630
+ s = nr(s, {
1326
1631
  ...e.offPageMessage !== void 0 ? { offPageMessage: e.offPageMessage } : {}
1327
- }), (e.openKnowls ?? !0) && (h = _t(h)), y === "slides" ? (h = Fn(h), h = fn(h, e.revealView ?? "scroll", {
1632
+ }), (e.openKnowls ?? !0) && (s = Xt(s)), D === "slides" ? (s = lr(s), s = kn(s, e.revealView ?? "scroll", {
1328
1633
  zoom: e.revealZoom
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 } : {}
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)), {
1637
+ 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 } : {}
1338
1645
  };
1339
- } catch (h) {
1340
- throw Ne(h), h;
1646
+ } catch (s) {
1647
+ throw He(s), s;
1341
1648
  } finally {
1342
- K.delete();
1649
+ Z.delete();
1343
1650
  }
1344
1651
  } finally {
1345
- Pt(m);
1652
+ Yt(p);
1346
1653
  }
1347
1654
  }
1348
- const qn = "__ptxLivePatch";
1349
- function Zn(e, n, t) {
1655
+ const Er = "__ptxLivePatch";
1656
+ function xr(e, t, n) {
1350
1657
  const r = "script, #latex-macros, [data-component], .ptx-runestone-container", i = /* @__PURE__ */ new Set([
1351
1658
  "BODY",
1352
1659
  "MAIN",
@@ -1405,246 +1712,246 @@ function Zn(e, n, t) {
1405
1712
  "U",
1406
1713
  "VAR",
1407
1714
  "WBR"
1408
- ]), l = ["clipboardable"], u = 25e4, m = 3, f = [], v = /* @__PURE__ */ new Map();
1409
- function w(s) {
1715
+ ]), a = ["clipboardable"], l = 25e4, h = 3, p = [], w = /* @__PURE__ */ new Map();
1716
+ function d(s) {
1410
1717
  return { bail: s };
1411
1718
  }
1412
- function b(s) {
1719
+ function L(s) {
1413
1720
  return typeof s == "object" && s !== null && typeof s.bail == "string";
1414
1721
  }
1415
- function y(s) {
1722
+ function x(s) {
1416
1723
  return s.matches(r) || s.querySelector(r) !== null;
1417
1724
  }
1418
- function B(s) {
1725
+ function _(s) {
1419
1726
  return s.tagName === "SCRIPT" && !s.hasAttribute("src") && (s.textContent ?? "").indexOf("ptx_lunr_docs") !== -1;
1420
1727
  }
1421
- function $(s) {
1728
+ function T(s) {
1422
1729
  if (!i.has(s.tagName) || s.matches(".process-math") || // Never looked inside: a change anywhere in one is a change to it.
1423
1730
  s.matches(r))
1424
1731
  return !1;
1425
- for (const a of Array.from(s.childNodes))
1426
- if (a.nodeType === m && /\S/.test(a.nodeValue ?? ""))
1732
+ for (const c of Array.from(s.childNodes))
1733
+ if (c.nodeType === h && /\S/.test(c.nodeValue ?? ""))
1427
1734
  return !1;
1428
1735
  if (s.tagName === "DIV" || s.tagName === "LI") {
1429
- for (const a of Array.from(s.children))
1430
- if (o.has(a.tagName.toUpperCase()))
1736
+ for (const c of Array.from(s.children))
1737
+ if (o.has(c.tagName.toUpperCase()))
1431
1738
  return !1;
1432
1739
  }
1433
1740
  return !0;
1434
1741
  }
1435
- function k(s) {
1436
- return l.indexOf(s) !== -1;
1742
+ function F(s) {
1743
+ return a.indexOf(s) !== -1;
1437
1744
  }
1438
- function J(s, a) {
1439
- if (s.tagName !== a.tagName)
1745
+ function D(s, c) {
1746
+ if (s.tagName !== c.tagName)
1440
1747
  return !1;
1441
- const c = a.getAttribute("id");
1442
- if (c !== null && s.getAttribute("id") !== c)
1748
+ const u = c.getAttribute("id");
1749
+ if (u !== null && s.getAttribute("id") !== u)
1443
1750
  return !1;
1444
- for (const d of Array.from(a.classList))
1445
- if (!k(d))
1446
- return s.classList.contains(d);
1751
+ for (const f of Array.from(c.classList))
1752
+ if (!F(f))
1753
+ return s.classList.contains(f);
1447
1754
  return !0;
1448
1755
  }
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 });
1756
+ function q(s, c) {
1757
+ const u = Array.from(s.children), f = [];
1758
+ let b = 0;
1759
+ for (const v of c) {
1760
+ let m = null;
1761
+ for (; !m && b < u.length; ) {
1762
+ 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 });
1457
1764
  }
1458
- if (!p)
1765
+ if (!m)
1459
1766
  return null;
1460
- d.push(p);
1767
+ f.push(m);
1461
1768
  }
1462
- return d;
1769
+ return f;
1463
1770
  }
1464
- function N(s, a) {
1465
- if (s.attributes.length !== a.attributes.length)
1771
+ function O(s, c) {
1772
+ if (s.attributes.length !== c.attributes.length)
1466
1773
  return !1;
1467
- for (const c of Array.from(s.attributes))
1468
- if (a.getAttributeNS(c.namespaceURI, c.localName) !== c.value)
1774
+ for (const u of Array.from(s.attributes))
1775
+ if (c.getAttributeNS(u.namespaceURI, u.localName) !== u.value)
1469
1776
  return !1;
1470
1777
  return !0;
1471
1778
  }
1472
- function G(s) {
1779
+ function g(s) {
1473
1780
  return s.outerHTML.replace(/<([A-Za-z][^\s/>]*)\s[^>]*>/g, "<$1>");
1474
1781
  }
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;
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;
1478
1785
  }
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;
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]);
1795
+ 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++;
1799
+ return V;
1493
1800
  }
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++] = _++;
1801
+ function P(s, c) {
1802
+ const u = c.map(() => -1);
1803
+ let f = 0;
1804
+ for (; f < s.length && f < c.length && s[f].isEqualNode(c[f]); )
1805
+ 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)
1811
+ 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++;
1512
1819
  continue;
1513
1820
  }
1514
- let C = _ + 1;
1515
- for (; C < T && s[C].tagName !== a[A].tagName; )
1516
- C++;
1517
- C < T ? _ = C : A++;
1821
+ let V = C + 1;
1822
+ for (; V < A && s[V].tagName !== c[$].tagName; )
1823
+ V++;
1824
+ V < A ? C = V : $++;
1518
1825
  }
1519
- T < E && (c[L] = T), _ = T + 1, A = L + 1;
1826
+ A < b && (u[R] = A), C = A + 1, $ = R + 1;
1520
1827
  }
1521
- return c;
1828
+ return u;
1522
1829
  }
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 };
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 };
1527
1834
  }
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)
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);
1838
+ if (f.length !== b.length)
1532
1839
  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])))
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])))
1536
1843
  return !1;
1537
1844
  return !0;
1538
1845
  }
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(
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);
1851
+ 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)) {
1854
+ const f = p.length;
1855
+ if (I(s.inner, c, u)) {
1856
+ if (x(c))
1857
+ throw d(
1551
1858
  "attributes changed inside an element that needs a full page load"
1552
1859
  );
1553
- return { next: c, outer: s.outer };
1860
+ return { next: u, outer: s.outer };
1554
1861
  }
1555
- f.length = d;
1862
+ p.length = f;
1556
1863
  }
1557
- return { ...te(a, c), outer: s.outer };
1864
+ return { ...B(c, u), outer: s.outer };
1558
1865
  }
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)
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)
1562
1869
  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`
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`
1570
1877
  );
1571
- R.push({ next: A });
1878
+ M.push({ next: $ });
1572
1879
  return;
1573
1880
  }
1574
- x[L] = !0, R.push(K(g[L], d[L], A));
1881
+ y[R] = !0, M.push(se(v[R], f[R], $));
1575
1882
  });
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`
1883
+ const C = [];
1884
+ return f.forEach(($, A) => {
1885
+ if (!y[A]) {
1886
+ if (x($))
1887
+ throw d(
1888
+ `removing <${$.tagName.toLowerCase()}> needs a full page load`
1582
1889
  );
1583
- _.push(g[T].outer);
1890
+ C.push(v[A].outer);
1584
1891
  }
1585
1892
  }), {
1586
1893
  live: s,
1587
- first: g.length ? g[0].outer : null,
1588
- items: R,
1589
- removed: _
1894
+ first: v.length ? v[0].outer : null,
1895
+ items: M,
1896
+ removed: C
1590
1897
  };
1591
1898
  }
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");
1899
+ 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");
1903
+ 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");
1604
1911
  }
1605
1912
  }
1606
- return c;
1913
+ return u;
1607
1914
  }
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);
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);
1619
1926
  }
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;
1927
+ const ne = [], W = [];
1928
+ function Z(s) {
1929
+ let c = null;
1930
+ for (const u of s.items) {
1931
+ if (!u.outer || u.replace) {
1932
+ 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;
1627
1934
  continue;
1628
1935
  }
1629
- c.sub && xe(c.sub), a = c.outer;
1936
+ u.sub && Z(u.sub), c = u.outer;
1630
1937
  }
1631
- for (const c of s.removed)
1632
- c.remove(), le.push(c);
1938
+ for (const u of s.removed)
1939
+ u.remove(), W.push(u);
1633
1940
  }
1634
1941
  try {
1635
- const s = S(), a = {
1942
+ const s = ae(), c = {
1636
1943
  live: e.documentElement,
1637
- old: n.documentElement,
1638
- next: t.documentElement
1944
+ old: t.documentElement,
1945
+ next: n.documentElement
1639
1946
  };
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 };
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);
1950
+ 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 };
1646
1953
  } catch (s) {
1647
- if (b(s))
1954
+ if (L(s))
1648
1955
  return {
1649
1956
  ok: !1,
1650
1957
  reason: s.bail,
@@ -1655,65 +1962,68 @@ function Zn(e, n, t) {
1655
1962
  throw s;
1656
1963
  }
1657
1964
  }
1658
- function Qn(e, n) {
1659
- const t = e.MathJax, r = t && t.startup;
1660
- if (!t || !r || !r.promise || typeof t.typesetPromise != "function")
1965
+ function Sr(e, t) {
1966
+ const n = e.MathJax, r = n && n.startup;
1967
+ if (!n || !r || !r.promise || typeof n.typesetPromise != "function")
1661
1968
  return Promise.resolve();
1662
1969
  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;
1970
+ for (const l of t.added)
1971
+ l.matches(".process-math") ? i.push(l) : i.push(...Array.from(l.querySelectorAll(".process-math")));
1972
+ const o = t.removed;
1666
1973
  if (i.length === 0 && o.length === 0)
1667
1974
  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(
1975
+ const a = r.promise.then(() => (o.length && typeof n.typesetClear == "function" && n.typesetClear(o), i.length && n.typesetPromise ? n.typesetPromise(i) : void 0)).then(
1669
1976
  () => {
1670
1977
  },
1671
- (u) => {
1672
- console.error("pretext-html: typesetting a live patch failed", u);
1978
+ (l) => {
1979
+ console.error("pretext-html: typesetting a live patch failed", l);
1673
1980
  }
1674
1981
  );
1675
- return r.promise = l, l;
1982
+ return r.promise = a, a;
1676
1983
  }
1677
- function lr() {
1984
+ function Cr() {
1678
1985
  return [
1679
1986
  "<script>",
1680
- `window[${JSON.stringify(qn)}] = {`,
1681
- ` patchDocument: ${Zn.toString()},`,
1682
- ` typeset: ${Qn.toString()}`,
1987
+ `window[${JSON.stringify(Er)}] = {`,
1988
+ ` patchDocument: ${xr.toString()},`,
1989
+ ` typeset: ${Sr.toString()}`,
1683
1990
  "};",
1684
1991
  "<\/script>"
1685
1992
  ].join(`
1686
1993
  `);
1687
1994
  }
1688
1995
  export {
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
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
1719
2029
  };