@pretextbook/pretext-html 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/assets/preview-html.xsl +16 -0
  2. package/assets/upstream.json +1 -1
  3. package/assets/xsl/extract-dynamic.xsl +54 -3
  4. package/assets/xsl/extract-gdscript.xsl +61 -0
  5. package/assets/xsl/extract-sageplot.xsl +3 -0
  6. package/assets/xsl/localizations/it-IT.xml +37 -41
  7. package/assets/xsl/pretext-assembly.xsl +188 -24
  8. package/assets/xsl/pretext-beamer.xsl +57 -12
  9. package/assets/xsl/pretext-common.xsl +156 -28
  10. package/assets/xsl/pretext-epub.xsl +0 -5
  11. package/assets/xsl/pretext-fo.xsl +110 -48
  12. package/assets/xsl/pretext-html.xsl +147 -54
  13. package/assets/xsl/pretext-jupyter.xsl +1 -0
  14. package/assets/xsl/pretext-latex-classic.xsl +2 -2
  15. package/assets/xsl/pretext-latex-common.xsl +268 -134
  16. package/assets/xsl/pretext-latex.xsl +16 -6
  17. package/assets/xsl/pretext-numbers.xsl +10 -0
  18. package/assets/xsl/pretext-revealjs.xsl +68 -1
  19. package/assets/xsl/pretext-runestone-fitb.xsl +179 -84
  20. package/assets/xsl/pretext-runestone-static.xsl +72 -20
  21. package/assets/xsl/pretext-runestone.xsl +27 -4
  22. package/assets/xsl/pretext-text-utilities.xsl +7 -0
  23. package/assets/xsl/pretext-text.xsl +17 -0
  24. package/assets/xsl/publisher-variables.xsl +39 -0
  25. package/assets/xsl-bundle.json +1 -1
  26. package/dist/cli-BUrNZxov.js +1098 -0
  27. package/dist/cli.js +1 -1
  28. package/dist/html-static.d.ts +2 -2
  29. package/dist/index.browser.js +595 -386
  30. package/dist/index.d.ts +4 -0
  31. package/dist/index.js +35 -30
  32. package/dist/renderer.d.ts +35 -0
  33. package/dist/skeleton.d.ts +41 -0
  34. package/dist/xrefs.d.ts +54 -0
  35. package/package.json +1 -1
  36. package/dist/cli-Bcn4t3B1.js +0 -871
@@ -1,23 +1,23 @@
1
- import { fromXml as x } from "xast-util-from-xml";
2
- import { toXml as S } from "xast-util-to-xml";
3
- const A = "/";
4
- function ye(e) {
1
+ import { fromXml as y } from "xast-util-from-xml";
2
+ import { toXml as $ } from "xast-util-to-xml";
3
+ const N = "/";
4
+ function Oe(e) {
5
5
  if (!e)
6
6
  return ".";
7
7
  const n = e.startsWith("/"), t = e.length > 1 && e.endsWith("/"), r = [];
8
- for (const s of e.split("/"))
9
- if (!(!s || s === ".")) {
10
- if (s === "..") {
11
- const o = r[r.length - 1];
12
- r.length > 0 && o !== ".." ? r.pop() : n || r.push("..");
8
+ for (const o of e.split("/"))
9
+ if (!(!o || o === ".")) {
10
+ if (o === "..") {
11
+ const s = r[r.length - 1];
12
+ r.length > 0 && s !== ".." ? r.pop() : n || r.push("..");
13
13
  continue;
14
14
  }
15
- r.push(s);
15
+ r.push(o);
16
16
  }
17
17
  let i = r.join("/");
18
18
  return n && (i = `/${i}`), i ? (t && !i.endsWith("/") && (i += "/"), i) : n ? "/" : ".";
19
19
  }
20
- function p(...e) {
20
+ function h(...e) {
21
21
  let n = "";
22
22
  for (let r = e.length - 1; r >= 0; r--) {
23
23
  const i = e[r];
@@ -25,38 +25,38 @@ function p(...e) {
25
25
  break;
26
26
  }
27
27
  n.startsWith("/") || (n = `/${n}`);
28
- const t = ye(n);
28
+ const t = Oe(n);
29
29
  return t.length > 1 && t.endsWith("/") ? t.slice(0, -1) : t;
30
30
  }
31
- function g(e) {
31
+ function I(e) {
32
32
  const n = e.replace(/\/+$/, "");
33
33
  if (!n)
34
34
  return e.startsWith("/") ? "/" : ".";
35
35
  const t = n.lastIndexOf("/");
36
36
  return t < 0 ? "." : t === 0 ? "/" : n.slice(0, t);
37
37
  }
38
- function k(e, n) {
39
- const t = p(e).split("/").filter(Boolean), r = p(n).split("/").filter(Boolean);
38
+ function B(e, n) {
39
+ const t = h(e).split("/").filter(Boolean), r = h(n).split("/").filter(Boolean);
40
40
  let i = 0;
41
41
  for (; i < t.length && i < r.length && t[i] === r[i]; )
42
42
  i += 1;
43
43
  return [...new Array(t.length - i).fill(".."), ...r.slice(i)].join("/");
44
44
  }
45
- const xe = "ptxPreviewBannerDismissed", Ee = "About live preview";
46
- function X(e) {
45
+ const Be = "ptxPreviewBannerDismissed", Ce = "About live preview";
46
+ function Q(e) {
47
47
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
48
48
  }
49
- function Te(e) {
49
+ function je(e) {
50
50
  return [
51
51
  '<div id="ptx-preview-banner" class="ptx-preview-banner" role="note">',
52
- ` <span class="ptx-preview-banner-text">${X(e)}</span>`,
52
+ ` <span class="ptx-preview-banner-text">${Q(e)}</span>`,
53
53
  ' <button type="button" class="ptx-preview-banner-dismiss" aria-label="Dismiss">&times;</button>',
54
54
  "</div>",
55
- `<button type="button" id="ptx-preview-banner-restore" class="ptx-preview-banner-restore" hidden>${X(Ee)}</button>`
55
+ `<button type="button" id="ptx-preview-banner-restore" class="ptx-preview-banner-restore" hidden>${Q(Ce)}</button>`
56
56
  ].join(`
57
57
  `);
58
58
  }
59
- function Se() {
59
+ function Fe() {
60
60
  return [
61
61
  "<style>",
62
62
  ".ptx-preview-banner {",
@@ -117,11 +117,11 @@ function Se() {
117
117
  ].join(`
118
118
  `);
119
119
  }
120
- function $e() {
120
+ function Ne() {
121
121
  return [
122
122
  "<script>",
123
123
  "(function () {",
124
- " var KEY = " + JSON.stringify(xe) + ";",
124
+ " var KEY = " + JSON.stringify(Be) + ";",
125
125
  ' var banner = document.getElementById("ptx-preview-banner");',
126
126
  ' var restore = document.getElementById("ptx-preview-banner-restore");',
127
127
  " if (!banner || !restore) { return; }",
@@ -158,39 +158,39 @@ function $e() {
158
158
  ].join(`
159
159
  `);
160
160
  }
161
- const _e = "<!--ptx-preview-banner-->", Ie = "<!--/ptx-preview-banner-->", Re = /\n?<!--ptx-preview-banner-->[\s\S]*?<!--\/ptx-preview-banner-->/;
162
- function ke(e, n) {
163
- const t = Re.exec(e), r = t ? e.slice(0, t.index) + e.slice(t.index + t[0].length) : e;
161
+ const We = "<!--ptx-preview-banner-->", He = "<!--/ptx-preview-banner-->", Ue = /\n?<!--ptx-preview-banner-->[\s\S]*?<!--\/ptx-preview-banner-->/;
162
+ function Ve(e, n) {
163
+ const t = Ue.exec(e), r = t ? e.slice(0, t.index) + e.slice(t.index + t[0].length) : e;
164
164
  if (!/<body[^>]*>/i.test(r))
165
165
  return r;
166
166
  const i = `
167
- ${_e}
168
- ${Se()}
169
- ${Te(n.message)}
170
- ${$e()}
171
- ${Ie}`;
167
+ ${We}
168
+ ${Fe()}
169
+ ${je(n.message)}
170
+ ${Ne()}
171
+ ${He}`;
172
172
  return r.replace(/<body([^>]*)>/i, `<body$1>${i}`);
173
173
  }
174
- const De = "https://cdn.jsdelivr.net/npm/@pretextbook/pretext-html@0.8.0/assets";
175
- let ee;
176
- function Ft(e) {
177
- ee = e.replace(/\/+$/, "");
174
+ const Xe = "https://cdn.jsdelivr.net/npm/@pretextbook/pretext-html@0.9.0/assets";
175
+ let ue;
176
+ function mn(e) {
177
+ ue = e.replace(/\/+$/, "");
178
178
  }
179
- function $() {
180
- return ee ?? De;
179
+ function A() {
180
+ return ue ?? Xe;
181
181
  }
182
- function te(e, n) {
182
+ function fe(e, n) {
183
183
  return `${e.replace(/\/+$/, "")}/${n.replace(/^\/+/, "")}`;
184
184
  }
185
- const V = /* @__PURE__ */ new Map();
186
- function Me(e) {
185
+ const ee = /* @__PURE__ */ new Map();
186
+ function ze(e) {
187
187
  return `${e.replace(/\/+$/, "")}-bundle.json`;
188
188
  }
189
- function Le(e) {
190
- let n = V.get(e);
189
+ function Je(e) {
190
+ let n = ee.get(e);
191
191
  return n || (n = (async () => {
192
192
  try {
193
- const t = await fetch(Me(e));
193
+ const t = await fetch(ze(e));
194
194
  if (!t.ok)
195
195
  return /* @__PURE__ */ new Map();
196
196
  const r = await t.json();
@@ -198,16 +198,16 @@ function Le(e) {
198
198
  } catch {
199
199
  return /* @__PURE__ */ new Map();
200
200
  }
201
- })(), V.set(e, n)), n;
201
+ })(), ee.set(e, n)), n;
202
202
  }
203
- function Ae(e) {
204
- return e === te($(), "xsl");
203
+ function Ge(e) {
204
+ return e === fe(A(), "xsl");
205
205
  }
206
- async function ne(e, n) {
207
- if (Ae(e)) {
208
- const s = (await Le(e)).get(n.replace(/^\/+/, ""));
209
- if (s !== void 0)
210
- return new TextEncoder().encode(s);
206
+ async function pe(e, n) {
207
+ if (Ge(e)) {
208
+ const o = (await Je(e)).get(n.replace(/^\/+/, ""));
209
+ if (o !== void 0)
210
+ return new TextEncoder().encode(o);
211
211
  }
212
212
  const t = `${e.replace(/\/+$/, "")}/`;
213
213
  let r;
@@ -229,7 +229,7 @@ async function ne(e, n) {
229
229
  return;
230
230
  }
231
231
  }
232
- async function C(e) {
232
+ async function P(e) {
233
233
  if (/^[a-z][a-z0-9+.-]*:\/\//i.test(e))
234
234
  try {
235
235
  const n = await fetch(e);
@@ -238,42 +238,42 @@ async function C(e) {
238
238
  return;
239
239
  }
240
240
  }
241
- const re = "2.46.0", je = "8.2.1", Be = [
242
- "prefix-runtime.ed2cce180827a7ad.bundle.js",
241
+ const he = "2.48.1", Ke = "8.2.4", Ye = [
242
+ "prefix-runtime.40bd1420d3277749.bundle.js",
243
243
  "prefix-926.5c7038c8ef173faf.bundle.js",
244
- "prefix-runestone.1f660864c47fc762.bundle.js"
245
- ], Ce = [
244
+ "prefix-runestone.b388362b5f43738a.bundle.js"
245
+ ], qe = [
246
246
  "prefix-926.229729d09512acc9.css",
247
247
  "prefix-runestone.8086b62682b271d1.css"
248
- ], Oe = "born-hidden-knowl", Pe = /<details\b([^>]*)>(\s*)(?:<summary\b([^>]*)>)?/g;
249
- function Ne(e) {
248
+ ], Ze = "born-hidden-knowl", Qe = /<details\b([^>]*)>(\s*)(?:<summary\b([^>]*)>)?/g;
249
+ function et(e) {
250
250
  const n = /\bclass="([^"]*)"/.exec(e);
251
251
  return n ? n[1].trim().split(/\s+/) : [];
252
252
  }
253
- function Fe(e) {
253
+ function tt(e) {
254
254
  return /(^|\s)open(\s|=|$)/.test(e);
255
255
  }
256
- function z(e) {
257
- return Fe(e) ? e : ` open${e}`;
256
+ function te(e) {
257
+ return tt(e) ? e : ` open${e}`;
258
258
  }
259
- function We(e) {
259
+ function nt(e) {
260
260
  return e.replace(
261
- Pe,
261
+ Qe,
262
262
  (n, t, r, i) => {
263
- if (!Ne(t).includes(Oe))
263
+ if (!et(t).includes(Ze))
264
264
  return n;
265
- const s = `<details${z(t)}>`;
266
- return i === void 0 ? `${s}${r}` : `${s}${r}<summary${z(i)}>`;
265
+ const o = `<details${te(t)}>`;
266
+ return i === void 0 ? `${o}${r}` : `${o}${r}<summary${te(i)}>`;
267
267
  }
268
268
  );
269
269
  }
270
- const O = /* @__PURE__ */ new Map(), ie = /* @__PURE__ */ new Map();
271
- let j, Ue = 0, se = ne;
272
- function Wt(e) {
273
- se = e;
270
+ const X = /* @__PURE__ */ new Map(), me = /* @__PURE__ */ new Map();
271
+ let W, rt = 0, we = pe;
272
+ function wn(e) {
273
+ we = e;
274
274
  }
275
- function He(e, n) {
276
- const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, r = ie.get(t);
275
+ function it(e, n) {
276
+ const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, r = me.get(t);
277
277
  if (r !== void 0)
278
278
  return Promise.resolve(new Response(r, { status: 200 }));
279
279
  let i;
@@ -282,32 +282,32 @@ function He(e, n) {
282
282
  } catch {
283
283
  i = "";
284
284
  }
285
- const s = O.get(i);
286
- return s !== void 0 ? Ve(s, t) : j(e, n);
285
+ const o = X.get(i);
286
+ return o !== void 0 ? st(o, t) : W(e, n);
287
287
  }
288
- const Xe = '<?xml version="1.0"?><pretext-preview-missing-file/>';
289
- async function Ve(e, n) {
290
- const t = decodeURIComponent(new URL(n).pathname), r = await se(e, t);
288
+ const ot = '<?xml version="1.0"?><pretext-preview-missing-file/>';
289
+ async function st(e, n) {
290
+ const t = decodeURIComponent(new URL(n).pathname), r = await we(e, t);
291
291
  if (r === void 0)
292
- return new Response(Xe, { status: 200 });
292
+ return new Response(ot, { status: 200 });
293
293
  const i = typeof r == "string" ? r : new Uint8Array(r);
294
294
  return new Response(i, { status: 200 });
295
295
  }
296
- function oe() {
297
- j || (j = globalThis.fetch, globalThis.fetch = He);
296
+ function ve() {
297
+ W || (W = globalThis.fetch, globalThis.fetch = it);
298
298
  }
299
- function ae(e) {
300
- oe();
301
- const n = `mnt${++Ue}.ptx.invalid`;
302
- return O.set(n, e), `http://${n}`;
299
+ function ge(e) {
300
+ ve();
301
+ const n = `mnt${++rt}.ptx.invalid`;
302
+ return X.set(n, e), `http://${n}`;
303
303
  }
304
- function ze(e) {
305
- O.delete(new URL(e).host);
304
+ function at(e) {
305
+ X.delete(new URL(e).host);
306
306
  }
307
- function Je(e, n) {
308
- oe(), ie.set(e, n);
307
+ function ct(e, n) {
308
+ ve(), me.set(e, n);
309
309
  }
310
- const B = `<?xml version="1.0" encoding="UTF-8"?>
310
+ const H = `<?xml version="1.0" encoding="UTF-8"?>
311
311
  <publication>
312
312
  <source>
313
313
  <directories external="../assets" generated="../generated-assets" />
@@ -316,82 +316,82 @@ const B = `<?xml version="1.0" encoding="UTF-8"?>
316
316
  <platform portable="yes"/>
317
317
  </html>
318
318
  </publication>
319
- `, Ke = ["theme", "style", "shell"];
320
- function v(e, n) {
319
+ `, lt = ["theme", "style", "shell"];
320
+ function x(e, n) {
321
321
  for (const t of e.children)
322
322
  if (t.type === "element" && t.name === n)
323
323
  return t;
324
324
  }
325
- function b(e, n) {
326
- let t = v(e, n);
325
+ function E(e, n) {
326
+ let t = x(e, n);
327
327
  return t || (t = { type: "element", name: n, attributes: {}, children: [] }, e.children.push(t)), t;
328
328
  }
329
- function Ge(e, n) {
330
- const t = v(e, "css");
331
- if (t && Ke.some((i) => t.attributes?.[i]))
329
+ function dt(e, n) {
330
+ const t = x(e, "css");
331
+ if (t && lt.some((i) => t.attributes?.[i]))
332
332
  return;
333
- const r = t ?? b(e, "css");
333
+ const r = t ?? E(e, "css");
334
334
  r.attributes = { ...r.attributes, theme: n };
335
335
  }
336
- function Ye(e, n) {
337
- const t = v(e, "appearance");
336
+ function ut(e, n) {
337
+ const t = x(e, "appearance");
338
338
  if (t?.attributes?.theme)
339
339
  return;
340
- const r = t ?? b(e, "appearance");
340
+ const r = t ?? E(e, "appearance");
341
341
  r.attributes = { ...r.attributes, theme: n };
342
342
  }
343
- function qe(e) {
344
- const n = b(e, "resources");
343
+ function ft(e) {
344
+ const n = E(e, "resources");
345
345
  n.attributes = {
346
346
  ...n.attributes,
347
347
  host: "cdn",
348
348
  math: "online"
349
349
  };
350
350
  }
351
- function Ze(e, n = {}) {
351
+ function pt(e, n = {}) {
352
352
  const t = n.cssTheme?.trim(), r = n.revealTheme?.trim(), i = n.target === "slides";
353
353
  if (!e && !t && !i)
354
- return B;
355
- const s = x(e ?? B), o = v(s, "publication");
356
- if (!o)
354
+ return H;
355
+ const o = y(e ?? H), s = x(o, "publication");
356
+ if (!s)
357
357
  throw new Error(
358
358
  "Invalid publication file: no root <publication> element found"
359
359
  );
360
- const a = b(o, "html"), d = b(a, "platform");
361
- if (d.attributes = { ...d.attributes, portable: "yes" }, t && Ge(a, t), i) {
362
- const l = b(o, "revealjs");
363
- qe(l), r && Ye(l, r);
360
+ const a = E(s, "html"), l = E(a, "platform");
361
+ if (l.attributes = { ...l.attributes, portable: "yes" }, t && dt(a, t), i) {
362
+ const d = E(s, "revealjs");
363
+ ft(d), r && ut(d, r);
364
364
  }
365
- return S(s);
365
+ return $(o);
366
366
  }
367
- function J(e) {
367
+ function ne(e) {
368
368
  if (!(e === void 0 || e === "" || e.startsWith("/")))
369
369
  return e.endsWith("/") ? e : `${e}/`;
370
370
  }
371
- function Qe(e) {
372
- const n = x(e ?? B), t = v(n, "publication"), r = t && v(t, "source"), i = r && v(r, "directories"), s = J(
371
+ function ht(e) {
372
+ const n = y(e ?? H), t = x(n, "publication"), r = t && x(t, "source"), i = r && x(r, "directories"), o = ne(
373
373
  i?.attributes?.external ?? void 0
374
- ), o = J(
374
+ ), s = ne(
375
375
  i?.attributes?.generated ?? void 0
376
376
  );
377
377
  return {
378
- external: s,
379
- generated: o,
380
- managed: s !== void 0 && o !== void 0
378
+ external: o,
379
+ generated: s,
380
+ managed: o !== void 0 && s !== void 0
381
381
  };
382
382
  }
383
- function Ut(e) {
383
+ function vn(e) {
384
384
  return e === "slides" || e === "scroll";
385
385
  }
386
- const ce = 960, le = 700, et = 1, tt = 0.04;
387
- function nt(e) {
388
- const n = typeof e == "number" && isFinite(e) ? e : et, t = Math.min(1, Math.max(0.25, n));
386
+ const be = 960, xe = 700, mt = 1, wt = 0.04;
387
+ function vt(e) {
388
+ const n = typeof e == "number" && isFinite(e) ? e : mt, t = Math.min(1, Math.max(0.25, n));
389
389
  return {
390
- width: Math.round(ce / t),
391
- height: Math.round(le / t)
390
+ width: Math.round(be / t),
391
+ height: Math.round(xe / t)
392
392
  };
393
393
  }
394
- function rt(e) {
394
+ function gt(e) {
395
395
  return {
396
396
  view: "scroll",
397
397
  scrollLayout: "compact",
@@ -401,11 +401,11 @@ function rt(e) {
401
401
  controls: !1,
402
402
  controlsTutorial: !1,
403
403
  hash: !1,
404
- ...nt(e.zoom),
405
- margin: tt
404
+ ...vt(e.zoom),
405
+ margin: wt
406
406
  };
407
407
  }
408
- function it() {
408
+ function bt() {
409
409
  return {
410
410
  // Explicitly null rather than absent: the same page may have been
411
411
  // delivered in scroll view a moment ago, and an embedder that re-injects
@@ -417,11 +417,11 @@ function it() {
417
417
  // size with a percentage width renders its text far larger, relative to
418
418
  // the slide, than the same deck will on a projector. No zoom margin
419
419
  // though — presenting means filling whatever it is shown in.
420
- width: ce,
421
- height: le
420
+ width: be,
421
+ height: xe
422
422
  };
423
423
  }
424
- const st = [
424
+ const xt = [
425
425
  "<style>",
426
426
  ".reveal-viewport.reveal-scroll .scroll-page section {",
427
427
  " box-shadow: inset 0 0 0 calc(1px / var(--slide-scale, 1))",
@@ -429,14 +429,14 @@ const st = [
429
429
  "}",
430
430
  "</style>"
431
431
  ].join(`
432
- `), ot = [
432
+ `), Et = [
433
433
  " var paused = document.querySelectorAll('.reveal .fragment');",
434
434
  " for (var i = 0; i < paused.length; i++) {",
435
435
  " paused[i].classList.remove('fragment');",
436
436
  " }"
437
437
  ];
438
- function at(e, n = {}) {
439
- const t = e === "scroll" ? rt(n) : it();
438
+ function yt(e, n = {}) {
439
+ const t = e === "scroll" ? gt(n) : bt();
440
440
  return [
441
441
  "<script>",
442
442
  "(function () {",
@@ -464,7 +464,7 @@ function at(e, n = {}) {
464
464
  // Inside the wrapper rather than at top level: this script sits in <head>,
465
465
  // where the slides have not been parsed yet, but the deck calls initialize
466
466
  // from the end of the document, by which time they have.
467
- ...e === "scroll" ? ot : [],
467
+ ...e === "scroll" ? Et : [],
468
468
  " return initialize(merged);",
469
469
  " };",
470
470
  "})();",
@@ -472,156 +472,156 @@ function at(e, n = {}) {
472
472
  ].join(`
473
473
  `);
474
474
  }
475
- const ct = /<script\b[^>]*\bsrc=["'][^"']*\breveal\.js["'][^>]*>\s*<\/script>/i, lt = "<!--ptx-reveal-view-->", dt = "<!--/ptx-reveal-view-->", ut = /\n?<!--ptx-reveal-view-->[\s\S]*?<!--\/ptx-reveal-view-->/;
476
- function ft(e, n, t = {}) {
477
- const r = ut.exec(e), i = r ? e.slice(0, r.index) + e.slice(r.index + r[0].length) : e, s = ct.exec(i);
478
- if (!s)
475
+ const Tt = /<script\b[^>]*\bsrc=["'][^"']*\breveal\.js["'][^>]*>\s*<\/script>/i, St = "<!--ptx-reveal-view-->", kt = "<!--/ptx-reveal-view-->", $t = /\n?<!--ptx-reveal-view-->[\s\S]*?<!--\/ptx-reveal-view-->/;
476
+ function It(e, n, t = {}) {
477
+ const r = $t.exec(e), i = r ? e.slice(0, r.index) + e.slice(r.index + r[0].length) : e, o = Tt.exec(i);
478
+ if (!o)
479
479
  return i;
480
- const o = s.index + s[0].length, a = `
481
- ${lt}
482
- ${st}
483
- ${at(n, t)}
484
- ${dt}`;
485
- return i.slice(0, o) + a + i.slice(o);
486
- }
487
- const de = "http://www.w3.org/2001/XInclude", K = 64;
488
- async function pt(e, n, t) {
489
- return e.includes("include") ? (await ue(e, n, t)).content : e;
490
- }
491
- async function ue(e, n, t) {
492
- const r = x(e), i = {
493
- projectDir: p(t),
494
- stack: [p(n)]
495
- }, s = await y(
480
+ const s = o.index + o[0].length, a = `
481
+ ${St}
482
+ ${xt}
483
+ ${yt(n, t)}
484
+ ${kt}`;
485
+ return i.slice(0, s) + a + i.slice(s);
486
+ }
487
+ const Ee = "http://www.w3.org/2001/XInclude", re = 64;
488
+ async function _t(e, n, t) {
489
+ return e.includes("include") ? (await z(e, n, t)).content : e;
490
+ }
491
+ async function z(e, n, t) {
492
+ const r = y(e), i = {
493
+ projectDir: h(t),
494
+ stack: [h(n)]
495
+ }, o = await _(
496
496
  r,
497
- g(p(n)),
497
+ I(h(n)),
498
498
  { "": "" },
499
499
  i
500
500
  );
501
- return { tree: r, content: s ? S(r) : e };
501
+ return { tree: r, content: o ? $(r) : e };
502
502
  }
503
- function ht(e) {
503
+ function Rt(e) {
504
504
  return e.data?.ptxIncludedFile;
505
505
  }
506
- function mt(e, n) {
506
+ function Dt(e, n) {
507
507
  const t = e.data ?? (e.data = {});
508
508
  t.ptxIncludedFile = n;
509
509
  }
510
- function _(e, n) {
510
+ function L(e, n) {
511
511
  let t = e;
512
512
  for (const [r, i] of Object.entries(n.attributes))
513
513
  (r === "xmlns" || r.startsWith("xmlns:")) && (t === e && (t = { ...e }), t[r === "xmlns" ? "" : r.slice(6)] = i ?? "");
514
514
  return t;
515
515
  }
516
- function fe(e, n) {
516
+ function ye(e, n) {
517
517
  const t = e.name.indexOf(":"), r = t === -1 ? "" : e.name.slice(0, t);
518
- return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && n[r] === de;
518
+ return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && n[r] === Ee;
519
519
  }
520
- async function y(e, n, t, r) {
520
+ async function _(e, n, t, r) {
521
521
  let i = !1;
522
- for (let s = 0; s < e.children.length; s++) {
523
- const o = e.children[s];
524
- if (o.type !== "element")
522
+ for (let o = 0; o < e.children.length; o++) {
523
+ const s = e.children[o];
524
+ if (s.type !== "element")
525
525
  continue;
526
- const a = _(t, o);
527
- if (fe(o, a)) {
528
- const d = await pe(
529
- o,
526
+ const a = L(t, s);
527
+ if (ye(s, a)) {
528
+ const l = await Te(
529
+ s,
530
530
  n,
531
531
  a,
532
532
  r
533
533
  );
534
- e.children.splice(s, 1, ...d), s += d.length - 1, i = !0;
535
- } else await y(o, n, a, r) && (i = !0);
534
+ e.children.splice(o, 1, ...l), o += l.length - 1, i = !0;
535
+ } else await _(s, n, a, r) && (i = !0);
536
536
  }
537
537
  return i;
538
538
  }
539
- async function pe(e, n, t, r) {
539
+ async function Te(e, n, t, r) {
540
540
  const i = r.stack[r.stack.length - 1];
541
541
  if (e.attributes.xpointer)
542
542
  throw new Error(
543
543
  `xi:include with xpointer is not supported by the JS preview build (in ${i})`
544
544
  );
545
- const s = e.attributes.href;
546
- if (!s)
545
+ const o = e.attributes.href;
546
+ if (!o)
547
547
  throw new Error(`xi:include without href (in ${i})`);
548
- let o = s;
548
+ let s = o;
549
549
  try {
550
- o = decodeURIComponent(s);
550
+ s = decodeURIComponent(o);
551
551
  } catch {
552
552
  }
553
- const a = p(n, o);
554
- if (a !== r.projectDir && !a.startsWith(r.projectDir + A))
553
+ const a = h(n, s);
554
+ if (a !== r.projectDir && !a.startsWith(r.projectDir + N))
555
555
  throw new Error(
556
- `xi:include escapes the project directory: ${s} (in ${i})`
556
+ `xi:include escapes the project directory: ${o} (in ${i})`
557
557
  );
558
558
  if (r.stack.includes(a))
559
559
  throw new Error(
560
560
  `Circular xi:include: ${[...r.stack, a].join(" -> ")}`
561
561
  );
562
- if (r.stack.length >= K)
563
- throw new Error(`xi:include nesting exceeds ${K} levels`);
564
- const d = await C(a);
565
- if (d === void 0) {
566
- const f = vt(e, t);
567
- if (f)
568
- return await y(f, n, t, r), f.children;
569
- throw new Error(`xi:include target not found: ${s} (in ${i})`);
562
+ if (r.stack.length >= re)
563
+ throw new Error(`xi:include nesting exceeds ${re} levels`);
564
+ const l = await P(a);
565
+ if (l === void 0) {
566
+ const p = At(e, t);
567
+ if (p)
568
+ return await _(p, n, t, r), p.children;
569
+ throw new Error(`xi:include target not found: ${o} (in ${i})`);
570
570
  }
571
571
  if (e.attributes.parse === "text")
572
- return [{ type: "text", value: d }];
573
- let l;
572
+ return [{ type: "text", value: l }];
573
+ let d;
574
574
  try {
575
- l = x(d);
576
- } catch (f) {
575
+ d = y(l);
576
+ } catch (p) {
577
577
  throw new Error(
578
- `Could not parse xi:include target ${a} as XML: ${f instanceof Error ? f.message : f}. (Included files must be well-formed, with a single root element.)`
578
+ `Could not parse xi:include target ${a} as XML: ${p instanceof Error ? p.message : p}. (Included files must be well-formed, with a single root element.)`
579
579
  );
580
580
  }
581
581
  r.stack.push(a);
582
582
  try {
583
- await y(l, g(a), { "": "" }, r);
583
+ await _(d, I(a), { "": "" }, r);
584
584
  } finally {
585
585
  r.stack.pop();
586
586
  }
587
- const u = l.children.filter(
588
- (f) => f.type === "element"
587
+ const f = d.children.filter(
588
+ (p) => p.type === "element"
589
589
  );
590
- for (const f of u)
591
- mt(f, a);
592
- return u;
590
+ for (const p of f)
591
+ Dt(p, a);
592
+ return f;
593
593
  }
594
- function G(e) {
594
+ function ie(e) {
595
595
  return e.name === "docinfo";
596
596
  }
597
- async function wt(e, n, t) {
597
+ async function Mt(e, n, t) {
598
598
  try {
599
- const i = x(e).children.find(
600
- (l) => l.type === "element"
599
+ const i = y(e).children.find(
600
+ (d) => d.type === "element"
601
601
  );
602
602
  if (!i)
603
603
  return;
604
- const s = p(n), o = g(s), a = {
605
- projectDir: p(t),
606
- stack: [s]
607
- }, d = _({ "": "" }, i);
608
- for (const l of i.children) {
609
- if (l.type !== "element")
604
+ const o = h(n), s = I(o), a = {
605
+ projectDir: h(t),
606
+ stack: [o]
607
+ }, l = L({ "": "" }, i);
608
+ for (const d of i.children) {
609
+ if (d.type !== "element")
610
610
  continue;
611
- const u = _(d, l);
612
- if (G(l))
613
- return await y(l, o, u, a), S(l);
614
- if (fe(l, u)) {
615
- const h = (await pe(
616
- l,
617
- o,
618
- u,
611
+ const f = L(l, d);
612
+ if (ie(d))
613
+ return await _(d, s, f, a), $(d);
614
+ if (ye(d, f)) {
615
+ const u = (await Te(
616
+ d,
617
+ s,
618
+ f,
619
619
  a
620
620
  )).find(
621
- (m) => m.type === "element" && G(m)
621
+ (m) => m.type === "element" && ie(m)
622
622
  );
623
- if (h)
624
- return S(h);
623
+ if (u)
624
+ return $(u);
625
625
  continue;
626
626
  }
627
627
  break;
@@ -631,78 +631,78 @@ async function wt(e, n, t) {
631
631
  return;
632
632
  }
633
633
  }
634
- function vt(e, n) {
634
+ function At(e, n) {
635
635
  for (const t of e.children) {
636
636
  if (t.type !== "element")
637
637
  continue;
638
- const r = _(n, t), i = t.name.indexOf(":"), s = i === -1 ? "" : t.name.slice(0, i);
639
- if ((i === -1 ? t.name : t.name.slice(i + 1)) === "fallback" && r[s] === de)
638
+ const r = L(n, t), i = t.name.indexOf(":"), o = i === -1 ? "" : t.name.slice(0, i);
639
+ if ((i === -1 ? t.name : t.name.slice(i + 1)) === "fallback" && r[o] === Ee)
640
640
  return t;
641
641
  }
642
642
  }
643
- function he(e) {
643
+ function Se(e) {
644
644
  return typeof e == "object" && e !== null && e.type === "element";
645
645
  }
646
- function bt(e) {
646
+ function Lt(e) {
647
647
  return /^(pf|xhtml):/.test(e.name);
648
648
  }
649
- function gt(e, n, t) {
650
- const r = [], i = e.children.find(he);
649
+ function Pt(e, n, t) {
650
+ const r = [], i = e.children.find(Se);
651
651
  if (i) {
652
- const s = t?.parentId ?? "root";
653
- me(i, s, t?.position ?? 1, n, s, r);
652
+ const o = t?.parentId ?? "root";
653
+ ke(i, o, t?.position ?? 1, n, o, r);
654
654
  }
655
655
  return r;
656
656
  }
657
- function me(e, n, t, r, i, s) {
658
- const o = ht(e) ?? r;
659
- let a, d;
660
- if (bt(e))
661
- d = "root";
657
+ function ke(e, n, t, r, i, o) {
658
+ const s = Rt(e) ?? r;
659
+ let a, l;
660
+ if (Lt(e))
661
+ l = "root";
662
662
  else {
663
- const u = e.attributes.label ?? e.attributes["xml:id"];
664
- a = u ?? `${n}-${t}`, s.push({
663
+ const f = e.attributes.label ?? e.attributes["xml:id"];
664
+ a = f ?? `${n}-${t}`, o.push({
665
665
  id: a,
666
- file: o,
666
+ file: s,
667
667
  line: e.position?.start.line ?? 1,
668
668
  column: e.position?.start.column ?? 1,
669
669
  endLine: e.position?.end.line ?? e.position?.start.line ?? 1,
670
670
  parent: i
671
- }), d = a;
671
+ }), l = a;
672
672
  }
673
- let l = 0;
674
- for (const u of e.children)
675
- he(u) && (l += 1, me(
676
- u,
677
- d,
673
+ let d = 0;
674
+ for (const f of e.children)
675
+ Se(f) && (d += 1, ke(
676
+ f,
678
677
  l,
679
- o,
678
+ d,
679
+ s,
680
680
  a ?? i,
681
- s
681
+ o
682
682
  ));
683
683
  }
684
- function Ht(e, n) {
684
+ function gn(e, n) {
685
685
  let t;
686
686
  for (const r of e)
687
687
  r.line <= n && (t = r);
688
688
  return t ?? e[0];
689
689
  }
690
- function yt(e) {
690
+ function Ot(e) {
691
691
  const n = e.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!\[CDATA\[[\s\S]*?\]\]>/g, " ");
692
692
  return /<\s*slide(?:show)?[\s/>]/.test(n) ? "slides" : "html";
693
693
  }
694
- const we = "pretext-html:set-theme";
695
- function Xt(e) {
694
+ const $e = "pretext-html:set-theme";
695
+ function bn(e) {
696
696
  return e === "dark" || e === "light" || e === "system";
697
697
  }
698
- function Vt(e) {
699
- return { type: we, theme: e };
698
+ function xn(e) {
699
+ return { type: $e, theme: e };
700
700
  }
701
- function xt(e) {
701
+ function Bt(e) {
702
702
  return [
703
703
  "<script>",
704
704
  "(function () {",
705
- " var CFG = " + JSON.stringify({ msg: we, initial: e }) + ";",
705
+ " var CFG = " + JSON.stringify({ msg: $e, initial: e }) + ";",
706
706
  // Where the last requested theme is remembered so it survives an in-place
707
707
  // document rewrite (same Window) and outranks the baked initial value.
708
708
  " var KEY = '__ptxPreviewTheme';",
@@ -772,255 +772,464 @@ function xt(e) {
772
772
  ].join(`
773
773
  `);
774
774
  }
775
- function Et(e, n) {
776
- const t = xt(n);
775
+ function Ct(e, n) {
776
+ const t = Bt(n);
777
777
  return /<head[^>]*>/i.test(e) ? e.replace(/<head([^>]*)>/i, `<head$1>
778
778
  ${t}`) : e;
779
779
  }
780
- function Tt() {
781
- return te($(), "xsl");
780
+ const Ie = /* @__PURE__ */ new Set([
781
+ "colophon",
782
+ "biography",
783
+ "dedication",
784
+ "acknowledgement",
785
+ "preface",
786
+ "chapter",
787
+ "section",
788
+ "subsection",
789
+ "subsubsection",
790
+ "slide",
791
+ "appendix",
792
+ "index",
793
+ "exercises",
794
+ "reading-questions",
795
+ "references",
796
+ "solutions",
797
+ "glossary",
798
+ "worksheet",
799
+ "handout"
800
+ ]), _e = /* @__PURE__ */ new Set([
801
+ "book",
802
+ "article",
803
+ "slideshow",
804
+ "letter",
805
+ "memo"
806
+ ]), Re = /* @__PURE__ */ new Set([
807
+ ..._e,
808
+ ...Ie,
809
+ "part",
810
+ "frontmatter",
811
+ "backmatter"
812
+ ]), jt = /* @__PURE__ */ new Set(["docinfo"]), De = /* @__PURE__ */ new Set([
813
+ "title",
814
+ "shorttitle",
815
+ "plaintitle",
816
+ "subtitle",
817
+ "caption"
818
+ ]);
819
+ function v(e) {
820
+ return e.type === "element";
821
+ }
822
+ function Me(e) {
823
+ return e.attributes["xml:id"] ?? void 0;
824
+ }
825
+ function U(e, n) {
826
+ for (const t of e.children) {
827
+ if (!v(t)) continue;
828
+ if (Me(t) === n) return t;
829
+ const r = U(t, n);
830
+ if (r) return r;
831
+ }
832
+ }
833
+ function M(e, n) {
834
+ for (const t of e.children) {
835
+ if (!v(t)) continue;
836
+ if (t === n) return [t];
837
+ const r = M(t, n);
838
+ if (r) return [t, ...r];
839
+ }
840
+ }
841
+ function Ft(e, n) {
842
+ let t = 0;
843
+ for (const [r, i] of e.entries()) {
844
+ const o = r === 0 ? void 0 : e[r - 1];
845
+ _e.has(i.name) ? t = 0 : i.name === "frontmatter" || i.name === "backmatter" || i.name === "part" ? t = o?.name === "book" && n ? 1 : 0 : Ie.has(i.name) && (t += 1);
846
+ }
847
+ return t;
848
+ }
849
+ function Ae(e) {
850
+ if (!De.has(e.name)) {
851
+ e.children = e.children.filter(v);
852
+ for (const n of e.children)
853
+ Ae(n);
854
+ }
855
+ }
856
+ function V(e, n) {
857
+ const t = [];
858
+ for (const r of e.children)
859
+ v(r) && (n.has(r) || jt.has(r.name) || De.has(r.name) ? t.push(r) : Re.has(r.name) && (V(r, n), t.push(r)));
860
+ e.children = t;
861
+ }
862
+ function Nt(e) {
863
+ const n = /* @__PURE__ */ new Set(), t = (r) => {
864
+ if (r.name === "xref") {
865
+ const i = [
866
+ r.attributes.ref,
867
+ r.attributes.first,
868
+ r.attributes.last
869
+ ];
870
+ for (const o of i)
871
+ for (const s of o?.split(/[\s,]+/) ?? [])
872
+ s && n.add(s);
873
+ }
874
+ for (const i of r.children)
875
+ v(i) && t(i);
876
+ };
877
+ return t(e), n;
878
+ }
879
+ function Wt(e, n, t) {
880
+ const r = (i) => {
881
+ for (const [o, s] of i.children.entries())
882
+ if (v(s)) {
883
+ if (Me(s) === n)
884
+ return i.children[o] = t, !0;
885
+ if (r(s)) return !0;
886
+ }
887
+ return !1;
888
+ };
889
+ return r(e);
890
+ }
891
+ function Ht(e, n) {
892
+ const t = U(e, n);
893
+ if (!t) return;
894
+ const r = M(e, t);
895
+ if (!r) return;
896
+ const i = r.filter(
897
+ (u) => u.name !== "pretext" && u.name !== "mathbook"
898
+ ), o = i[0], s = o?.name === "book" && o.children.some(
899
+ (u) => v(u) && u.name === "part"
900
+ ), a = Ft(i, s), l = new Set(r), d = Nt(t), f = /* @__PURE__ */ new Set();
901
+ if (d.size > 0)
902
+ for (const u of d) {
903
+ const m = U(e, u);
904
+ if (!m || m === t) continue;
905
+ const R = M(e, m);
906
+ if (!R) continue;
907
+ const g = [...R].reverse().find((w) => Re.has(w.name));
908
+ if (g && g !== t) {
909
+ f.add(g);
910
+ for (const w of M(e, g) ?? [])
911
+ l.add(w);
912
+ }
913
+ }
914
+ for (const u of r) {
915
+ if (u === t) break;
916
+ V(u, l);
917
+ }
918
+ for (const u of f)
919
+ Ae(u);
920
+ const p = e.children.find(v);
921
+ return p && !r.includes(p) && V(p, l), { content: $(e), divisionId: n, level: a };
922
+ }
923
+ const Ut = "This live preview shows a single division, so links into the rest of the document do not work here.", Vt = /<a\b([^>]*)>/g, Xt = /\sid="([^"]*)"/g, C = /\shref="([^"]*)"/, zt = /\\href\{([^{}]*)\}/g, oe = /\stitle="([^"]*)"/;
924
+ function Jt(e) {
925
+ const n = /* @__PURE__ */ new Set();
926
+ for (const t of e.matchAll(Xt))
927
+ n.add(t[1]);
928
+ return n;
782
929
  }
783
- function St() {
930
+ function Gt(e) {
931
+ return e.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
932
+ }
933
+ function se(e, n) {
934
+ if (e.startsWith("#") || e === "") return { kind: "keep" };
935
+ if (/^[a-z][a-z0-9+.-]*:/i.test(e) || e.startsWith("//"))
936
+ return { kind: "keep" };
937
+ const t = e.indexOf("#");
938
+ if (t === -1) return { kind: "off-page" };
939
+ const r = e.slice(t + 1);
940
+ return n.has(r) && r !== "" ? { kind: "same-page", id: r } : { kind: "off-page" };
941
+ }
942
+ function Kt(e, n = {}) {
943
+ const t = n.offPageMessage ?? Ut, r = Jt(e);
944
+ return e.replace(Vt, (o, s) => {
945
+ const a = C.exec(s);
946
+ if (!a) return o;
947
+ const l = se(a[1], r);
948
+ if (l.kind === "keep") return o;
949
+ if (l.kind === "same-page")
950
+ return `<a${s.replace(C, ` href="#${l.id}"`)}>`;
951
+ const d = oe.exec(s), f = Gt(t), p = d ? `${d[1]} — ${f}` : f;
952
+ return `<a${s.replace(C, "").replace(oe, "")} title="${p}" aria-disabled="true" style="cursor:default">`;
953
+ }).replace(zt, (o, s) => {
954
+ const a = se(s, r);
955
+ return a.kind === "same-page" ? `\\href{#${a.id}}` : o;
956
+ });
957
+ }
958
+ function Yt() {
959
+ return fe(A(), "xsl");
960
+ }
961
+ function qt() {
784
962
  return "Suspending" in WebAssembly;
785
963
  }
786
- function $t() {
787
- if (!St())
964
+ function Zt() {
965
+ if (!qt())
788
966
  throw new Error(
789
967
  "WebAssembly JSPI is not enabled. Run Node with --experimental-wasm-jspi (or use the pretext-html CLI, which re-launches itself with the flag)."
790
968
  );
791
969
  }
792
- function D(e) {
970
+ function k(e) {
793
971
  return e.includes("'") ? e.includes('"') ? `concat(${e.split("'").map((t) => `'${t}'`).join(`, "'", `)})` : `"${e}"` : `'${e}'`;
794
972
  }
795
- function _t(e) {
973
+ function Qt(e) {
796
974
  return e.replace(
797
975
  /from '\.\/(https:\/\/[^']+)'/g,
798
976
  (n, t) => `from '${t}'`
799
977
  );
800
978
  }
801
- const It = `https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@${re}/dist/`, Rt = {
802
- "cli.version": re,
979
+ const en = `https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@${he}/dist/`, tn = {
980
+ "cli.version": he,
803
981
  // Colon-delimited: pretext-runestone.xsl splits them with str:tokenize.
804
- "rs-js": Be.join(":"),
805
- "rs-css": Ce.join(":"),
806
- "rs-version": je
982
+ "rs-js": Ye.join(":"),
983
+ "rs-css": qe.join(":"),
984
+ "rs-version": Ke
807
985
  };
808
- function kt(e) {
986
+ function nn(e) {
809
987
  return e.replace(
810
988
  /(<link\b[^>]*\bhref=["'])_static\//gi,
811
- `$1${It}_static/`
989
+ `$1${en}_static/`
812
990
  );
813
991
  }
814
- function Dt(e) {
992
+ function rn(e) {
815
993
  return e.slice(0, 65536).replace(/<\?[\s\S]*?\?>/g, " ").replace(/<!--[\s\S]*?-->/g, " ").replace(/<!DOCTYPE[^>]*>/gi, " ").match(/<\s*([A-Za-z][\w:-]*)/)?.[1];
816
994
  }
817
- async function Y(e) {
818
- const n = await C(e);
995
+ async function ae(e) {
996
+ const n = await P(e);
819
997
  if (n === void 0)
820
998
  throw new Error(
821
999
  `Could not read ${e}. (In the browser build only absolute URLs are readable — pass sourceContent instead of relying on sourcePath.)`
822
1000
  );
823
1001
  return n;
824
1002
  }
825
- async function Mt(e, n) {
826
- const t = p(e), r = await C(t);
1003
+ async function on(e, n) {
1004
+ const t = h(e), r = await P(t);
827
1005
  if (r !== void 0)
828
- return wt(r, t, n);
1006
+ return Mt(r, t, n);
829
1007
  }
830
- function Lt(e, n, t, r) {
831
- const i = e.replace(/^\uFEFF/, "").replace(/<\?xml[\s\S]*?\?>/, "").replace(/<!DOCTYPE[^>]*>/i, ""), s = t === "slides" ? "slideshow" : n === "chapter" || n === "part" ? "book" : "article";
1008
+ function sn(e, n, t, r) {
1009
+ const i = e.replace(/^\uFEFF/, "").replace(/<\?xml[\s\S]*?\?>/, "").replace(/<!DOCTYPE[^>]*>/i, ""), o = t === "slides" ? "slideshow" : n === "chapter" || n === "part" ? "book" : "article";
832
1010
  return `<pretext>
833
1011
  ${r?.trim() ? `${r.trim()}
834
- ` : ""}<${s}>
1012
+ ` : ""}<${o}>
835
1013
  <title/>
836
1014
  ${i}
837
- </${s}>
1015
+ </${o}>
838
1016
  </pretext>
839
1017
  `;
840
1018
  }
841
- let ve = !1;
842
- function At(e) {
1019
+ async function an(e, n, t) {
1020
+ const r = y(e).children.find(
1021
+ (d) => d.type === "element"
1022
+ ), i = r?.attributes["xml:id"];
1023
+ if (!r || !i) return;
1024
+ const o = h(n), s = await P(o);
1025
+ if (s === void 0) return;
1026
+ let a;
1027
+ try {
1028
+ a = (await z(s, o, t)).tree;
1029
+ } catch {
1030
+ return;
1031
+ }
1032
+ if (!Wt(a, i, r)) return;
1033
+ const l = Ht(a, i);
1034
+ if (l)
1035
+ return { ...l, tree: a };
1036
+ }
1037
+ let Le = !1;
1038
+ function cn(e) {
843
1039
  return e instanceof Error && /\bAborted\(/.test(e.message);
844
1040
  }
845
- function jt(e) {
1041
+ function ln(e) {
846
1042
  return e instanceof Error && /memory access|out of bounds/i.test(e.message);
847
1043
  }
848
- function Bt() {
849
- if (ve)
1044
+ function dn() {
1045
+ if (Le)
850
1046
  throw new Error(
851
1047
  "The WebAssembly renderer aborted earlier in this process and cannot be reused. Restart the process (or reload the page) to render again."
852
1048
  );
853
1049
  }
854
- function q(e) {
855
- if (At(e))
856
- throw ve = !0, new Error(
1050
+ function ce(e) {
1051
+ if (cn(e))
1052
+ throw Le = !0, new Error(
857
1053
  "The WebAssembly renderer aborted and cannot be reused. Restart the process (or reload the page) to render again.",
858
1054
  { cause: e }
859
1055
  );
860
- if (jt(e))
1056
+ if (ln(e))
861
1057
  throw new Error(
862
1058
  "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.",
863
1059
  { cause: e }
864
1060
  );
865
1061
  }
866
- let M;
867
- async function be() {
868
- return M || (M = (async () => {
1062
+ let j;
1063
+ async function Pe() {
1064
+ return j || (j = (async () => {
869
1065
  const [e, n] = await Promise.all([
870
1066
  import("@pretextbook/libxslt-wasm"),
871
1067
  import("@pretextbook/libxslt-wasm/exslt")
872
1068
  ]);
873
1069
  return n.registerAll(), e;
874
- })()), M;
1070
+ })()), j;
875
1071
  }
876
- const L = /* @__PURE__ */ new Map(), Ct = {
1072
+ const F = /* @__PURE__ */ new Map(), un = {
877
1073
  html: "preview-html.xsl",
878
1074
  slides: "preview-revealjs.xsl"
879
1075
  };
880
- async function Ot(e, n) {
881
- const t = Ct[n], r = `${n}\0${e}`;
882
- let i = L.get(r);
1076
+ async function fn(e, n) {
1077
+ const t = un[n], r = `${n}\0${e}`;
1078
+ let i = F.get(r);
883
1079
  return i || (i = (async () => {
884
- const { XmlDocument: s, XsltStylesheet: o } = await be(), a = ae(e), d = await ne($(), `/${t}`);
885
- if (d === void 0)
1080
+ const { XmlDocument: o, XsltStylesheet: s } = await Pe(), a = ge(e), l = await pe(A(), `/${t}`);
1081
+ if (l === void 0)
886
1082
  throw new Error(
887
- `Could not read ${t} from ${$()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
1083
+ `Could not read ${t} from ${A()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
888
1084
  );
889
- const l = new TextDecoder().decode(d), u = await s.fromString(l, {
1085
+ const d = new TextDecoder().decode(l), f = await o.fromString(d, {
890
1086
  url: `${a}/${t}`,
891
1087
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
892
1088
  });
893
- return o.fromXmlDocument(u);
894
- })(), L.set(r, i), i.catch(() => L.delete(r))), i;
895
- }
896
- let Z = Promise.resolve();
897
- function zt(e) {
898
- const n = Z.then(
899
- () => Q(e),
900
- () => Q(e)
1089
+ return s.fromXmlDocument(f);
1090
+ })(), F.set(r, i), i.catch(() => F.delete(r))), i;
1091
+ }
1092
+ let le = Promise.resolve();
1093
+ function En(e) {
1094
+ const n = le.then(
1095
+ () => de(e),
1096
+ () => de(e)
901
1097
  );
902
- return Z = n.catch(() => {
1098
+ return le = n.catch(() => {
903
1099
  }), n;
904
1100
  }
905
- async function Q(e) {
906
- $t(), Bt();
907
- const { XmlDocument: n } = await be(), t = p(e.sourcePath), r = p(
908
- e.projectDir ?? g(t)
909
- ), i = e.sourceContent ?? await Y(t), s = k(r, t);
910
- if (s.startsWith(".."))
1101
+ async function de(e) {
1102
+ Zt(), dn();
1103
+ const { XmlDocument: n } = await Pe(), t = h(e.sourcePath), r = h(
1104
+ e.projectDir ?? I(t)
1105
+ ), i = e.sourceContent ?? await ae(t), o = B(r, t);
1106
+ if (o.startsWith(".."))
911
1107
  throw new Error(
912
1108
  `sourcePath (${t}) must live inside projectDir (${r})`
913
1109
  );
914
- const o = k(
1110
+ const s = B(
915
1111
  r,
916
- p(e.mainSourcePath ?? t)
917
- ), a = o.startsWith("..") ? s : o, d = ae(r);
1112
+ h(e.mainSourcePath ?? t)
1113
+ ), a = s.startsWith("..") ? o : s, l = ge(r);
918
1114
  try {
919
- let l, u = `${d}/__pretext-preview-publication.xml`;
1115
+ let d, f = `${l}/__pretext-preview-publication.xml`;
920
1116
  if (e.publicationPath) {
921
- const c = p(e.publicationPath);
922
- l = await Y(c);
923
- const w = k(r, c);
924
- w.startsWith("..") || (u = `${d}/${w.split(A).join("/")}`);
1117
+ const c = h(e.publicationPath);
1118
+ d = await ae(c);
1119
+ const b = B(r, c);
1120
+ b.startsWith("..") || (f = `${l}/${b.split(N).join("/")}`);
925
1121
  }
926
- let f, h;
1122
+ let p, u;
927
1123
  if (e.sourceMap) {
928
- const c = await ue(
1124
+ const c = await z(
929
1125
  i,
930
1126
  t,
931
1127
  r
932
1128
  );
933
- f = c.tree, h = c.content;
1129
+ p = c.tree, u = c.content;
934
1130
  } else
935
- h = await pt(
1131
+ u = await _t(
936
1132
  i,
937
1133
  t,
938
1134
  r
939
1135
  );
940
- const m = e.target ?? yt(h), ge = await Ot(e.xslDir ?? Tt(), m), P = Ze(l, {
1136
+ const m = e.target ?? Ot(u), R = await fn(e.xslDir ?? Yt(), m), g = pt(d, {
941
1137
  cssTheme: e.cssTheme,
942
1138
  revealTheme: e.revealTheme,
943
1139
  target: m
944
1140
  });
945
- Je(u, P);
946
- const E = Qe(P), N = g(p(r, a)), F = E.external !== void 0 && E.generated !== void 0 ? {
947
- external: p(N, E.external),
948
- generated: p(N, E.generated)
949
- } : void 0, T = Dt(h);
950
- let W = { parentId: "root", position: 1 };
951
- if (T !== "pretext" && T !== "mathbook")
952
- if (e.fragment) {
953
- const c = e.docinfo ?? (e.docinfoSourcePath ? await Mt(e.docinfoSourcePath, r) : void 0);
954
- h = Lt(
955
- h,
956
- T,
957
- m,
958
- c
959
- ), W = { parentId: c?.trim() ? "root-1-2" : "root-1-1", position: 2 };
960
- } else
1141
+ ct(f, g);
1142
+ const w = ht(g), J = I(h(r, a)), G = w.external !== void 0 && w.generated !== void 0 ? {
1143
+ external: h(J, w.external),
1144
+ generated: h(J, w.generated)
1145
+ } : void 0, D = rn(u);
1146
+ let K = { parentId: "root", position: 1 }, T, Y = t;
1147
+ if (D !== "pretext" && D !== "mathbook") {
1148
+ if (!e.fragment)
961
1149
  throw new Error(
962
- `The document root is <${T ?? "?"}>, not <pretext> — this looks like an xi:included fragment. Render the project's main source file instead, or pass the fragment option.`
1150
+ `The document root is <${D ?? "?"}>, not <pretext> — this looks like an xi:included fragment. Render the project's main source file instead, or pass the fragment option.`
963
1151
  );
964
- const U = f ? gt(f, t, W) : void 0, H = await n.fromString(h, {
965
- url: `${d}/${a.split(A).join("/")}`,
1152
+ if (e.contextSourcePath) {
1153
+ const c = await an(
1154
+ u,
1155
+ e.contextSourcePath,
1156
+ r
1157
+ );
1158
+ c && (u = c.content, p = e.sourceMap ? c.tree : void 0, Y = h(e.contextSourcePath), T = { divisionId: c.divisionId, level: c.level });
1159
+ }
1160
+ if (!T) {
1161
+ const c = e.docinfo ?? (e.docinfoSourcePath ? await on(e.docinfoSourcePath, r) : void 0);
1162
+ u = sn(
1163
+ u,
1164
+ D,
1165
+ m,
1166
+ c
1167
+ ), K = { parentId: c?.trim() ? "root-1-2" : "root-1-1", position: 2 };
1168
+ }
1169
+ }
1170
+ const q = p ? Pt(p, Y, K) : void 0, Z = await n.fromString(u, {
1171
+ url: `${l}/${a.split(N).join("/")}`,
966
1172
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
967
- }), I = {
968
- publisher: D(u)
1173
+ }), S = {
1174
+ publisher: k(f)
969
1175
  };
970
- for (const [c, w] of Object.entries(Rt))
971
- I[c] = D(w);
972
- for (const [c, w] of Object.entries(e.stringParams ?? {}))
973
- I[c] = D(w);
974
- let R;
1176
+ for (const [c, b] of Object.entries(tn))
1177
+ S[c] = k(b);
1178
+ T && (S.subtree = k(T.divisionId), S["subtree-level"] = k(String(T.level)));
1179
+ for (const [c, b] of Object.entries(e.stringParams ?? {}))
1180
+ S[c] = k(b);
1181
+ let O;
975
1182
  try {
976
- R = await ge.apply(H, I);
1183
+ O = await R.apply(Z, S);
977
1184
  } catch (c) {
978
- throw q(c), new Error(
1185
+ throw ce(c), new Error(
979
1186
  "PreTeXt XSLT transform failed; see the PTX:ERROR/PTX:FATAL messages on stderr for details.",
980
1187
  { cause: c }
981
1188
  );
982
1189
  } finally {
983
- H.delete();
1190
+ Z.delete();
984
1191
  }
985
1192
  try {
986
- let c = _t(R.toHtmlString());
987
- return (e.openKnowls ?? !0) && (c = We(c)), m === "slides" ? (c = kt(c), c = ft(c, e.revealView ?? "scroll", {
1193
+ let c = Qt(O.toHtmlString());
1194
+ return c = Kt(c, {
1195
+ ...e.offPageMessage !== void 0 ? { offPageMessage: e.offPageMessage } : {}
1196
+ }), (e.openKnowls ?? !0) && (c = nt(c)), m === "slides" ? (c = nn(c), c = It(c, e.revealView ?? "scroll", {
988
1197
  zoom: e.revealZoom
989
- })) : e.theme && (c = Et(c, e.theme)), e.previewBanner && (c = ke(c, e.previewBanner)), {
1198
+ })) : e.theme && (c = Ct(c, e.theme)), e.previewBanner && (c = Ve(c, e.previewBanner)), {
990
1199
  html: c,
991
1200
  target: m,
992
- ...U ? { sourceMap: U } : {},
993
- ...F ? { assetDirs: F } : {}
1201
+ ...q ? { sourceMap: q } : {},
1202
+ ...G ? { assetDirs: G } : {}
994
1203
  };
995
1204
  } catch (c) {
996
- throw q(c), c;
1205
+ throw ce(c), c;
997
1206
  } finally {
998
- R.delete();
1207
+ O.delete();
999
1208
  }
1000
1209
  } finally {
1001
- ze(d);
1210
+ at(l);
1002
1211
  }
1003
1212
  }
1004
1213
  export {
1005
- xe as PREVIEW_BANNER_STORAGE_KEY,
1006
- we as PREVIEW_THEME_MESSAGE,
1007
- Tt as defaultXslDir,
1008
- yt as detectRenderTarget,
1009
- Ht as findSourceMapEntry,
1010
- Ze as forcePortablePublication,
1011
- ke as injectPreviewBanner,
1012
- ft as injectRevealBridge,
1013
- Et as injectThemeBridge,
1014
- St as isJspiAvailable,
1015
- Xt as isPreviewTheme,
1016
- Ut as isRevealView,
1017
- We as openBornHiddenKnowls,
1018
- $e as previewBannerScript,
1019
- Vt as previewThemeMessage,
1020
- zt as renderHtml,
1021
- at as revealBridgeScript,
1022
- Ft as setAssetsBase,
1023
- Wt as setMountReader,
1024
- xt as themeBridgeScript,
1025
- D as xpathStringLiteral
1214
+ Be as PREVIEW_BANNER_STORAGE_KEY,
1215
+ $e as PREVIEW_THEME_MESSAGE,
1216
+ Yt as defaultXslDir,
1217
+ Ot as detectRenderTarget,
1218
+ gn as findSourceMapEntry,
1219
+ pt as forcePortablePublication,
1220
+ Ve as injectPreviewBanner,
1221
+ It as injectRevealBridge,
1222
+ Ct as injectThemeBridge,
1223
+ qt as isJspiAvailable,
1224
+ bn as isPreviewTheme,
1225
+ vn as isRevealView,
1226
+ nt as openBornHiddenKnowls,
1227
+ Ne as previewBannerScript,
1228
+ xn as previewThemeMessage,
1229
+ En as renderHtml,
1230
+ yt as revealBridgeScript,
1231
+ mn as setAssetsBase,
1232
+ wn as setMountReader,
1233
+ Bt as themeBridgeScript,
1234
+ k as xpathStringLiteral
1026
1235
  };