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