@pretextbook/pretext-html 0.6.0 → 0.7.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 (96) hide show
  1. package/assets/upstream.json +1 -1
  2. package/assets/xsl/LICENSE-pretext +1 -1
  3. package/assets/xsl/README.md +43 -25
  4. package/assets/xsl/entities.ent +4 -4
  5. package/assets/xsl/extract-asymptote.xsl +5 -5
  6. package/assets/xsl/extract-biblio-csl.xsl +1 -1
  7. package/assets/xsl/extract-datafile.xsl +1 -1
  8. package/assets/xsl/extract-dynamic.xsl +1 -1
  9. package/assets/xsl/extract-identity.xsl +5 -5
  10. package/assets/xsl/extract-interactive.xsl +1 -1
  11. package/assets/xsl/extract-latex-image.xsl +5 -5
  12. package/assets/xsl/extract-mermaid.xsl +1 -1
  13. package/assets/xsl/extract-mom.xsl +5 -5
  14. package/assets/xsl/extract-pg.xsl +1 -1
  15. package/assets/xsl/extract-prefigure.xsl +5 -5
  16. package/assets/xsl/extract-qrcode.xsl +1 -1
  17. package/assets/xsl/extract-runestone-page-template.xsl +1 -1
  18. package/assets/xsl/extract-sageplot.xsl +5 -5
  19. package/assets/xsl/extract-stack.xsl +1 -1
  20. package/assets/xsl/extract-trace.xsl +1 -1
  21. package/assets/xsl/extract-youtube.xsl +5 -5
  22. package/assets/xsl/latex/pretext-latex-AIM.xsl +1 -1
  23. package/assets/xsl/latex/pretext-latex-chaos.xsl +1 -1
  24. package/assets/xsl/latex/pretext-latex-dyslexic-font.xsl +1 -1
  25. package/assets/xsl/latex/pretext-latex-guide.xsl +1 -1
  26. package/assets/xsl/localizations/README.md +25 -25
  27. package/assets/xsl/localizations/af-ZA.xml +1 -1
  28. package/assets/xsl/localizations/bg-BG.xml +1 -1
  29. package/assets/xsl/localizations/ca-ES.xml +1 -1
  30. package/assets/xsl/localizations/cs-CZ.xml +1 -1
  31. package/assets/xsl/localizations/de-DE.xml +1 -1
  32. package/assets/xsl/localizations/en-US.xml +1 -1
  33. package/assets/xsl/localizations/es-ES.xml +1 -1
  34. package/assets/xsl/localizations/fi-FI.xml +1 -1
  35. package/assets/xsl/localizations/fr-CA.xml +1 -1
  36. package/assets/xsl/localizations/fr-FR.xml +1 -1
  37. package/assets/xsl/localizations/hu-HU.xml +1 -1
  38. package/assets/xsl/localizations/it-IT.xml +1 -1
  39. package/assets/xsl/localizations/ku-CKB.xml +1 -1
  40. package/assets/xsl/localizations/localizations.xml +1 -1
  41. package/assets/xsl/localizations/nl-NL.xml +1 -1
  42. package/assets/xsl/localizations/pt-BR.xml +1 -1
  43. package/assets/xsl/localizations/pt-PT.xml +1 -1
  44. package/assets/xsl/localizations/zh-HANS.xml +1 -1
  45. package/assets/xsl/pretext-assembly.xsl +64 -1
  46. package/assets/xsl/pretext-basic-html.xsl +5 -5
  47. package/assets/xsl/pretext-braille-preprint.xsl +5 -5
  48. package/assets/xsl/pretext-common.xsl +104 -30
  49. package/assets/xsl/pretext-dynamic.xsl +1 -1
  50. package/assets/xsl/pretext-epub.xsl +90 -84
  51. package/assets/xsl/pretext-fo.xsl +1 -1
  52. package/assets/xsl/pretext-html.xsl +57 -34
  53. package/assets/xsl/pretext-json-manifest.xsl +1 -1
  54. package/assets/xsl/pretext-jupyter.xsl +5 -5
  55. package/assets/xsl/pretext-latex-classic.xsl +1 -1
  56. package/assets/xsl/pretext-latex-common.xsl +7 -5
  57. package/assets/xsl/pretext-latex.xsl +3 -3
  58. package/assets/xsl/pretext-litprog.xsl +9 -2
  59. package/assets/xsl/pretext-markdown.xsl +1 -1
  60. package/assets/xsl/pretext-numbers.xsl +1 -1
  61. package/assets/xsl/pretext-runestone-fitb.xsl +18 -0
  62. package/assets/xsl/pretext-runestone-static.xsl +13 -1
  63. package/assets/xsl/pretext-runestone.xsl +34 -6
  64. package/assets/xsl/pretext-sage-doctest.xsl +18 -0
  65. package/assets/xsl/pretext-solution-manual-latex.xsl +4 -4
  66. package/assets/xsl/pretext-text-utilities.xsl +1 -1
  67. package/assets/xsl/pretext-text.xsl +5 -5
  68. package/assets/xsl/pretext-units.xsl +5 -5
  69. package/assets/xsl/pretext-view-source.xsl +1 -1
  70. package/assets/xsl/pretext-ww-problem-sets.xsl +15 -12
  71. package/assets/xsl/publisher-variables.xsl +104 -36
  72. package/assets/xsl/support/README.md +19 -0
  73. package/assets/xsl/support/extract-math.xsl +1 -1
  74. package/assets/xsl/support/package-math.xsl +1 -1
  75. package/assets/xsl/support/play-button/README.md +3 -1
  76. package/assets/xsl/support/webpack_static_imports.xml +19 -0
  77. package/assets/xsl/tests/README.md +20 -1
  78. package/assets/xsl/tests/null.xml +19 -0
  79. package/assets/xsl/tests/pretext-text-utilities-test.xsl +1 -1
  80. package/assets/xsl/utilities/README.md +27 -6
  81. package/assets/xsl/utilities/author-report.xsl +1 -1
  82. package/assets/xsl/utilities/fix-deprecations.xsl +5 -5
  83. package/assets/xsl/utilities/pretext-enhanced-source.xsl +1 -1
  84. package/assets/xsl/utilities/report-publisher-variables.xsl +5 -5
  85. package/assets/xsl/xml-to-json.xsl +4 -4
  86. package/assets/xsl-bundle.json +1 -1
  87. package/dist/banner.d.ts +51 -0
  88. package/dist/{cli-DF7XOWN7.js → cli-D0m0Ha1j.js} +343 -211
  89. package/dist/cli.js +2 -2
  90. package/dist/index.browser.d.ts +2 -0
  91. package/dist/index.browser.js +528 -396
  92. package/dist/index.d.ts +2 -0
  93. package/dist/index.js +28 -25
  94. package/dist/renderer.d.ts +13 -0
  95. package/package.json +1 -1
  96. package/assets/xsl/pretext-smc.xsl +0 -492
@@ -1,95 +1,224 @@
1
- import { fromXml as E } from "xast-util-from-xml";
1
+ import { fromXml as x } from "xast-util-from-xml";
2
2
  import { toXml as $ } from "xast-util-to-xml";
3
- const D = "/";
4
- function ve(e) {
3
+ const M = "/";
4
+ function ge(e) {
5
5
  if (!e)
6
6
  return ".";
7
- const t = e.startsWith("/"), n = e.length > 1 && e.endsWith("/"), r = [];
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() : t || r.push("..");
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("..");
13
13
  continue;
14
14
  }
15
- r.push(o);
15
+ r.push(s);
16
16
  }
17
17
  let i = r.join("/");
18
- return t && (i = `/${i}`), i ? (n && !i.endsWith("/") && (i += "/"), i) : t ? "/" : ".";
18
+ return n && (i = `/${i}`), i ? (t && !i.endsWith("/") && (i += "/"), i) : n ? "/" : ".";
19
19
  }
20
- function h(...e) {
21
- let t = "";
20
+ function p(...e) {
21
+ let n = "";
22
22
  for (let r = e.length - 1; r >= 0; r--) {
23
23
  const i = e[r];
24
- if (i && (t = t ? `${i}/${t}` : i, i.startsWith("/")))
24
+ if (i && (n = n ? `${i}/${n}` : i, i.startsWith("/")))
25
25
  break;
26
26
  }
27
- t.startsWith("/") || (t = `/${t}`);
28
- const n = ve(t);
29
- return n.length > 1 && n.endsWith("/") ? n.slice(0, -1) : n;
27
+ n.startsWith("/") || (n = `/${n}`);
28
+ const t = ge(n);
29
+ return t.length > 1 && t.endsWith("/") ? t.slice(0, -1) : t;
30
30
  }
31
- function b(e) {
32
- const t = e.replace(/\/+$/, "");
33
- if (!t)
31
+ function g(e) {
32
+ const n = e.replace(/\/+$/, "");
33
+ if (!n)
34
34
  return e.startsWith("/") ? "/" : ".";
35
- const n = t.lastIndexOf("/");
36
- return n < 0 ? "." : n === 0 ? "/" : t.slice(0, n);
35
+ const t = n.lastIndexOf("/");
36
+ return t < 0 ? "." : t === 0 ? "/" : n.slice(0, t);
37
37
  }
38
- function I(e, t) {
39
- const n = h(e).split("/").filter(Boolean), r = h(t).split("/").filter(Boolean);
38
+ function I(e, n) {
39
+ const t = p(e).split("/").filter(Boolean), r = p(n).split("/").filter(Boolean);
40
40
  let i = 0;
41
- for (; i < n.length && i < r.length && n[i] === r[i]; )
41
+ for (; i < t.length && i < r.length && t[i] === r[i]; )
42
42
  i += 1;
43
- return [...new Array(n.length - i).fill(".."), ...r.slice(i)].join("/");
43
+ return [...new Array(t.length - i).fill(".."), ...r.slice(i)].join("/");
44
44
  }
45
- const be = "https://cdn.jsdelivr.net/npm/@pretextbook/pretext-html@0.6.0/assets";
46
- let Q;
47
- function St(e) {
48
- Q = e.replace(/\/+$/, "");
45
+ const ye = "ptxPreviewBannerDismissed", xe = "About live preview";
46
+ function X(e) {
47
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
48
+ }
49
+ function Ee(e) {
50
+ return [
51
+ '<div id="ptx-preview-banner" class="ptx-preview-banner" role="note">',
52
+ ` <span class="ptx-preview-banner-text">${X(e)}</span>`,
53
+ ' <button type="button" class="ptx-preview-banner-dismiss" aria-label="Dismiss">&times;</button>',
54
+ "</div>",
55
+ `<button type="button" id="ptx-preview-banner-restore" class="ptx-preview-banner-restore" hidden>${X(xe)}</button>`
56
+ ].join(`
57
+ `);
58
+ }
59
+ function Te() {
60
+ return [
61
+ "<style>",
62
+ ".ptx-preview-banner {",
63
+ " display: flex;",
64
+ " align-items: center;",
65
+ " gap: 0.75em;",
66
+ " padding: 0.5em 1em;",
67
+ " font-size: 0.9em;",
68
+ " background: #fff8e1;",
69
+ " color: #6b5300;",
70
+ " border-bottom: 1px solid #f0c36d;",
71
+ "}",
72
+ // The [hidden] content attribute only hides an element via the
73
+ // user-agent stylesheet's `[hidden] { display: none }` rule, and a
74
+ // normal-priority *author* rule always wins over a normal-priority UA
75
+ // rule regardless of selector specificity — so the unconditional
76
+ // `display: flex` above would otherwise keep the banner visible even
77
+ // after previewBannerScript sets `banner.hidden = true`.
78
+ ".ptx-preview-banner[hidden] {",
79
+ " display: none;",
80
+ "}",
81
+ ".ptx-preview-banner-text {",
82
+ " flex: 1 1 auto;",
83
+ "}",
84
+ ".ptx-preview-banner-dismiss {",
85
+ " flex: 0 0 auto;",
86
+ " background: transparent;",
87
+ " border: none;",
88
+ " font-size: 1.2em;",
89
+ " line-height: 1;",
90
+ " cursor: pointer;",
91
+ " color: inherit;",
92
+ " padding: 0 0.25em;",
93
+ "}",
94
+ "html.dark-mode .ptx-preview-banner {",
95
+ " background: #3a2f00;",
96
+ " color: #f2d27a;",
97
+ " border-bottom-color: #6b5300;",
98
+ "}",
99
+ ".ptx-preview-banner-restore {",
100
+ " position: fixed;",
101
+ " right: 0.5em;",
102
+ " bottom: 0.5em;",
103
+ " z-index: 1000;",
104
+ " background: transparent;",
105
+ " border: none;",
106
+ " padding: 0.15em 0.4em;",
107
+ " font-size: 0.75em;",
108
+ " color: inherit;",
109
+ " opacity: 0.45;",
110
+ " text-decoration: underline;",
111
+ " cursor: pointer;",
112
+ "}",
113
+ ".ptx-preview-banner-restore:hover {",
114
+ " opacity: 0.85;",
115
+ "}",
116
+ "</style>"
117
+ ].join(`
118
+ `);
119
+ }
120
+ function $e() {
121
+ return [
122
+ "<script>",
123
+ "(function () {",
124
+ " var KEY = " + JSON.stringify(ye) + ";",
125
+ ' var banner = document.getElementById("ptx-preview-banner");',
126
+ ' var restore = document.getElementById("ptx-preview-banner-restore");',
127
+ " if (!banner || !restore) { return; }",
128
+ // localStorage can throw (disabled cookies/storage, sandboxed iframe);
129
+ // fall back to always showing the banner rather than crashing the page.
130
+ " function isDismissed() {",
131
+ " try { return window.localStorage.getItem(KEY) === '1'; }",
132
+ " catch (e) { return false; }",
133
+ " }",
134
+ " function setDismissed(value) {",
135
+ " try {",
136
+ " if (value) { window.localStorage.setItem(KEY, '1'); }",
137
+ " else { window.localStorage.removeItem(KEY); }",
138
+ " } catch (e) {}",
139
+ " }",
140
+ " function apply(dismissed) {",
141
+ " banner.hidden = dismissed;",
142
+ " restore.hidden = !dismissed;",
143
+ " }",
144
+ " apply(isDismissed());",
145
+ ' var dismissBtn = banner.querySelector(".ptx-preview-banner-dismiss");',
146
+ " if (dismissBtn) {",
147
+ " dismissBtn.addEventListener('click', function () {",
148
+ " setDismissed(true);",
149
+ " apply(true);",
150
+ " });",
151
+ " }",
152
+ " restore.addEventListener('click', function () {",
153
+ " setDismissed(false);",
154
+ " apply(false);",
155
+ " });",
156
+ "})();",
157
+ "<\/script>"
158
+ ].join(`
159
+ `);
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;
164
+ if (!/<body[^>]*>/i.test(r))
165
+ return r;
166
+ const i = `
167
+ ${Se}
168
+ ${Te()}
169
+ ${Ee(n.message)}
170
+ ${$e()}
171
+ ${_e}`;
172
+ return r.replace(/<body([^>]*)>/i, `<body$1>${i}`);
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(/\/+$/, "");
49
178
  }
50
179
  function S() {
51
- return Q ?? be;
180
+ return ee ?? De;
52
181
  }
53
- function ee(e, t) {
54
- return `${e.replace(/\/+$/, "")}/${t.replace(/^\/+/, "")}`;
182
+ function te(e, n) {
183
+ return `${e.replace(/\/+$/, "")}/${n.replace(/^\/+/, "")}`;
55
184
  }
56
185
  const U = /* @__PURE__ */ new Map();
57
- function ye(e) {
186
+ function Re(e) {
58
187
  return `${e.replace(/\/+$/, "")}-bundle.json`;
59
188
  }
60
- function Ee(e) {
61
- let t = U.get(e);
62
- return t || (t = (async () => {
189
+ function Me(e) {
190
+ let n = U.get(e);
191
+ return n || (n = (async () => {
63
192
  try {
64
- const n = await fetch(ye(e));
65
- if (!n.ok)
193
+ const t = await fetch(Re(e));
194
+ if (!t.ok)
66
195
  return /* @__PURE__ */ new Map();
67
- const r = await n.json();
196
+ const r = await t.json();
68
197
  return new Map(Object.entries(r));
69
198
  } catch {
70
199
  return /* @__PURE__ */ new Map();
71
200
  }
72
- })(), U.set(e, t)), t;
201
+ })(), U.set(e, n)), n;
73
202
  }
74
- function xe(e) {
75
- return e === ee(S(), "xsl");
203
+ function Le(e) {
204
+ return e === te(S(), "xsl");
76
205
  }
77
- async function te(e, t) {
78
- if (xe(e)) {
79
- const o = (await Ee(e)).get(t.replace(/^\/+/, ""));
80
- if (o !== void 0)
81
- return new TextEncoder().encode(o);
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);
82
211
  }
83
- const n = `${e.replace(/\/+$/, "")}/`;
212
+ const t = `${e.replace(/\/+$/, "")}/`;
84
213
  let r;
85
214
  try {
86
- r = new URL(t.replace(/^\/+/, ""), n);
215
+ r = new URL(n.replace(/^\/+/, ""), t);
87
216
  } catch {
88
217
  return;
89
218
  }
90
- if (!r.href.startsWith(n)) {
219
+ if (!r.href.startsWith(t)) {
91
220
  console.error(
92
- `pretext-html: refusing to serve ${t} from outside ${e}`
221
+ `pretext-html: refusing to serve ${n} from outside ${e}`
93
222
  );
94
223
  return;
95
224
  }
@@ -100,76 +229,76 @@ async function te(e, t) {
100
229
  return;
101
230
  }
102
231
  }
103
- async function P(e) {
232
+ async function B(e) {
104
233
  if (/^[a-z][a-z0-9+.-]*:\/\//i.test(e))
105
234
  try {
106
- const t = await fetch(e);
107
- return t.ok ? await t.text() : void 0;
235
+ const n = await fetch(e);
236
+ return n.ok ? await n.text() : void 0;
108
237
  } catch {
109
238
  return;
110
239
  }
111
240
  }
112
- const Te = "born-hidden-knowl", $e = /<details\b([^>]*)>(\s*)(?:<summary\b([^>]*)>)?/g;
113
- function Se(e) {
114
- const t = /\bclass="([^"]*)"/.exec(e);
115
- return t ? t[1].trim().split(/\s+/) : [];
241
+ const Ae = "born-hidden-knowl", Be = /<details\b([^>]*)>(\s*)(?:<summary\b([^>]*)>)?/g;
242
+ function Ce(e) {
243
+ const n = /\bclass="([^"]*)"/.exec(e);
244
+ return n ? n[1].trim().split(/\s+/) : [];
116
245
  }
117
- function _e(e) {
246
+ function Pe(e) {
118
247
  return /(^|\s)open(\s|=|$)/.test(e);
119
248
  }
120
- function N(e) {
121
- return _e(e) ? e : ` open${e}`;
249
+ function V(e) {
250
+ return Pe(e) ? e : ` open${e}`;
122
251
  }
123
- function ke(e) {
252
+ function je(e) {
124
253
  return e.replace(
125
- $e,
126
- (t, n, r, i) => {
127
- if (!Se(n).includes(Te))
128
- return t;
129
- const o = `<details${N(n)}>`;
130
- return i === void 0 ? `${o}${r}` : `${o}${r}<summary${N(i)}>`;
254
+ Be,
255
+ (n, t, r, i) => {
256
+ if (!Ce(t).includes(Ae))
257
+ return n;
258
+ const s = `<details${V(t)}>`;
259
+ return i === void 0 ? `${s}${r}` : `${s}${r}<summary${V(i)}>`;
131
260
  }
132
261
  );
133
262
  }
134
- const C = /* @__PURE__ */ new Map(), ne = /* @__PURE__ */ new Map();
135
- let L, Ie = 0, re = te;
136
- function _t(e) {
137
- re = e;
263
+ const C = /* @__PURE__ */ new Map(), re = /* @__PURE__ */ new Map();
264
+ let L, Oe = 0, ie = ne;
265
+ function Pt(e) {
266
+ ie = e;
138
267
  }
139
- function Re(e, t) {
140
- const n = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, r = ne.get(n);
268
+ function We(e, n) {
269
+ const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, r = re.get(t);
141
270
  if (r !== void 0)
142
271
  return Promise.resolve(new Response(r, { status: 200 }));
143
272
  let i;
144
273
  try {
145
- i = new URL(n).host;
274
+ i = new URL(t).host;
146
275
  } catch {
147
276
  i = "";
148
277
  }
149
- const o = C.get(i);
150
- return o !== void 0 ? De(o, n) : L(e, t);
278
+ const s = C.get(i);
279
+ return s !== void 0 ? Ne(s, t) : L(e, n);
151
280
  }
152
- const Me = '<?xml version="1.0"?><pretext-preview-missing-file/>';
153
- async function De(e, t) {
154
- const n = decodeURIComponent(new URL(t).pathname), r = await re(e, n);
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);
155
284
  if (r === void 0)
156
- return new Response(Me, { status: 200 });
285
+ return new Response(Fe, { status: 200 });
157
286
  const i = typeof r == "string" ? r : new Uint8Array(r);
158
287
  return new Response(i, { status: 200 });
159
288
  }
160
- function ie() {
161
- L || (L = globalThis.fetch, globalThis.fetch = Re);
289
+ function se() {
290
+ L || (L = globalThis.fetch, globalThis.fetch = We);
162
291
  }
163
292
  function oe(e) {
164
- ie();
165
- const t = `mnt${++Ie}.ptx.invalid`;
166
- return C.set(t, e), `http://${t}`;
293
+ se();
294
+ const n = `mnt${++Oe}.ptx.invalid`;
295
+ return C.set(n, e), `http://${n}`;
167
296
  }
168
- function Le(e) {
297
+ function He(e) {
169
298
  C.delete(new URL(e).host);
170
299
  }
171
- function Ae(e, t) {
172
- ie(), ne.set(e, t);
300
+ function Xe(e, n) {
301
+ se(), re.set(e, n);
173
302
  }
174
303
  const A = `<?xml version="1.0" encoding="UTF-8"?>
175
304
  <publication>
@@ -180,82 +309,82 @@ const A = `<?xml version="1.0" encoding="UTF-8"?>
180
309
  <platform portable="yes"/>
181
310
  </html>
182
311
  </publication>
183
- `, Pe = ["theme", "style", "shell"];
184
- function w(e, t) {
185
- for (const n of e.children)
186
- if (n.type === "element" && n.name === t)
187
- return n;
188
- }
189
- function g(e, t) {
190
- let n = w(e, t);
191
- return n || (n = { type: "element", name: t, attributes: {}, children: [] }, e.children.push(n)), n;
192
- }
193
- function Ce(e, t) {
194
- const n = w(e, "css");
195
- if (n && Pe.some((i) => n.attributes?.[i]))
312
+ `, Ue = ["theme", "style", "shell"];
313
+ function w(e, n) {
314
+ for (const t of e.children)
315
+ if (t.type === "element" && t.name === n)
316
+ return t;
317
+ }
318
+ function v(e, n) {
319
+ let t = w(e, n);
320
+ return t || (t = { type: "element", name: n, attributes: {}, children: [] }, e.children.push(t)), t;
321
+ }
322
+ function Ve(e, n) {
323
+ const t = w(e, "css");
324
+ if (t && Ue.some((i) => t.attributes?.[i]))
196
325
  return;
197
- const r = n ?? g(e, "css");
198
- r.attributes = { ...r.attributes, theme: t };
326
+ const r = t ?? v(e, "css");
327
+ r.attributes = { ...r.attributes, theme: n };
199
328
  }
200
- function je(e, t) {
201
- const n = w(e, "appearance");
202
- if (n?.attributes?.theme)
329
+ function ze(e, n) {
330
+ const t = w(e, "appearance");
331
+ if (t?.attributes?.theme)
203
332
  return;
204
- const r = n ?? g(e, "appearance");
205
- r.attributes = { ...r.attributes, theme: t };
333
+ const r = t ?? v(e, "appearance");
334
+ r.attributes = { ...r.attributes, theme: n };
206
335
  }
207
- function Fe(e) {
208
- const t = g(e, "resources");
209
- t.attributes = {
210
- ...t.attributes,
336
+ function Je(e) {
337
+ const n = v(e, "resources");
338
+ n.attributes = {
339
+ ...n.attributes,
211
340
  host: "cdn",
212
341
  math: "online"
213
342
  };
214
343
  }
215
- function Oe(e, t = {}) {
216
- const n = t.cssTheme?.trim(), r = t.revealTheme?.trim(), i = t.target === "slides";
217
- if (!e && !n && !i)
344
+ function Ke(e, n = {}) {
345
+ const t = n.cssTheme?.trim(), r = n.revealTheme?.trim(), i = n.target === "slides";
346
+ if (!e && !t && !i)
218
347
  return A;
219
- const o = E(e ?? A), s = w(o, "publication");
220
- if (!s)
348
+ const s = x(e ?? A), o = w(s, "publication");
349
+ if (!o)
221
350
  throw new Error(
222
351
  "Invalid publication file: no root <publication> element found"
223
352
  );
224
- const a = g(s, "html"), u = g(a, "platform");
225
- if (u.attributes = { ...u.attributes, portable: "yes" }, n && Ce(a, n), i) {
226
- const l = g(s, "revealjs");
227
- Fe(l), r && je(l, r);
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);
228
357
  }
229
- return $(o);
358
+ return $(s);
230
359
  }
231
- function V(e) {
360
+ function z(e) {
232
361
  if (!(e === void 0 || e === "" || e.startsWith("/")))
233
362
  return e.endsWith("/") ? e : `${e}/`;
234
363
  }
235
- function We(e) {
236
- const t = E(e ?? A), n = w(t, "publication"), r = n && w(n, "source"), i = r && w(r, "directories"), o = V(
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(
237
366
  i?.attributes?.external ?? void 0
238
- ), s = V(
367
+ ), o = z(
239
368
  i?.attributes?.generated ?? void 0
240
369
  );
241
370
  return {
242
- external: o,
243
- generated: s,
244
- managed: o !== void 0 && s !== void 0
371
+ external: s,
372
+ generated: o,
373
+ managed: s !== void 0 && o !== void 0
245
374
  };
246
375
  }
247
- function kt(e) {
376
+ function jt(e) {
248
377
  return e === "slides" || e === "scroll";
249
378
  }
250
- const se = 960, ae = 700, Be = 1, Xe = 0.04;
251
- function He(e) {
252
- const t = typeof e == "number" && isFinite(e) ? e : Be, n = Math.min(1, Math.max(0.25, t));
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));
253
382
  return {
254
- width: Math.round(se / n),
255
- height: Math.round(ae / n)
383
+ width: Math.round(ae / t),
384
+ height: Math.round(ce / t)
256
385
  };
257
386
  }
258
- function Ue(e) {
387
+ function Qe(e) {
259
388
  return {
260
389
  view: "scroll",
261
390
  scrollLayout: "compact",
@@ -265,11 +394,11 @@ function Ue(e) {
265
394
  controls: !1,
266
395
  controlsTutorial: !1,
267
396
  hash: !1,
268
- ...He(e.zoom),
269
- margin: Xe
397
+ ...Ze(e.zoom),
398
+ margin: qe
270
399
  };
271
400
  }
272
- function Ne() {
401
+ function et() {
273
402
  return {
274
403
  // Explicitly null rather than absent: the same page may have been
275
404
  // delivered in scroll view a moment ago, and an embedder that re-injects
@@ -281,11 +410,11 @@ function Ne() {
281
410
  // size with a percentage width renders its text far larger, relative to
282
411
  // the slide, than the same deck will on a projector. No zoom margin
283
412
  // though — presenting means filling whatever it is shown in.
284
- width: se,
285
- height: ae
413
+ width: ae,
414
+ height: ce
286
415
  };
287
416
  }
288
- const Ve = [
417
+ const tt = [
289
418
  "<style>",
290
419
  ".reveal-viewport.reveal-scroll .scroll-page section {",
291
420
  " box-shadow: inset 0 0 0 calc(1px / var(--slide-scale, 1))",
@@ -293,18 +422,18 @@ const Ve = [
293
422
  "}",
294
423
  "</style>"
295
424
  ].join(`
296
- `), ze = [
425
+ `), nt = [
297
426
  " var paused = document.querySelectorAll('.reveal .fragment');",
298
427
  " for (var i = 0; i < paused.length; i++) {",
299
428
  " paused[i].classList.remove('fragment');",
300
429
  " }"
301
430
  ];
302
- function Je(e, t = {}) {
303
- const n = e === "scroll" ? Ue(t) : Ne();
431
+ function rt(e, n = {}) {
432
+ const t = e === "scroll" ? Qe(n) : et();
304
433
  return [
305
434
  "<script>",
306
435
  "(function () {",
307
- " var OVERRIDES = " + JSON.stringify(n) + ";",
436
+ " var OVERRIDES = " + JSON.stringify(t) + ";",
308
437
  // Nothing to wrap if reveal.js failed to load (offline, CDN blocked). The
309
438
  // deck is broken either way, but throwing here would replace the browser's
310
439
  // useful network error with a confusing one from an injected script.
@@ -328,7 +457,7 @@ function Je(e, t = {}) {
328
457
  // Inside the wrapper rather than at top level: this script sits in <head>,
329
458
  // where the slides have not been parsed yet, but the deck calls initialize
330
459
  // from the end of the document, by which time they have.
331
- ...e === "scroll" ? ze : [],
460
+ ...e === "scroll" ? nt : [],
332
461
  " return initialize(merged);",
333
462
  " };",
334
463
  "})();",
@@ -336,107 +465,107 @@ function Je(e, t = {}) {
336
465
  ].join(`
337
466
  `);
338
467
  }
339
- const Ge = /<script\b[^>]*\bsrc=["'][^"']*\breveal\.js["'][^>]*>\s*<\/script>/i, Ke = "<!--ptx-reveal-view-->", Ye = "<!--/ptx-reveal-view-->", qe = /\n?<!--ptx-reveal-view-->[\s\S]*?<!--\/ptx-reveal-view-->/;
340
- function Ze(e, t, n = {}) {
341
- const r = qe.exec(e), i = r ? e.slice(0, r.index) + e.slice(r.index + r[0].length) : e, o = Ge.exec(i);
342
- if (!o)
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)
343
472
  return i;
344
- const s = o.index + o[0].length, a = `
345
- ${Ke}
346
- ${Ve}
347
- ${Je(t, n)}
348
- ${Ye}`;
349
- return i.slice(0, s) + a + i.slice(s);
350
- }
351
- const ce = "http://www.w3.org/2001/XInclude", z = 64;
352
- async function Qe(e, t, n) {
353
- return e.includes("include") ? (await le(e, t, n)).content : e;
354
- }
355
- async function le(e, t, n) {
356
- const r = E(e), i = {
357
- projectDir: h(n),
358
- stack: [h(t)]
359
- }, o = await y(
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(
360
489
  r,
361
- b(h(t)),
490
+ g(p(n)),
362
491
  { "": "" },
363
492
  i
364
493
  );
365
- return { tree: r, content: o ? $(r) : e };
494
+ return { tree: r, content: s ? $(r) : e };
366
495
  }
367
- function et(e) {
496
+ function dt(e) {
368
497
  return e.data?.ptxIncludedFile;
369
498
  }
370
- function tt(e, t) {
371
- const n = e.data ?? (e.data = {});
372
- n.ptxIncludedFile = t;
499
+ function ut(e, n) {
500
+ const t = e.data ?? (e.data = {});
501
+ t.ptxIncludedFile = n;
373
502
  }
374
- function _(e, t) {
375
- let n = e;
376
- for (const [r, i] of Object.entries(t.attributes))
377
- (r === "xmlns" || r.startsWith("xmlns:")) && (n === e && (n = { ...e }), n[r === "xmlns" ? "" : r.slice(6)] = i ?? "");
378
- return n;
503
+ function _(e, n) {
504
+ let t = e;
505
+ for (const [r, i] of Object.entries(n.attributes))
506
+ (r === "xmlns" || r.startsWith("xmlns:")) && (t === e && (t = { ...e }), t[r === "xmlns" ? "" : r.slice(6)] = i ?? "");
507
+ return t;
379
508
  }
380
- function ue(e, t) {
381
- const n = e.name.indexOf(":"), r = n === -1 ? "" : e.name.slice(0, n);
382
- return (n === -1 ? e.name : e.name.slice(n + 1)) === "include" && t[r] === ce;
509
+ function ue(e, n) {
510
+ 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;
383
512
  }
384
- async function y(e, t, n, r) {
513
+ async function y(e, n, t, r) {
385
514
  let i = !1;
386
- for (let o = 0; o < e.children.length; o++) {
387
- const s = e.children[o];
388
- if (s.type !== "element")
515
+ for (let s = 0; s < e.children.length; s++) {
516
+ const o = e.children[s];
517
+ if (o.type !== "element")
389
518
  continue;
390
- const a = _(n, s);
391
- if (ue(s, a)) {
392
- const u = await de(
393
- s,
394
- t,
519
+ const a = _(t, o);
520
+ if (ue(o, a)) {
521
+ const d = await fe(
522
+ o,
523
+ n,
395
524
  a,
396
525
  r
397
526
  );
398
- e.children.splice(o, 1, ...u), o += u.length - 1, i = !0;
399
- } else await y(s, t, a, r) && (i = !0);
527
+ e.children.splice(s, 1, ...d), s += d.length - 1, i = !0;
528
+ } else await y(o, n, a, r) && (i = !0);
400
529
  }
401
530
  return i;
402
531
  }
403
- async function de(e, t, n, r) {
532
+ async function fe(e, n, t, r) {
404
533
  const i = r.stack[r.stack.length - 1];
405
534
  if (e.attributes.xpointer)
406
535
  throw new Error(
407
536
  `xi:include with xpointer is not supported by the JS preview build (in ${i})`
408
537
  );
409
- const o = e.attributes.href;
410
- if (!o)
538
+ const s = e.attributes.href;
539
+ if (!s)
411
540
  throw new Error(`xi:include without href (in ${i})`);
412
- let s = o;
541
+ let o = s;
413
542
  try {
414
- s = decodeURIComponent(o);
543
+ o = decodeURIComponent(s);
415
544
  } catch {
416
545
  }
417
- const a = h(t, s);
418
- if (a !== r.projectDir && !a.startsWith(r.projectDir + D))
546
+ const a = p(n, o);
547
+ if (a !== r.projectDir && !a.startsWith(r.projectDir + M))
419
548
  throw new Error(
420
- `xi:include escapes the project directory: ${o} (in ${i})`
549
+ `xi:include escapes the project directory: ${s} (in ${i})`
421
550
  );
422
551
  if (r.stack.includes(a))
423
552
  throw new Error(
424
553
  `Circular xi:include: ${[...r.stack, a].join(" -> ")}`
425
554
  );
426
- if (r.stack.length >= z)
427
- throw new Error(`xi:include nesting exceeds ${z} levels`);
428
- const u = await P(a);
429
- if (u === void 0) {
430
- const f = rt(e, n);
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);
431
560
  if (f)
432
- return await y(f, t, n, r), f.children;
433
- throw new Error(`xi:include target not found: ${o} (in ${i})`);
561
+ return await y(f, n, t, r), f.children;
562
+ throw new Error(`xi:include target not found: ${s} (in ${i})`);
434
563
  }
435
564
  if (e.attributes.parse === "text")
436
- return [{ type: "text", value: u }];
565
+ return [{ type: "text", value: d }];
437
566
  let l;
438
567
  try {
439
- l = E(u);
568
+ l = x(d);
440
569
  } catch (f) {
441
570
  throw new Error(
442
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.)`
@@ -444,48 +573,48 @@ async function de(e, t, n, r) {
444
573
  }
445
574
  r.stack.push(a);
446
575
  try {
447
- await y(l, b(a), { "": "" }, r);
576
+ await y(l, g(a), { "": "" }, r);
448
577
  } finally {
449
578
  r.stack.pop();
450
579
  }
451
- const d = l.children.filter(
580
+ const u = l.children.filter(
452
581
  (f) => f.type === "element"
453
582
  );
454
- for (const f of d)
455
- tt(f, a);
456
- return d;
583
+ for (const f of u)
584
+ ut(f, a);
585
+ return u;
457
586
  }
458
- function J(e) {
587
+ function K(e) {
459
588
  return e.name === "docinfo";
460
589
  }
461
- async function nt(e, t, n) {
590
+ async function ft(e, n, t) {
462
591
  try {
463
- const i = E(e).children.find(
592
+ const i = x(e).children.find(
464
593
  (l) => l.type === "element"
465
594
  );
466
595
  if (!i)
467
596
  return;
468
- const o = h(t), s = b(o), a = {
469
- projectDir: h(n),
470
- stack: [o]
471
- }, u = _({ "": "" }, i);
597
+ const s = p(n), o = g(s), a = {
598
+ projectDir: p(t),
599
+ stack: [s]
600
+ }, d = _({ "": "" }, i);
472
601
  for (const l of i.children) {
473
602
  if (l.type !== "element")
474
603
  continue;
475
- const d = _(u, l);
476
- if (J(l))
477
- return await y(l, s, d, a), $(l);
478
- if (ue(l, d)) {
479
- const p = (await de(
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(
480
609
  l,
481
- s,
482
- d,
610
+ o,
611
+ u,
483
612
  a
484
613
  )).find(
485
- (m) => m.type === "element" && J(m)
614
+ (m) => m.type === "element" && K(m)
486
615
  );
487
- if (p)
488
- return $(p);
616
+ if (h)
617
+ return $(h);
489
618
  continue;
490
619
  }
491
620
  break;
@@ -495,78 +624,78 @@ async function nt(e, t, n) {
495
624
  return;
496
625
  }
497
626
  }
498
- function rt(e, t) {
499
- for (const n of e.children) {
500
- if (n.type !== "element")
627
+ function pt(e, n) {
628
+ for (const t of e.children) {
629
+ if (t.type !== "element")
501
630
  continue;
502
- const r = _(t, n), i = n.name.indexOf(":"), o = i === -1 ? "" : n.name.slice(0, i);
503
- if ((i === -1 ? n.name : n.name.slice(i + 1)) === "fallback" && r[o] === ce)
504
- return n;
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)
633
+ return t;
505
634
  }
506
635
  }
507
- function fe(e) {
636
+ function pe(e) {
508
637
  return typeof e == "object" && e !== null && e.type === "element";
509
638
  }
510
- function it(e) {
639
+ function ht(e) {
511
640
  return /^(pf|xhtml):/.test(e.name);
512
641
  }
513
- function ot(e, t, n) {
514
- const r = [], i = e.children.find(fe);
642
+ function mt(e, n, t) {
643
+ const r = [], i = e.children.find(pe);
515
644
  if (i) {
516
- const o = n?.parentId ?? "root";
517
- he(i, o, n?.position ?? 1, t, o, r);
645
+ const s = t?.parentId ?? "root";
646
+ he(i, s, t?.position ?? 1, n, s, r);
518
647
  }
519
648
  return r;
520
649
  }
521
- function he(e, t, n, r, i, o) {
522
- const s = et(e) ?? r;
523
- let a, u;
524
- if (it(e))
525
- u = "root";
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";
526
655
  else {
527
- const d = e.attributes.label ?? e.attributes["xml:id"];
528
- a = d ?? `${t}-${n}`, o.push({
656
+ const u = e.attributes.label ?? e.attributes["xml:id"];
657
+ a = u ?? `${n}-${t}`, s.push({
529
658
  id: a,
530
- file: s,
659
+ file: o,
531
660
  line: e.position?.start.line ?? 1,
532
661
  column: e.position?.start.column ?? 1,
533
662
  endLine: e.position?.end.line ?? e.position?.start.line ?? 1,
534
663
  parent: i
535
- }), u = a;
664
+ }), d = a;
536
665
  }
537
666
  let l = 0;
538
- for (const d of e.children)
539
- fe(d) && (l += 1, he(
540
- d,
667
+ for (const u of e.children)
668
+ pe(u) && (l += 1, he(
541
669
  u,
670
+ d,
542
671
  l,
543
- s,
672
+ o,
544
673
  a ?? i,
545
- o
674
+ s
546
675
  ));
547
676
  }
548
- function It(e, t) {
549
- let n;
677
+ function Ot(e, n) {
678
+ let t;
550
679
  for (const r of e)
551
- r.line <= t && (n = r);
552
- return n ?? e[0];
680
+ r.line <= n && (t = r);
681
+ return t ?? e[0];
553
682
  }
554
- function st(e) {
555
- const t = e.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!\[CDATA\[[\s\S]*?\]\]>/g, " ");
556
- return /<\s*slide(?:show)?[\s/>]/.test(t) ? "slides" : "html";
683
+ function wt(e) {
684
+ const n = e.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!\[CDATA\[[\s\S]*?\]\]>/g, " ");
685
+ return /<\s*slide(?:show)?[\s/>]/.test(n) ? "slides" : "html";
557
686
  }
558
- const pe = "pretext-html:set-theme";
559
- function Rt(e) {
687
+ const me = "pretext-html:set-theme";
688
+ function Wt(e) {
560
689
  return e === "dark" || e === "light" || e === "system";
561
690
  }
562
- function Mt(e) {
563
- return { type: pe, theme: e };
691
+ function Ft(e) {
692
+ return { type: me, theme: e };
564
693
  }
565
- function at(e) {
694
+ function vt(e) {
566
695
  return [
567
696
  "<script>",
568
697
  "(function () {",
569
- " var CFG = " + JSON.stringify({ msg: pe, initial: e }) + ";",
698
+ " var CFG = " + JSON.stringify({ msg: me, initial: e }) + ";",
570
699
  // Where the last requested theme is remembered so it survives an in-place
571
700
  // document rewrite (same Window) and outranks the baked initial value.
572
701
  " var KEY = '__ptxPreviewTheme';",
@@ -636,181 +765,181 @@ function at(e) {
636
765
  ].join(`
637
766
  `);
638
767
  }
639
- function ct(e, t) {
640
- const n = at(t);
768
+ function bt(e, n) {
769
+ const t = vt(n);
641
770
  return /<head[^>]*>/i.test(e) ? e.replace(/<head([^>]*)>/i, `<head$1>
642
- ${n}`) : e;
771
+ ${t}`) : e;
643
772
  }
644
- function lt() {
645
- return ee(S(), "xsl");
773
+ function gt() {
774
+ return te(S(), "xsl");
646
775
  }
647
- function ut() {
776
+ function yt() {
648
777
  return "Suspending" in WebAssembly;
649
778
  }
650
- function dt() {
651
- if (!ut())
779
+ function xt() {
780
+ if (!yt())
652
781
  throw new Error(
653
782
  "WebAssembly JSPI is not enabled. Run Node with --experimental-wasm-jspi (or use the pretext-html CLI, which re-launches itself with the flag)."
654
783
  );
655
784
  }
656
- function G(e) {
657
- return e.includes("'") ? e.includes('"') ? `concat(${e.split("'").map((n) => `'${n}'`).join(`, "'", `)})` : `"${e}"` : `'${e}'`;
785
+ function Y(e) {
786
+ return e.includes("'") ? e.includes('"') ? `concat(${e.split("'").map((t) => `'${t}'`).join(`, "'", `)})` : `"${e}"` : `'${e}'`;
658
787
  }
659
- function ft(e) {
788
+ function Et(e) {
660
789
  return e.replace(
661
790
  /from '\.\/(https:\/\/[^']+)'/g,
662
- (t, n) => `from '${n}'`
791
+ (n, t) => `from '${t}'`
663
792
  );
664
793
  }
665
- const ht = "https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@latest/dist/";
666
- function pt(e) {
794
+ const Tt = "https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@latest/dist/";
795
+ function $t(e) {
667
796
  return e.replace(
668
797
  /(<link\b[^>]*\bhref=["'])_static\//gi,
669
- `$1${ht}_static/`
798
+ `$1${Tt}_static/`
670
799
  );
671
800
  }
672
- function mt(e) {
801
+ function St(e) {
673
802
  return e.slice(0, 65536).replace(/<\?[\s\S]*?\?>/g, " ").replace(/<!--[\s\S]*?-->/g, " ").replace(/<!DOCTYPE[^>]*>/gi, " ").match(/<\s*([A-Za-z][\w:-]*)/)?.[1];
674
803
  }
675
- async function K(e) {
676
- const t = await P(e);
677
- if (t === void 0)
804
+ async function G(e) {
805
+ const n = await B(e);
806
+ if (n === void 0)
678
807
  throw new Error(
679
808
  `Could not read ${e}. (In the browser build only absolute URLs are readable — pass sourceContent instead of relying on sourcePath.)`
680
809
  );
681
- return t;
810
+ return n;
682
811
  }
683
- async function wt(e, t) {
684
- const n = h(e), r = await P(n);
812
+ async function _t(e, n) {
813
+ const t = p(e), r = await B(t);
685
814
  if (r !== void 0)
686
- return nt(r, n, t);
815
+ return ft(r, t, n);
687
816
  }
688
- function gt(e, t, n, r) {
689
- const i = e.replace(/^\uFEFF/, "").replace(/<\?xml[\s\S]*?\?>/, "").replace(/<!DOCTYPE[^>]*>/i, ""), o = n === "slides" ? "slideshow" : t === "chapter" || t === "part" ? "book" : "article";
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";
690
819
  return `<pretext>
691
820
  ${r?.trim() ? `${r.trim()}
692
- ` : ""}<${o}>
821
+ ` : ""}<${s}>
693
822
  <title/>
694
823
  ${i}
695
- </${o}>
824
+ </${s}>
696
825
  </pretext>
697
826
  `;
698
827
  }
699
- let me = !1;
700
- function vt(e) {
828
+ let we = !1;
829
+ function It(e) {
701
830
  return e instanceof Error && /\bAborted\(/.test(e.message);
702
831
  }
703
- function bt(e) {
832
+ function Dt(e) {
704
833
  return e instanceof Error && /memory access|out of bounds/i.test(e.message);
705
834
  }
706
- function yt() {
707
- if (me)
835
+ function Rt() {
836
+ if (we)
708
837
  throw new Error(
709
838
  "The WebAssembly renderer aborted earlier in this process and cannot be reused. Restart the process (or reload the page) to render again."
710
839
  );
711
840
  }
712
- function Y(e) {
713
- if (vt(e))
714
- throw me = !0, new Error(
841
+ function q(e) {
842
+ if (It(e))
843
+ throw we = !0, new Error(
715
844
  "The WebAssembly renderer aborted and cannot be reused. Restart the process (or reload the page) to render again.",
716
845
  { cause: e }
717
846
  );
718
- if (bt(e))
847
+ if (Dt(e))
719
848
  throw new Error(
720
849
  "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.",
721
850
  { cause: e }
722
851
  );
723
852
  }
724
- let R;
725
- async function we() {
726
- return R || (R = (async () => {
727
- const [e, t] = await Promise.all([
853
+ let D;
854
+ async function ve() {
855
+ return D || (D = (async () => {
856
+ const [e, n] = await Promise.all([
728
857
  import("@pretextbook/libxslt-wasm"),
729
858
  import("@pretextbook/libxslt-wasm/exslt")
730
859
  ]);
731
- return t.registerAll(), e;
732
- })()), R;
860
+ return n.registerAll(), e;
861
+ })()), D;
733
862
  }
734
- const M = /* @__PURE__ */ new Map(), Et = {
863
+ const R = /* @__PURE__ */ new Map(), Mt = {
735
864
  html: "preview-html.xsl",
736
865
  slides: "preview-revealjs.xsl"
737
866
  };
738
- async function xt(e, t) {
739
- const n = Et[t], r = `${t}\0${e}`;
740
- let i = M.get(r);
867
+ async function Lt(e, n) {
868
+ const t = Mt[n], r = `${n}\0${e}`;
869
+ let i = R.get(r);
741
870
  return i || (i = (async () => {
742
- const { XmlDocument: o, XsltStylesheet: s } = await we(), a = oe(e), u = await te(S(), `/${n}`);
743
- if (u === void 0)
871
+ const { XmlDocument: s, XsltStylesheet: o } = await ve(), a = oe(e), d = await ne(S(), `/${t}`);
872
+ if (d === void 0)
744
873
  throw new Error(
745
- `Could not read ${n} from ${S()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
874
+ `Could not read ${t} from ${S()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
746
875
  );
747
- const l = new TextDecoder().decode(u), d = await o.fromString(l, {
748
- url: `${a}/${n}`,
876
+ const l = new TextDecoder().decode(d), u = await s.fromString(l, {
877
+ url: `${a}/${t}`,
749
878
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
750
879
  });
751
- return s.fromXmlDocument(d);
752
- })(), M.set(r, i), i.catch(() => M.delete(r))), i;
753
- }
754
- let q = Promise.resolve();
755
- function Dt(e) {
756
- const t = q.then(
757
- () => Z(e),
758
- () => Z(e)
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)
759
888
  );
760
- return q = t.catch(() => {
761
- }), t;
762
- }
763
- async function Z(e) {
764
- dt(), yt();
765
- const { XmlDocument: t } = await we(), n = h(e.sourcePath), r = h(
766
- e.projectDir ?? b(n)
767
- ), i = e.sourceContent ?? await K(n), o = I(r, n);
768
- if (o.startsWith(".."))
889
+ return Z = n.catch(() => {
890
+ }), n;
891
+ }
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(".."))
769
898
  throw new Error(
770
- `sourcePath (${n}) must live inside projectDir (${r})`
899
+ `sourcePath (${t}) must live inside projectDir (${r})`
771
900
  );
772
- const s = I(
901
+ const o = I(
773
902
  r,
774
- h(e.mainSourcePath ?? n)
775
- ), a = s.startsWith("..") ? o : s, u = oe(r);
903
+ p(e.mainSourcePath ?? t)
904
+ ), a = o.startsWith("..") ? s : o, d = oe(r);
776
905
  try {
777
- let l, d = `${u}/__pretext-preview-publication.xml`;
906
+ let l, u = `${d}/__pretext-preview-publication.xml`;
778
907
  if (e.publicationPath) {
779
- const c = h(e.publicationPath);
780
- l = await K(c);
781
- const v = I(r, c);
782
- v.startsWith("..") || (d = `${u}/${v.split(D).join("/")}`);
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("/")}`);
783
912
  }
784
- let f, p;
913
+ let f, h;
785
914
  if (e.sourceMap) {
786
- const c = await le(
915
+ const c = await de(
787
916
  i,
788
- n,
917
+ t,
789
918
  r
790
919
  );
791
- f = c.tree, p = c.content;
920
+ f = c.tree, h = c.content;
792
921
  } else
793
- p = await Qe(
922
+ h = await lt(
794
923
  i,
795
- n,
924
+ t,
796
925
  r
797
926
  );
798
- const m = e.target ?? st(p), ge = await xt(e.xslDir ?? lt(), m), j = Oe(l, {
927
+ const m = e.target ?? wt(h), be = await Lt(e.xslDir ?? gt(), m), P = Ke(l, {
799
928
  cssTheme: e.cssTheme,
800
929
  revealTheme: e.revealTheme,
801
930
  target: m
802
931
  });
803
- Ae(d, j);
804
- const x = We(j), F = b(h(r, a)), O = x.external !== void 0 && x.generated !== void 0 ? {
805
- external: h(F, x.external),
806
- generated: h(F, x.generated)
807
- } : void 0, T = mt(p);
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);
808
937
  let W = { parentId: "root", position: 1 };
809
938
  if (T !== "pretext" && T !== "mathbook")
810
939
  if (e.fragment) {
811
- const c = e.docinfo ?? (e.docinfoSourcePath ? await wt(e.docinfoSourcePath, r) : void 0);
812
- p = gt(
813
- p,
940
+ const c = e.docinfo ?? (e.docinfoSourcePath ? await _t(e.docinfoSourcePath, r) : void 0);
941
+ h = kt(
942
+ h,
814
943
  T,
815
944
  m,
816
945
  c
@@ -819,61 +948,64 @@ async function Z(e) {
819
948
  throw new Error(
820
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.`
821
950
  );
822
- const B = f ? ot(f, n, W) : void 0, X = await t.fromString(p, {
823
- url: `${u}/${a.split(D).join("/")}`,
951
+ const F = f ? mt(f, t, W) : void 0, N = await n.fromString(h, {
952
+ url: `${d}/${a.split(M).join("/")}`,
824
953
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
825
954
  }), H = {
826
- publisher: G(d)
955
+ publisher: Y(u)
827
956
  };
828
- for (const [c, v] of Object.entries(e.stringParams ?? {}))
829
- H[c] = G(v);
957
+ for (const [c, b] of Object.entries(e.stringParams ?? {}))
958
+ H[c] = Y(b);
830
959
  let k;
831
960
  try {
832
- k = await ge.apply(X, H);
961
+ k = await be.apply(N, H);
833
962
  } catch (c) {
834
- throw Y(c), new Error(
963
+ throw q(c), new Error(
835
964
  "PreTeXt XSLT transform failed; see the PTX:ERROR/PTX:FATAL messages on stderr for details.",
836
965
  { cause: c }
837
966
  );
838
967
  } finally {
839
- X.delete();
968
+ N.delete();
840
969
  }
841
970
  try {
842
- let c = ft(k.toHtmlString());
843
- return (e.openKnowls ?? !0) && (c = ke(c)), m === "slides" ? (c = pt(c), c = Ze(c, e.revealView ?? "scroll", {
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", {
844
973
  zoom: e.revealZoom
845
- })) : e.theme && (c = ct(c, e.theme)), {
974
+ })) : e.theme && (c = bt(c, e.theme)), e.previewBanner && (c = Ie(c, e.previewBanner)), {
846
975
  html: c,
847
976
  target: m,
848
- ...B ? { sourceMap: B } : {},
977
+ ...F ? { sourceMap: F } : {},
849
978
  ...O ? { assetDirs: O } : {}
850
979
  };
851
980
  } catch (c) {
852
- throw Y(c), c;
981
+ throw q(c), c;
853
982
  } finally {
854
983
  k.delete();
855
984
  }
856
985
  } finally {
857
- Le(u);
986
+ He(d);
858
987
  }
859
988
  }
860
989
  export {
861
- pe as PREVIEW_THEME_MESSAGE,
862
- lt as defaultXslDir,
863
- st as detectRenderTarget,
864
- It as findSourceMapEntry,
865
- Oe as forcePortablePublication,
866
- Ze as injectRevealBridge,
867
- ct as injectThemeBridge,
868
- ut as isJspiAvailable,
869
- Rt as isPreviewTheme,
870
- kt as isRevealView,
871
- ke as openBornHiddenKnowls,
872
- Mt as previewThemeMessage,
873
- Dt as renderHtml,
874
- Je as revealBridgeScript,
875
- St as setAssetsBase,
876
- _t as setMountReader,
877
- at as themeBridgeScript,
878
- G as xpathStringLiteral
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
879
1011
  };