@pretextbook/pretext-html 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,95 +1,95 @@
1
1
  import { fromXml as E } from "xast-util-from-xml";
2
- import { toXml as S } from "xast-util-to-xml";
2
+ import { toXml as $ } from "xast-util-to-xml";
3
3
  const D = "/";
4
- function ge(e) {
4
+ function ve(e) {
5
5
  if (!e)
6
6
  return ".";
7
- const n = e.startsWith("/"), t = e.length > 1 && e.endsWith("/"), r = [];
7
+ const t = e.startsWith("/"), n = e.length > 1 && e.endsWith("/"), r = [];
8
8
  for (const o of e.split("/"))
9
9
  if (!(!o || o === ".")) {
10
10
  if (o === "..") {
11
11
  const s = r[r.length - 1];
12
- r.length > 0 && s !== ".." ? r.pop() : n || r.push("..");
12
+ r.length > 0 && s !== ".." ? r.pop() : t || r.push("..");
13
13
  continue;
14
14
  }
15
15
  r.push(o);
16
16
  }
17
17
  let i = r.join("/");
18
- return n && (i = `/${i}`), i ? (t && !i.endsWith("/") && (i += "/"), i) : n ? "/" : ".";
18
+ return t && (i = `/${i}`), i ? (n && !i.endsWith("/") && (i += "/"), i) : t ? "/" : ".";
19
19
  }
20
20
  function h(...e) {
21
- let n = "";
21
+ let t = "";
22
22
  for (let r = e.length - 1; r >= 0; r--) {
23
23
  const i = e[r];
24
- if (i && (n = n ? `${i}/${n}` : i, i.startsWith("/")))
24
+ if (i && (t = t ? `${i}/${t}` : i, i.startsWith("/")))
25
25
  break;
26
26
  }
27
- n.startsWith("/") || (n = `/${n}`);
28
- const t = ge(n);
29
- return t.length > 1 && t.endsWith("/") ? t.slice(0, -1) : t;
27
+ t.startsWith("/") || (t = `/${t}`);
28
+ const n = ve(t);
29
+ return n.length > 1 && n.endsWith("/") ? n.slice(0, -1) : n;
30
30
  }
31
31
  function b(e) {
32
- const n = e.replace(/\/+$/, "");
33
- if (!n)
32
+ const t = e.replace(/\/+$/, "");
33
+ if (!t)
34
34
  return e.startsWith("/") ? "/" : ".";
35
- const t = n.lastIndexOf("/");
36
- return t < 0 ? "." : t === 0 ? "/" : n.slice(0, t);
35
+ const n = t.lastIndexOf("/");
36
+ return n < 0 ? "." : n === 0 ? "/" : t.slice(0, n);
37
37
  }
38
- function k(e, n) {
39
- const t = h(e).split("/").filter(Boolean), r = h(n).split("/").filter(Boolean);
38
+ function I(e, t) {
39
+ const n = h(e).split("/").filter(Boolean), r = h(t).split("/").filter(Boolean);
40
40
  let i = 0;
41
- for (; i < t.length && i < r.length && t[i] === r[i]; )
41
+ for (; i < n.length && i < r.length && n[i] === r[i]; )
42
42
  i += 1;
43
- return [...new Array(t.length - i).fill(".."), ...r.slice(i)].join("/");
43
+ return [...new Array(n.length - i).fill(".."), ...r.slice(i)].join("/");
44
44
  }
45
- const ve = "https://cdn.jsdelivr.net/npm/@pretextbook/pretext-html@0.5.0/assets";
46
- let Z;
47
- function bt(e) {
48
- Z = e.replace(/\/+$/, "");
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(/\/+$/, "");
49
49
  }
50
- function $() {
51
- return Z ?? ve;
50
+ function S() {
51
+ return Q ?? be;
52
52
  }
53
- function Q(e, n) {
54
- return `${e.replace(/\/+$/, "")}/${n.replace(/^\/+/, "")}`;
53
+ function ee(e, t) {
54
+ return `${e.replace(/\/+$/, "")}/${t.replace(/^\/+/, "")}`;
55
55
  }
56
56
  const U = /* @__PURE__ */ new Map();
57
- function be(e) {
57
+ function ye(e) {
58
58
  return `${e.replace(/\/+$/, "")}-bundle.json`;
59
59
  }
60
- function ye(e) {
61
- let n = U.get(e);
62
- return n || (n = (async () => {
60
+ function Ee(e) {
61
+ let t = U.get(e);
62
+ return t || (t = (async () => {
63
63
  try {
64
- const t = await fetch(be(e));
65
- if (!t.ok)
64
+ const n = await fetch(ye(e));
65
+ if (!n.ok)
66
66
  return /* @__PURE__ */ new Map();
67
- const r = await t.json();
67
+ const r = await n.json();
68
68
  return new Map(Object.entries(r));
69
69
  } catch {
70
70
  return /* @__PURE__ */ new Map();
71
71
  }
72
- })(), U.set(e, n)), n;
72
+ })(), U.set(e, t)), t;
73
73
  }
74
- function Ee(e) {
75
- return e === Q($(), "xsl");
74
+ function xe(e) {
75
+ return e === ee(S(), "xsl");
76
76
  }
77
- async function ee(e, n) {
78
- if (Ee(e)) {
79
- const o = (await ye(e)).get(n.replace(/^\/+/, ""));
77
+ async function te(e, t) {
78
+ if (xe(e)) {
79
+ const o = (await Ee(e)).get(t.replace(/^\/+/, ""));
80
80
  if (o !== void 0)
81
81
  return new TextEncoder().encode(o);
82
82
  }
83
- const t = `${e.replace(/\/+$/, "")}/`;
83
+ const n = `${e.replace(/\/+$/, "")}/`;
84
84
  let r;
85
85
  try {
86
- r = new URL(n.replace(/^\/+/, ""), t);
86
+ r = new URL(t.replace(/^\/+/, ""), n);
87
87
  } catch {
88
88
  return;
89
89
  }
90
- if (!r.href.startsWith(t)) {
90
+ if (!r.href.startsWith(n)) {
91
91
  console.error(
92
- `pretext-html: refusing to serve ${n} from outside ${e}`
92
+ `pretext-html: refusing to serve ${t} from outside ${e}`
93
93
  );
94
94
  return;
95
95
  }
@@ -103,51 +103,73 @@ async function ee(e, n) {
103
103
  async function P(e) {
104
104
  if (/^[a-z][a-z0-9+.-]*:\/\//i.test(e))
105
105
  try {
106
- const n = await fetch(e);
107
- return n.ok ? await n.text() : void 0;
106
+ const t = await fetch(e);
107
+ return t.ok ? await t.text() : void 0;
108
108
  } catch {
109
109
  return;
110
110
  }
111
111
  }
112
- const C = /* @__PURE__ */ new Map(), te = /* @__PURE__ */ new Map();
113
- let L, xe = 0, ne = ee;
114
- function yt(e) {
115
- ne = e;
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+/) : [];
116
+ }
117
+ function _e(e) {
118
+ return /(^|\s)open(\s|=|$)/.test(e);
116
119
  }
117
- function Te(e, n) {
118
- const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, r = te.get(t);
120
+ function N(e) {
121
+ return _e(e) ? e : ` open${e}`;
122
+ }
123
+ function ke(e) {
124
+ 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)}>`;
131
+ }
132
+ );
133
+ }
134
+ const C = /* @__PURE__ */ new Map(), ne = /* @__PURE__ */ new Map();
135
+ let L, Ie = 0, re = te;
136
+ function _t(e) {
137
+ re = e;
138
+ }
139
+ function Re(e, t) {
140
+ const n = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, r = ne.get(n);
119
141
  if (r !== void 0)
120
142
  return Promise.resolve(new Response(r, { status: 200 }));
121
143
  let i;
122
144
  try {
123
- i = new URL(t).host;
145
+ i = new URL(n).host;
124
146
  } catch {
125
147
  i = "";
126
148
  }
127
149
  const o = C.get(i);
128
- return o !== void 0 ? $e(o, t) : L(e, n);
150
+ return o !== void 0 ? De(o, n) : L(e, t);
129
151
  }
130
- const Se = '<?xml version="1.0"?><pretext-preview-missing-file/>';
131
- async function $e(e, n) {
132
- const t = decodeURIComponent(new URL(n).pathname), r = await ne(e, t);
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);
133
155
  if (r === void 0)
134
- return new Response(Se, { status: 200 });
156
+ return new Response(Me, { status: 200 });
135
157
  const i = typeof r == "string" ? r : new Uint8Array(r);
136
158
  return new Response(i, { status: 200 });
137
159
  }
138
- function re() {
139
- L || (L = globalThis.fetch, globalThis.fetch = Te);
160
+ function ie() {
161
+ L || (L = globalThis.fetch, globalThis.fetch = Re);
140
162
  }
141
- function ie(e) {
142
- re();
143
- const n = `mnt${++xe}.ptx.invalid`;
144
- return C.set(n, e), `http://${n}`;
163
+ function oe(e) {
164
+ ie();
165
+ const t = `mnt${++Ie}.ptx.invalid`;
166
+ return C.set(t, e), `http://${t}`;
145
167
  }
146
- function _e(e) {
168
+ function Le(e) {
147
169
  C.delete(new URL(e).host);
148
170
  }
149
- function Re(e, n) {
150
- re(), te.set(e, n);
171
+ function Ae(e, t) {
172
+ ie(), ne.set(e, t);
151
173
  }
152
174
  const A = `<?xml version="1.0" encoding="UTF-8"?>
153
175
  <publication>
@@ -158,41 +180,41 @@ const A = `<?xml version="1.0" encoding="UTF-8"?>
158
180
  <platform portable="yes"/>
159
181
  </html>
160
182
  </publication>
161
- `, ke = ["theme", "style", "shell"];
162
- function w(e, n) {
163
- for (const t of e.children)
164
- if (t.type === "element" && t.name === n)
165
- return t;
166
- }
167
- function g(e, n) {
168
- let t = w(e, n);
169
- return t || (t = { type: "element", name: n, attributes: {}, children: [] }, e.children.push(t)), t;
170
- }
171
- function Ie(e, n) {
172
- const t = w(e, "css");
173
- if (t && ke.some((i) => t.attributes?.[i]))
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]))
174
196
  return;
175
- const r = t ?? g(e, "css");
176
- r.attributes = { ...r.attributes, theme: n };
197
+ const r = n ?? g(e, "css");
198
+ r.attributes = { ...r.attributes, theme: t };
177
199
  }
178
- function Me(e, n) {
179
- const t = w(e, "appearance");
180
- if (t?.attributes?.theme)
200
+ function je(e, t) {
201
+ const n = w(e, "appearance");
202
+ if (n?.attributes?.theme)
181
203
  return;
182
- const r = t ?? g(e, "appearance");
183
- r.attributes = { ...r.attributes, theme: n };
204
+ const r = n ?? g(e, "appearance");
205
+ r.attributes = { ...r.attributes, theme: t };
184
206
  }
185
- function De(e) {
186
- const n = g(e, "resources");
187
- n.attributes = {
188
- ...n.attributes,
207
+ function Fe(e) {
208
+ const t = g(e, "resources");
209
+ t.attributes = {
210
+ ...t.attributes,
189
211
  host: "cdn",
190
212
  math: "online"
191
213
  };
192
214
  }
193
- function Le(e, n = {}) {
194
- const t = n.cssTheme?.trim(), r = n.revealTheme?.trim(), i = n.target === "slides";
195
- if (!e && !t && !i)
215
+ function Oe(e, t = {}) {
216
+ const n = t.cssTheme?.trim(), r = t.revealTheme?.trim(), i = t.target === "slides";
217
+ if (!e && !n && !i)
196
218
  return A;
197
219
  const o = E(e ?? A), s = w(o, "publication");
198
220
  if (!s)
@@ -200,18 +222,18 @@ function Le(e, n = {}) {
200
222
  "Invalid publication file: no root <publication> element found"
201
223
  );
202
224
  const a = g(s, "html"), u = g(a, "platform");
203
- if (u.attributes = { ...u.attributes, portable: "yes" }, t && Ie(a, t), i) {
204
- const c = g(s, "revealjs");
205
- De(c), r && Me(c, r);
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);
206
228
  }
207
- return S(o);
229
+ return $(o);
208
230
  }
209
231
  function V(e) {
210
232
  if (!(e === void 0 || e === "" || e.startsWith("/")))
211
233
  return e.endsWith("/") ? e : `${e}/`;
212
234
  }
213
- function Ae(e) {
214
- const n = E(e ?? A), t = w(n, "publication"), r = t && w(t, "source"), i = r && w(r, "directories"), o = V(
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(
215
237
  i?.attributes?.external ?? void 0
216
238
  ), s = V(
217
239
  i?.attributes?.generated ?? void 0
@@ -222,18 +244,18 @@ function Ae(e) {
222
244
  managed: o !== void 0 && s !== void 0
223
245
  };
224
246
  }
225
- function Et(e) {
247
+ function kt(e) {
226
248
  return e === "slides" || e === "scroll";
227
249
  }
228
- const oe = 960, se = 700, Pe = 1, Ce = 0.04;
229
- function je(e) {
230
- const n = typeof e == "number" && isFinite(e) ? e : Pe, t = Math.min(1, Math.max(0.25, n));
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));
231
253
  return {
232
- width: Math.round(oe / t),
233
- height: Math.round(se / t)
254
+ width: Math.round(se / n),
255
+ height: Math.round(ae / n)
234
256
  };
235
257
  }
236
- function Fe(e) {
258
+ function Ue(e) {
237
259
  return {
238
260
  view: "scroll",
239
261
  scrollLayout: "compact",
@@ -243,11 +265,11 @@ function Fe(e) {
243
265
  controls: !1,
244
266
  controlsTutorial: !1,
245
267
  hash: !1,
246
- ...je(e.zoom),
247
- margin: Ce
268
+ ...He(e.zoom),
269
+ margin: Xe
248
270
  };
249
271
  }
250
- function We() {
272
+ function Ne() {
251
273
  return {
252
274
  // Explicitly null rather than absent: the same page may have been
253
275
  // delivered in scroll view a moment ago, and an embedder that re-injects
@@ -259,11 +281,11 @@ function We() {
259
281
  // size with a percentage width renders its text far larger, relative to
260
282
  // the slide, than the same deck will on a projector. No zoom margin
261
283
  // though — presenting means filling whatever it is shown in.
262
- width: oe,
263
- height: se
284
+ width: se,
285
+ height: ae
264
286
  };
265
287
  }
266
- const Be = [
288
+ const Ve = [
267
289
  "<style>",
268
290
  ".reveal-viewport.reveal-scroll .scroll-page section {",
269
291
  " box-shadow: inset 0 0 0 calc(1px / var(--slide-scale, 1))",
@@ -271,18 +293,18 @@ const Be = [
271
293
  "}",
272
294
  "</style>"
273
295
  ].join(`
274
- `), Oe = [
296
+ `), ze = [
275
297
  " var paused = document.querySelectorAll('.reveal .fragment');",
276
298
  " for (var i = 0; i < paused.length; i++) {",
277
299
  " paused[i].classList.remove('fragment');",
278
300
  " }"
279
301
  ];
280
- function Xe(e, n = {}) {
281
- const t = e === "scroll" ? Fe(n) : We();
302
+ function Je(e, t = {}) {
303
+ const n = e === "scroll" ? Ue(t) : Ne();
282
304
  return [
283
305
  "<script>",
284
306
  "(function () {",
285
- " var OVERRIDES = " + JSON.stringify(t) + ";",
307
+ " var OVERRIDES = " + JSON.stringify(n) + ";",
286
308
  // Nothing to wrap if reveal.js failed to load (offline, CDN blocked). The
287
309
  // deck is broken either way, but throwing here would replace the browser's
288
310
  // useful network error with a confusing one from an injected script.
@@ -306,7 +328,7 @@ function Xe(e, n = {}) {
306
328
  // Inside the wrapper rather than at top level: this script sits in <head>,
307
329
  // where the slides have not been parsed yet, but the deck calls initialize
308
330
  // from the end of the document, by which time they have.
309
- ...e === "scroll" ? Oe : [],
331
+ ...e === "scroll" ? ze : [],
310
332
  " return initialize(merged);",
311
333
  " };",
312
334
  "})();",
@@ -314,71 +336,71 @@ function Xe(e, n = {}) {
314
336
  ].join(`
315
337
  `);
316
338
  }
317
- const He = /<script\b[^>]*\bsrc=["'][^"']*\breveal\.js["'][^>]*>\s*<\/script>/i, Ue = "<!--ptx-reveal-view-->", Ve = "<!--/ptx-reveal-view-->", Ne = /\n?<!--ptx-reveal-view-->[\s\S]*?<!--\/ptx-reveal-view-->/;
318
- function ze(e, n, t = {}) {
319
- const r = Ne.exec(e), i = r ? e.slice(0, r.index) + e.slice(r.index + r[0].length) : e, o = He.exec(i);
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);
320
342
  if (!o)
321
343
  return i;
322
344
  const s = o.index + o[0].length, a = `
323
- ${Ue}
324
- ${Be}
325
- ${Xe(n, t)}
326
- ${Ve}`;
345
+ ${Ke}
346
+ ${Ve}
347
+ ${Je(t, n)}
348
+ ${Ye}`;
327
349
  return i.slice(0, s) + a + i.slice(s);
328
350
  }
329
- const ae = "http://www.w3.org/2001/XInclude", N = 64;
330
- async function Je(e, n, t) {
331
- return e.includes("include") ? (await ce(e, n, t)).content : e;
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;
332
354
  }
333
- async function ce(e, n, t) {
355
+ async function le(e, t, n) {
334
356
  const r = E(e), i = {
335
- projectDir: h(t),
336
- stack: [h(n)]
357
+ projectDir: h(n),
358
+ stack: [h(t)]
337
359
  }, o = await y(
338
360
  r,
339
- b(h(n)),
361
+ b(h(t)),
340
362
  { "": "" },
341
363
  i
342
364
  );
343
- return { tree: r, content: o ? S(r) : e };
365
+ return { tree: r, content: o ? $(r) : e };
344
366
  }
345
- function Ge(e) {
367
+ function et(e) {
346
368
  return e.data?.ptxIncludedFile;
347
369
  }
348
- function Ye(e, n) {
349
- const t = e.data ?? (e.data = {});
350
- t.ptxIncludedFile = n;
370
+ function tt(e, t) {
371
+ const n = e.data ?? (e.data = {});
372
+ n.ptxIncludedFile = t;
351
373
  }
352
- function _(e, n) {
353
- let t = e;
354
- for (const [r, i] of Object.entries(n.attributes))
355
- (r === "xmlns" || r.startsWith("xmlns:")) && (t === e && (t = { ...e }), t[r === "xmlns" ? "" : r.slice(6)] = i ?? "");
356
- return t;
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;
357
379
  }
358
- function le(e, n) {
359
- const t = e.name.indexOf(":"), r = t === -1 ? "" : e.name.slice(0, t);
360
- return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && n[r] === ae;
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;
361
383
  }
362
- async function y(e, n, t, r) {
384
+ async function y(e, t, n, r) {
363
385
  let i = !1;
364
386
  for (let o = 0; o < e.children.length; o++) {
365
387
  const s = e.children[o];
366
388
  if (s.type !== "element")
367
389
  continue;
368
- const a = _(t, s);
369
- if (le(s, a)) {
370
- const u = await ue(
390
+ const a = _(n, s);
391
+ if (ue(s, a)) {
392
+ const u = await de(
371
393
  s,
372
- n,
394
+ t,
373
395
  a,
374
396
  r
375
397
  );
376
398
  e.children.splice(o, 1, ...u), o += u.length - 1, i = !0;
377
- } else await y(s, n, a, r) && (i = !0);
399
+ } else await y(s, t, a, r) && (i = !0);
378
400
  }
379
401
  return i;
380
402
  }
381
- async function ue(e, n, t, r) {
403
+ async function de(e, t, n, r) {
382
404
  const i = r.stack[r.stack.length - 1];
383
405
  if (e.attributes.xpointer)
384
406
  throw new Error(
@@ -392,7 +414,7 @@ async function ue(e, n, t, r) {
392
414
  s = decodeURIComponent(o);
393
415
  } catch {
394
416
  }
395
- const a = h(n, s);
417
+ const a = h(t, s);
396
418
  if (a !== r.projectDir && !a.startsWith(r.projectDir + D))
397
419
  throw new Error(
398
420
  `xi:include escapes the project directory: ${o} (in ${i})`
@@ -401,20 +423,20 @@ async function ue(e, n, t, r) {
401
423
  throw new Error(
402
424
  `Circular xi:include: ${[...r.stack, a].join(" -> ")}`
403
425
  );
404
- if (r.stack.length >= N)
405
- throw new Error(`xi:include nesting exceeds ${N} levels`);
426
+ if (r.stack.length >= z)
427
+ throw new Error(`xi:include nesting exceeds ${z} levels`);
406
428
  const u = await P(a);
407
429
  if (u === void 0) {
408
- const f = qe(e, t);
430
+ const f = rt(e, n);
409
431
  if (f)
410
- return await y(f, n, t, r), f.children;
432
+ return await y(f, t, n, r), f.children;
411
433
  throw new Error(`xi:include target not found: ${o} (in ${i})`);
412
434
  }
413
435
  if (e.attributes.parse === "text")
414
436
  return [{ type: "text", value: u }];
415
- let c;
437
+ let l;
416
438
  try {
417
- c = E(u);
439
+ l = E(u);
418
440
  } catch (f) {
419
441
  throw new Error(
420
442
  `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.)`
@@ -422,48 +444,48 @@ async function ue(e, n, t, r) {
422
444
  }
423
445
  r.stack.push(a);
424
446
  try {
425
- await y(c, b(a), { "": "" }, r);
447
+ await y(l, b(a), { "": "" }, r);
426
448
  } finally {
427
449
  r.stack.pop();
428
450
  }
429
- const d = c.children.filter(
451
+ const d = l.children.filter(
430
452
  (f) => f.type === "element"
431
453
  );
432
454
  for (const f of d)
433
- Ye(f, a);
455
+ tt(f, a);
434
456
  return d;
435
457
  }
436
- function z(e) {
458
+ function J(e) {
437
459
  return e.name === "docinfo";
438
460
  }
439
- async function Ke(e, n, t) {
461
+ async function nt(e, t, n) {
440
462
  try {
441
463
  const i = E(e).children.find(
442
- (c) => c.type === "element"
464
+ (l) => l.type === "element"
443
465
  );
444
466
  if (!i)
445
467
  return;
446
- const o = h(n), s = b(o), a = {
447
- projectDir: h(t),
468
+ const o = h(t), s = b(o), a = {
469
+ projectDir: h(n),
448
470
  stack: [o]
449
471
  }, u = _({ "": "" }, i);
450
- for (const c of i.children) {
451
- if (c.type !== "element")
472
+ for (const l of i.children) {
473
+ if (l.type !== "element")
452
474
  continue;
453
- const d = _(u, c);
454
- if (z(c))
455
- return await y(c, s, d, a), S(c);
456
- if (le(c, d)) {
457
- const p = (await ue(
458
- c,
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(
480
+ l,
459
481
  s,
460
482
  d,
461
483
  a
462
484
  )).find(
463
- (m) => m.type === "element" && z(m)
485
+ (m) => m.type === "element" && J(m)
464
486
  );
465
487
  if (p)
466
- return S(p);
488
+ return $(p);
467
489
  continue;
468
490
  }
469
491
  break;
@@ -473,37 +495,37 @@ async function Ke(e, n, t) {
473
495
  return;
474
496
  }
475
497
  }
476
- function qe(e, n) {
477
- for (const t of e.children) {
478
- if (t.type !== "element")
498
+ function rt(e, t) {
499
+ for (const n of e.children) {
500
+ if (n.type !== "element")
479
501
  continue;
480
- const r = _(n, t), i = t.name.indexOf(":"), o = i === -1 ? "" : t.name.slice(0, i);
481
- if ((i === -1 ? t.name : t.name.slice(i + 1)) === "fallback" && r[o] === ae)
482
- return t;
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;
483
505
  }
484
506
  }
485
- function de(e) {
507
+ function fe(e) {
486
508
  return typeof e == "object" && e !== null && e.type === "element";
487
509
  }
488
- function Ze(e) {
510
+ function it(e) {
489
511
  return /^(pf|xhtml):/.test(e.name);
490
512
  }
491
- function Qe(e, n, t) {
492
- const r = [], i = e.children.find(de);
513
+ function ot(e, t, n) {
514
+ const r = [], i = e.children.find(fe);
493
515
  if (i) {
494
- const o = t?.parentId ?? "root";
495
- fe(i, o, t?.position ?? 1, n, o, r);
516
+ const o = n?.parentId ?? "root";
517
+ he(i, o, n?.position ?? 1, t, o, r);
496
518
  }
497
519
  return r;
498
520
  }
499
- function fe(e, n, t, r, i, o) {
500
- const s = Ge(e) ?? r;
521
+ function he(e, t, n, r, i, o) {
522
+ const s = et(e) ?? r;
501
523
  let a, u;
502
- if (Ze(e))
524
+ if (it(e))
503
525
  u = "root";
504
526
  else {
505
527
  const d = e.attributes.label ?? e.attributes["xml:id"];
506
- a = d ?? `${n}-${t}`, o.push({
528
+ a = d ?? `${t}-${n}`, o.push({
507
529
  id: a,
508
530
  file: s,
509
531
  line: e.position?.start.line ?? 1,
@@ -512,39 +534,39 @@ function fe(e, n, t, r, i, o) {
512
534
  parent: i
513
535
  }), u = a;
514
536
  }
515
- let c = 0;
537
+ let l = 0;
516
538
  for (const d of e.children)
517
- de(d) && (c += 1, fe(
539
+ fe(d) && (l += 1, he(
518
540
  d,
519
541
  u,
520
- c,
542
+ l,
521
543
  s,
522
544
  a ?? i,
523
545
  o
524
546
  ));
525
547
  }
526
- function xt(e, n) {
527
- let t;
548
+ function It(e, t) {
549
+ let n;
528
550
  for (const r of e)
529
- r.line <= n && (t = r);
530
- return t ?? e[0];
551
+ r.line <= t && (n = r);
552
+ return n ?? e[0];
531
553
  }
532
- function et(e) {
533
- const n = e.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!\[CDATA\[[\s\S]*?\]\]>/g, " ");
534
- return /<\s*slide(?:show)?[\s/>]/.test(n) ? "slides" : "html";
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";
535
557
  }
536
- const he = "pretext-html:set-theme";
537
- function Tt(e) {
558
+ const pe = "pretext-html:set-theme";
559
+ function Rt(e) {
538
560
  return e === "dark" || e === "light" || e === "system";
539
561
  }
540
- function St(e) {
541
- return { type: he, theme: e };
562
+ function Mt(e) {
563
+ return { type: pe, theme: e };
542
564
  }
543
- function tt(e) {
565
+ function at(e) {
544
566
  return [
545
567
  "<script>",
546
568
  "(function () {",
547
- " var CFG = " + JSON.stringify({ msg: he, initial: e }) + ";",
569
+ " var CFG = " + JSON.stringify({ msg: pe, initial: e }) + ";",
548
570
  // Where the last requested theme is remembered so it survives an in-place
549
571
  // document rewrite (same Window) and outranks the baked initial value.
550
572
  " var KEY = '__ptxPreviewTheme';",
@@ -614,57 +636,57 @@ function tt(e) {
614
636
  ].join(`
615
637
  `);
616
638
  }
617
- function nt(e, n) {
618
- const t = tt(n);
639
+ function ct(e, t) {
640
+ const n = at(t);
619
641
  return /<head[^>]*>/i.test(e) ? e.replace(/<head([^>]*)>/i, `<head$1>
620
- ${t}`) : e;
642
+ ${n}`) : e;
621
643
  }
622
- function rt() {
623
- return Q($(), "xsl");
644
+ function lt() {
645
+ return ee(S(), "xsl");
624
646
  }
625
- function it() {
647
+ function ut() {
626
648
  return "Suspending" in WebAssembly;
627
649
  }
628
- function ot() {
629
- if (!it())
650
+ function dt() {
651
+ if (!ut())
630
652
  throw new Error(
631
653
  "WebAssembly JSPI is not enabled. Run Node with --experimental-wasm-jspi (or use the pretext-html CLI, which re-launches itself with the flag)."
632
654
  );
633
655
  }
634
- function J(e) {
635
- return e.includes("'") ? e.includes('"') ? `concat(${e.split("'").map((t) => `'${t}'`).join(`, "'", `)})` : `"${e}"` : `'${e}'`;
656
+ function G(e) {
657
+ return e.includes("'") ? e.includes('"') ? `concat(${e.split("'").map((n) => `'${n}'`).join(`, "'", `)})` : `"${e}"` : `'${e}'`;
636
658
  }
637
- function st(e) {
659
+ function ft(e) {
638
660
  return e.replace(
639
661
  /from '\.\/(https:\/\/[^']+)'/g,
640
- (n, t) => `from '${t}'`
662
+ (t, n) => `from '${n}'`
641
663
  );
642
664
  }
643
- const at = "https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@latest/dist/";
644
- function ct(e) {
665
+ const ht = "https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@latest/dist/";
666
+ function pt(e) {
645
667
  return e.replace(
646
668
  /(<link\b[^>]*\bhref=["'])_static\//gi,
647
- `$1${at}_static/`
669
+ `$1${ht}_static/`
648
670
  );
649
671
  }
650
- function lt(e) {
672
+ function mt(e) {
651
673
  return e.slice(0, 65536).replace(/<\?[\s\S]*?\?>/g, " ").replace(/<!--[\s\S]*?-->/g, " ").replace(/<!DOCTYPE[^>]*>/gi, " ").match(/<\s*([A-Za-z][\w:-]*)/)?.[1];
652
674
  }
653
- async function G(e) {
654
- const n = await P(e);
655
- if (n === void 0)
675
+ async function K(e) {
676
+ const t = await P(e);
677
+ if (t === void 0)
656
678
  throw new Error(
657
679
  `Could not read ${e}. (In the browser build only absolute URLs are readable — pass sourceContent instead of relying on sourcePath.)`
658
680
  );
659
- return n;
681
+ return t;
660
682
  }
661
- async function ut(e, n) {
662
- const t = h(e), r = await P(t);
683
+ async function wt(e, t) {
684
+ const n = h(e), r = await P(n);
663
685
  if (r !== void 0)
664
- return Ke(r, t, n);
686
+ return nt(r, n, t);
665
687
  }
666
- function dt(e, n, t, r) {
667
- const i = e.replace(/^\uFEFF/, "").replace(/<\?xml[\s\S]*?\?>/, "").replace(/<!DOCTYPE[^>]*>/i, ""), o = t === "slides" ? "slideshow" : n === "chapter" || n === "part" ? "book" : "article";
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";
668
690
  return `<pretext>
669
691
  ${r?.trim() ? `${r.trim()}
670
692
  ` : ""}<${o}>
@@ -674,183 +696,184 @@ ${i}
674
696
  </pretext>
675
697
  `;
676
698
  }
677
- let pe = !1;
678
- function ft(e) {
699
+ let me = !1;
700
+ function vt(e) {
679
701
  return e instanceof Error && /\bAborted\(/.test(e.message);
680
702
  }
681
- function ht(e) {
703
+ function bt(e) {
682
704
  return e instanceof Error && /memory access|out of bounds/i.test(e.message);
683
705
  }
684
- function pt() {
685
- if (pe)
706
+ function yt() {
707
+ if (me)
686
708
  throw new Error(
687
709
  "The WebAssembly renderer aborted earlier in this process and cannot be reused. Restart the process (or reload the page) to render again."
688
710
  );
689
711
  }
690
712
  function Y(e) {
691
- if (ft(e))
692
- throw pe = !0, new Error(
713
+ if (vt(e))
714
+ throw me = !0, new Error(
693
715
  "The WebAssembly renderer aborted and cannot be reused. Restart the process (or reload the page) to render again.",
694
716
  { cause: e }
695
717
  );
696
- if (ht(e))
718
+ if (bt(e))
697
719
  throw new Error(
698
720
  "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.",
699
721
  { cause: e }
700
722
  );
701
723
  }
702
- let I;
703
- async function me() {
704
- return I || (I = (async () => {
705
- const [e, n] = await Promise.all([
724
+ let R;
725
+ async function we() {
726
+ return R || (R = (async () => {
727
+ const [e, t] = await Promise.all([
706
728
  import("@pretextbook/libxslt-wasm"),
707
729
  import("@pretextbook/libxslt-wasm/exslt")
708
730
  ]);
709
- return n.registerAll(), e;
710
- })()), I;
731
+ return t.registerAll(), e;
732
+ })()), R;
711
733
  }
712
- const M = /* @__PURE__ */ new Map(), mt = {
734
+ const M = /* @__PURE__ */ new Map(), Et = {
713
735
  html: "preview-html.xsl",
714
736
  slides: "preview-revealjs.xsl"
715
737
  };
716
- async function wt(e, n) {
717
- const t = mt[n], r = `${n}\0${e}`;
738
+ async function xt(e, t) {
739
+ const n = Et[t], r = `${t}\0${e}`;
718
740
  let i = M.get(r);
719
741
  return i || (i = (async () => {
720
- const { XmlDocument: o, XsltStylesheet: s } = await me(), a = ie(e), u = await ee($(), `/${t}`);
742
+ const { XmlDocument: o, XsltStylesheet: s } = await we(), a = oe(e), u = await te(S(), `/${n}`);
721
743
  if (u === void 0)
722
744
  throw new Error(
723
- `Could not read ${t} from ${$()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
745
+ `Could not read ${n} from ${S()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
724
746
  );
725
- const c = new TextDecoder().decode(u), d = await o.fromString(c, {
726
- url: `${a}/${t}`,
747
+ const l = new TextDecoder().decode(u), d = await o.fromString(l, {
748
+ url: `${a}/${n}`,
727
749
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
728
750
  });
729
751
  return s.fromXmlDocument(d);
730
752
  })(), M.set(r, i), i.catch(() => M.delete(r))), i;
731
753
  }
732
- let K = Promise.resolve();
733
- function $t(e) {
734
- const n = K.then(
735
- () => q(e),
736
- () => q(e)
754
+ let q = Promise.resolve();
755
+ function Dt(e) {
756
+ const t = q.then(
757
+ () => Z(e),
758
+ () => Z(e)
737
759
  );
738
- return K = n.catch(() => {
739
- }), n;
740
- }
741
- async function q(e) {
742
- ot(), pt();
743
- const { XmlDocument: n } = await me(), t = h(e.sourcePath), r = h(
744
- e.projectDir ?? b(t)
745
- ), i = e.sourceContent ?? await G(t), o = k(r, t);
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);
746
768
  if (o.startsWith(".."))
747
769
  throw new Error(
748
- `sourcePath (${t}) must live inside projectDir (${r})`
770
+ `sourcePath (${n}) must live inside projectDir (${r})`
749
771
  );
750
- const s = k(
772
+ const s = I(
751
773
  r,
752
- h(e.mainSourcePath ?? t)
753
- ), a = s.startsWith("..") ? o : s, u = ie(r);
774
+ h(e.mainSourcePath ?? n)
775
+ ), a = s.startsWith("..") ? o : s, u = oe(r);
754
776
  try {
755
- let c, d = `${u}/__pretext-preview-publication.xml`;
777
+ let l, d = `${u}/__pretext-preview-publication.xml`;
756
778
  if (e.publicationPath) {
757
- const l = h(e.publicationPath);
758
- c = await G(l);
759
- const v = k(r, l);
779
+ const c = h(e.publicationPath);
780
+ l = await K(c);
781
+ const v = I(r, c);
760
782
  v.startsWith("..") || (d = `${u}/${v.split(D).join("/")}`);
761
783
  }
762
784
  let f, p;
763
785
  if (e.sourceMap) {
764
- const l = await ce(
786
+ const c = await le(
765
787
  i,
766
- t,
788
+ n,
767
789
  r
768
790
  );
769
- f = l.tree, p = l.content;
791
+ f = c.tree, p = c.content;
770
792
  } else
771
- p = await Je(
793
+ p = await Qe(
772
794
  i,
773
- t,
795
+ n,
774
796
  r
775
797
  );
776
- const m = e.target ?? et(p), we = await wt(e.xslDir ?? rt(), m), j = Le(c, {
798
+ const m = e.target ?? st(p), ge = await xt(e.xslDir ?? lt(), m), j = Oe(l, {
777
799
  cssTheme: e.cssTheme,
778
800
  revealTheme: e.revealTheme,
779
801
  target: m
780
802
  });
781
- Re(d, j);
782
- const x = Ae(j), F = b(h(r, a)), W = x.external !== void 0 && x.generated !== void 0 ? {
803
+ Ae(d, j);
804
+ const x = We(j), F = b(h(r, a)), O = x.external !== void 0 && x.generated !== void 0 ? {
783
805
  external: h(F, x.external),
784
806
  generated: h(F, x.generated)
785
- } : void 0, T = lt(p);
786
- let B = { parentId: "root", position: 1 };
807
+ } : void 0, T = mt(p);
808
+ let W = { parentId: "root", position: 1 };
787
809
  if (T !== "pretext" && T !== "mathbook")
788
810
  if (e.fragment) {
789
- const l = e.docinfo ?? (e.docinfoSourcePath ? await ut(e.docinfoSourcePath, r) : void 0);
790
- p = dt(
811
+ const c = e.docinfo ?? (e.docinfoSourcePath ? await wt(e.docinfoSourcePath, r) : void 0);
812
+ p = gt(
791
813
  p,
792
814
  T,
793
815
  m,
794
- l
795
- ), B = { parentId: l?.trim() ? "root-1-2" : "root-1-1", position: 2 };
816
+ c
817
+ ), W = { parentId: c?.trim() ? "root-1-2" : "root-1-1", position: 2 };
796
818
  } else
797
819
  throw new Error(
798
820
  `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.`
799
821
  );
800
- const O = f ? Qe(f, t, B) : void 0, X = await n.fromString(p, {
822
+ const B = f ? ot(f, n, W) : void 0, X = await t.fromString(p, {
801
823
  url: `${u}/${a.split(D).join("/")}`,
802
824
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
803
825
  }), H = {
804
- publisher: J(d)
826
+ publisher: G(d)
805
827
  };
806
- for (const [l, v] of Object.entries(e.stringParams ?? {}))
807
- H[l] = J(v);
808
- let R;
828
+ for (const [c, v] of Object.entries(e.stringParams ?? {}))
829
+ H[c] = G(v);
830
+ let k;
809
831
  try {
810
- R = await we.apply(X, H);
811
- } catch (l) {
812
- throw Y(l), new Error(
832
+ k = await ge.apply(X, H);
833
+ } catch (c) {
834
+ throw Y(c), new Error(
813
835
  "PreTeXt XSLT transform failed; see the PTX:ERROR/PTX:FATAL messages on stderr for details.",
814
- { cause: l }
836
+ { cause: c }
815
837
  );
816
838
  } finally {
817
839
  X.delete();
818
840
  }
819
841
  try {
820
- let l = st(R.toHtmlString());
821
- return m === "slides" ? (l = ct(l), l = ze(l, e.revealView ?? "scroll", {
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", {
822
844
  zoom: e.revealZoom
823
- })) : e.theme && (l = nt(l, e.theme)), {
824
- html: l,
845
+ })) : e.theme && (c = ct(c, e.theme)), {
846
+ html: c,
825
847
  target: m,
826
- ...O ? { sourceMap: O } : {},
827
- ...W ? { assetDirs: W } : {}
848
+ ...B ? { sourceMap: B } : {},
849
+ ...O ? { assetDirs: O } : {}
828
850
  };
829
- } catch (l) {
830
- throw Y(l), l;
851
+ } catch (c) {
852
+ throw Y(c), c;
831
853
  } finally {
832
- R.delete();
854
+ k.delete();
833
855
  }
834
856
  } finally {
835
- _e(u);
857
+ Le(u);
836
858
  }
837
859
  }
838
860
  export {
839
- he as PREVIEW_THEME_MESSAGE,
840
- rt as defaultXslDir,
841
- et as detectRenderTarget,
842
- xt as findSourceMapEntry,
843
- Le as forcePortablePublication,
844
- ze as injectRevealBridge,
845
- nt as injectThemeBridge,
846
- it as isJspiAvailable,
847
- Tt as isPreviewTheme,
848
- Et as isRevealView,
849
- St as previewThemeMessage,
850
- $t as renderHtml,
851
- Xe as revealBridgeScript,
852
- bt as setAssetsBase,
853
- yt as setMountReader,
854
- tt as themeBridgeScript,
855
- J as xpathStringLiteral
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
856
879
  };