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