@pretextbook/pretext-html 0.16.1 → 0.18.0

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