@pretextbook/pretext-html 0.7.0 → 0.8.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,7 +1,7 @@
1
1
  import { fromXml as x } from "xast-util-from-xml";
2
- import { toXml as $ } from "xast-util-to-xml";
3
- const M = "/";
4
- function ge(e) {
2
+ import { toXml as S } from "xast-util-to-xml";
3
+ const A = "/";
4
+ function ye(e) {
5
5
  if (!e)
6
6
  return ".";
7
7
  const n = e.startsWith("/"), t = e.length > 1 && e.endsWith("/"), r = [];
@@ -25,7 +25,7 @@ function p(...e) {
25
25
  break;
26
26
  }
27
27
  n.startsWith("/") || (n = `/${n}`);
28
- const t = ge(n);
28
+ const t = ye(n);
29
29
  return t.length > 1 && t.endsWith("/") ? t.slice(0, -1) : t;
30
30
  }
31
31
  function g(e) {
@@ -35,28 +35,28 @@ function g(e) {
35
35
  const t = n.lastIndexOf("/");
36
36
  return t < 0 ? "." : t === 0 ? "/" : n.slice(0, t);
37
37
  }
38
- function I(e, n) {
38
+ function k(e, n) {
39
39
  const t = p(e).split("/").filter(Boolean), r = p(n).split("/").filter(Boolean);
40
40
  let i = 0;
41
41
  for (; i < t.length && i < r.length && t[i] === r[i]; )
42
42
  i += 1;
43
43
  return [...new Array(t.length - i).fill(".."), ...r.slice(i)].join("/");
44
44
  }
45
- const ye = "ptxPreviewBannerDismissed", xe = "About live preview";
45
+ const xe = "ptxPreviewBannerDismissed", Ee = "About live preview";
46
46
  function X(e) {
47
47
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
48
48
  }
49
- function Ee(e) {
49
+ function Te(e) {
50
50
  return [
51
51
  '<div id="ptx-preview-banner" class="ptx-preview-banner" role="note">',
52
52
  ` <span class="ptx-preview-banner-text">${X(e)}</span>`,
53
53
  ' <button type="button" class="ptx-preview-banner-dismiss" aria-label="Dismiss">&times;</button>',
54
54
  "</div>",
55
- `<button type="button" id="ptx-preview-banner-restore" class="ptx-preview-banner-restore" hidden>${X(xe)}</button>`
55
+ `<button type="button" id="ptx-preview-banner-restore" class="ptx-preview-banner-restore" hidden>${X(Ee)}</button>`
56
56
  ].join(`
57
57
  `);
58
58
  }
59
- function Te() {
59
+ function Se() {
60
60
  return [
61
61
  "<style>",
62
62
  ".ptx-preview-banner {",
@@ -121,7 +121,7 @@ function $e() {
121
121
  return [
122
122
  "<script>",
123
123
  "(function () {",
124
- " var KEY = " + JSON.stringify(ye) + ";",
124
+ " var KEY = " + JSON.stringify(xe) + ";",
125
125
  ' var banner = document.getElementById("ptx-preview-banner");',
126
126
  ' var restore = document.getElementById("ptx-preview-banner-restore");',
127
127
  " if (!banner || !restore) { return; }",
@@ -158,39 +158,39 @@ function $e() {
158
158
  ].join(`
159
159
  `);
160
160
  }
161
- const Se = "<!--ptx-preview-banner-->", _e = "<!--/ptx-preview-banner-->", ke = /\n?<!--ptx-preview-banner-->[\s\S]*?<!--\/ptx-preview-banner-->/;
162
- function Ie(e, n) {
163
- const t = ke.exec(e), r = t ? e.slice(0, t.index) + e.slice(t.index + t[0].length) : e;
161
+ const _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;
164
164
  if (!/<body[^>]*>/i.test(r))
165
165
  return r;
166
166
  const i = `
167
- ${Se}
168
- ${Te()}
169
- ${Ee(n.message)}
167
+ ${_e}
168
+ ${Se()}
169
+ ${Te(n.message)}
170
170
  ${$e()}
171
- ${_e}`;
171
+ ${Ie}`;
172
172
  return r.replace(/<body([^>]*)>/i, `<body$1>${i}`);
173
173
  }
174
- const De = "https://cdn.jsdelivr.net/npm/@pretextbook/pretext-html@0.7.0/assets";
174
+ const De = "https://cdn.jsdelivr.net/npm/@pretextbook/pretext-html@0.8.0/assets";
175
175
  let ee;
176
- function Ct(e) {
176
+ function Ft(e) {
177
177
  ee = e.replace(/\/+$/, "");
178
178
  }
179
- function S() {
179
+ function $() {
180
180
  return ee ?? De;
181
181
  }
182
182
  function te(e, n) {
183
183
  return `${e.replace(/\/+$/, "")}/${n.replace(/^\/+/, "")}`;
184
184
  }
185
- const U = /* @__PURE__ */ new Map();
186
- function Re(e) {
185
+ const V = /* @__PURE__ */ new Map();
186
+ function Me(e) {
187
187
  return `${e.replace(/\/+$/, "")}-bundle.json`;
188
188
  }
189
- function Me(e) {
190
- let n = U.get(e);
189
+ function Le(e) {
190
+ let n = V.get(e);
191
191
  return n || (n = (async () => {
192
192
  try {
193
- const t = await fetch(Re(e));
193
+ const t = await fetch(Me(e));
194
194
  if (!t.ok)
195
195
  return /* @__PURE__ */ new Map();
196
196
  const r = await t.json();
@@ -198,14 +198,14 @@ function Me(e) {
198
198
  } catch {
199
199
  return /* @__PURE__ */ new Map();
200
200
  }
201
- })(), U.set(e, n)), n;
201
+ })(), V.set(e, n)), n;
202
202
  }
203
- function Le(e) {
204
- return e === te(S(), "xsl");
203
+ function Ae(e) {
204
+ return e === te($(), "xsl");
205
205
  }
206
206
  async function ne(e, n) {
207
- if (Le(e)) {
208
- const s = (await Me(e)).get(n.replace(/^\/+/, ""));
207
+ if (Ae(e)) {
208
+ const s = (await Le(e)).get(n.replace(/^\/+/, ""));
209
209
  if (s !== void 0)
210
210
  return new TextEncoder().encode(s);
211
211
  }
@@ -229,7 +229,7 @@ async function ne(e, n) {
229
229
  return;
230
230
  }
231
231
  }
232
- async function B(e) {
232
+ async function C(e) {
233
233
  if (/^[a-z][a-z0-9+.-]*:\/\//i.test(e))
234
234
  try {
235
235
  const n = await fetch(e);
@@ -238,35 +238,42 @@ async function B(e) {
238
238
  return;
239
239
  }
240
240
  }
241
- const Ae = "born-hidden-knowl", Be = /<details\b([^>]*)>(\s*)(?:<summary\b([^>]*)>)?/g;
242
- function Ce(e) {
241
+ const re = "2.46.0", je = "8.2.1", Be = [
242
+ "prefix-runtime.ed2cce180827a7ad.bundle.js",
243
+ "prefix-926.5c7038c8ef173faf.bundle.js",
244
+ "prefix-runestone.1f660864c47fc762.bundle.js"
245
+ ], Ce = [
246
+ "prefix-926.229729d09512acc9.css",
247
+ "prefix-runestone.8086b62682b271d1.css"
248
+ ], Oe = "born-hidden-knowl", Pe = /<details\b([^>]*)>(\s*)(?:<summary\b([^>]*)>)?/g;
249
+ function Ne(e) {
243
250
  const n = /\bclass="([^"]*)"/.exec(e);
244
251
  return n ? n[1].trim().split(/\s+/) : [];
245
252
  }
246
- function Pe(e) {
253
+ function Fe(e) {
247
254
  return /(^|\s)open(\s|=|$)/.test(e);
248
255
  }
249
- function V(e) {
250
- return Pe(e) ? e : ` open${e}`;
256
+ function z(e) {
257
+ return Fe(e) ? e : ` open${e}`;
251
258
  }
252
- function je(e) {
259
+ function We(e) {
253
260
  return e.replace(
254
- Be,
261
+ Pe,
255
262
  (n, t, r, i) => {
256
- if (!Ce(t).includes(Ae))
263
+ if (!Ne(t).includes(Oe))
257
264
  return n;
258
- const s = `<details${V(t)}>`;
259
- return i === void 0 ? `${s}${r}` : `${s}${r}<summary${V(i)}>`;
265
+ const s = `<details${z(t)}>`;
266
+ return i === void 0 ? `${s}${r}` : `${s}${r}<summary${z(i)}>`;
260
267
  }
261
268
  );
262
269
  }
263
- const C = /* @__PURE__ */ new Map(), re = /* @__PURE__ */ new Map();
264
- let L, Oe = 0, ie = ne;
265
- function Pt(e) {
266
- ie = e;
270
+ const O = /* @__PURE__ */ new Map(), ie = /* @__PURE__ */ new Map();
271
+ let j, Ue = 0, se = ne;
272
+ function Wt(e) {
273
+ se = e;
267
274
  }
268
- function We(e, n) {
269
- const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, r = re.get(t);
275
+ function He(e, n) {
276
+ const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, r = ie.get(t);
270
277
  if (r !== void 0)
271
278
  return Promise.resolve(new Response(r, { status: 200 }));
272
279
  let i;
@@ -275,32 +282,32 @@ function We(e, n) {
275
282
  } catch {
276
283
  i = "";
277
284
  }
278
- const s = C.get(i);
279
- return s !== void 0 ? Ne(s, t) : L(e, n);
285
+ const s = O.get(i);
286
+ return s !== void 0 ? Ve(s, t) : j(e, n);
280
287
  }
281
- const Fe = '<?xml version="1.0"?><pretext-preview-missing-file/>';
282
- async function Ne(e, n) {
283
- const t = decodeURIComponent(new URL(n).pathname), r = await ie(e, t);
288
+ const 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);
284
291
  if (r === void 0)
285
- return new Response(Fe, { status: 200 });
292
+ return new Response(Xe, { status: 200 });
286
293
  const i = typeof r == "string" ? r : new Uint8Array(r);
287
294
  return new Response(i, { status: 200 });
288
295
  }
289
- function se() {
290
- L || (L = globalThis.fetch, globalThis.fetch = We);
296
+ function oe() {
297
+ j || (j = globalThis.fetch, globalThis.fetch = He);
291
298
  }
292
- function oe(e) {
293
- se();
294
- const n = `mnt${++Oe}.ptx.invalid`;
295
- return C.set(n, e), `http://${n}`;
299
+ function ae(e) {
300
+ oe();
301
+ const n = `mnt${++Ue}.ptx.invalid`;
302
+ return O.set(n, e), `http://${n}`;
296
303
  }
297
- function He(e) {
298
- C.delete(new URL(e).host);
304
+ function ze(e) {
305
+ O.delete(new URL(e).host);
299
306
  }
300
- function Xe(e, n) {
301
- se(), re.set(e, n);
307
+ function Je(e, n) {
308
+ oe(), ie.set(e, n);
302
309
  }
303
- const A = `<?xml version="1.0" encoding="UTF-8"?>
310
+ const B = `<?xml version="1.0" encoding="UTF-8"?>
304
311
  <publication>
305
312
  <source>
306
313
  <directories external="../assets" generated="../generated-assets" />
@@ -309,62 +316,62 @@ const A = `<?xml version="1.0" encoding="UTF-8"?>
309
316
  <platform portable="yes"/>
310
317
  </html>
311
318
  </publication>
312
- `, Ue = ["theme", "style", "shell"];
313
- function w(e, n) {
319
+ `, Ke = ["theme", "style", "shell"];
320
+ function v(e, n) {
314
321
  for (const t of e.children)
315
322
  if (t.type === "element" && t.name === n)
316
323
  return t;
317
324
  }
318
- function v(e, n) {
319
- let t = w(e, n);
325
+ function b(e, n) {
326
+ let t = v(e, n);
320
327
  return t || (t = { type: "element", name: n, attributes: {}, children: [] }, e.children.push(t)), t;
321
328
  }
322
- function Ve(e, n) {
323
- const t = w(e, "css");
324
- if (t && Ue.some((i) => t.attributes?.[i]))
329
+ function Ge(e, n) {
330
+ const t = v(e, "css");
331
+ if (t && Ke.some((i) => t.attributes?.[i]))
325
332
  return;
326
- const r = t ?? v(e, "css");
333
+ const r = t ?? b(e, "css");
327
334
  r.attributes = { ...r.attributes, theme: n };
328
335
  }
329
- function ze(e, n) {
330
- const t = w(e, "appearance");
336
+ function Ye(e, n) {
337
+ const t = v(e, "appearance");
331
338
  if (t?.attributes?.theme)
332
339
  return;
333
- const r = t ?? v(e, "appearance");
340
+ const r = t ?? b(e, "appearance");
334
341
  r.attributes = { ...r.attributes, theme: n };
335
342
  }
336
- function Je(e) {
337
- const n = v(e, "resources");
343
+ function qe(e) {
344
+ const n = b(e, "resources");
338
345
  n.attributes = {
339
346
  ...n.attributes,
340
347
  host: "cdn",
341
348
  math: "online"
342
349
  };
343
350
  }
344
- function Ke(e, n = {}) {
351
+ function Ze(e, n = {}) {
345
352
  const t = n.cssTheme?.trim(), r = n.revealTheme?.trim(), i = n.target === "slides";
346
353
  if (!e && !t && !i)
347
- return A;
348
- const s = x(e ?? A), o = w(s, "publication");
354
+ return B;
355
+ const s = x(e ?? B), o = v(s, "publication");
349
356
  if (!o)
350
357
  throw new Error(
351
358
  "Invalid publication file: no root <publication> element found"
352
359
  );
353
- const a = v(o, "html"), d = v(a, "platform");
354
- if (d.attributes = { ...d.attributes, portable: "yes" }, t && Ve(a, t), i) {
355
- const l = v(o, "revealjs");
356
- Je(l), r && ze(l, r);
360
+ const a = 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);
357
364
  }
358
- return $(s);
365
+ return S(s);
359
366
  }
360
- function z(e) {
367
+ function J(e) {
361
368
  if (!(e === void 0 || e === "" || e.startsWith("/")))
362
369
  return e.endsWith("/") ? e : `${e}/`;
363
370
  }
364
- function Ye(e) {
365
- const n = x(e ?? A), t = w(n, "publication"), r = t && w(t, "source"), i = r && w(r, "directories"), s = z(
371
+ function Qe(e) {
372
+ const n = x(e ?? B), t = v(n, "publication"), r = t && v(t, "source"), i = r && v(r, "directories"), s = J(
366
373
  i?.attributes?.external ?? void 0
367
- ), o = z(
374
+ ), o = J(
368
375
  i?.attributes?.generated ?? void 0
369
376
  );
370
377
  return {
@@ -373,18 +380,18 @@ function Ye(e) {
373
380
  managed: s !== void 0 && o !== void 0
374
381
  };
375
382
  }
376
- function jt(e) {
383
+ function Ut(e) {
377
384
  return e === "slides" || e === "scroll";
378
385
  }
379
- const ae = 960, ce = 700, Ge = 1, qe = 0.04;
380
- function Ze(e) {
381
- const n = typeof e == "number" && isFinite(e) ? e : Ge, t = Math.min(1, Math.max(0.25, n));
386
+ const 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));
382
389
  return {
383
- width: Math.round(ae / t),
384
- height: Math.round(ce / t)
390
+ width: Math.round(ce / t),
391
+ height: Math.round(le / t)
385
392
  };
386
393
  }
387
- function Qe(e) {
394
+ function rt(e) {
388
395
  return {
389
396
  view: "scroll",
390
397
  scrollLayout: "compact",
@@ -394,11 +401,11 @@ function Qe(e) {
394
401
  controls: !1,
395
402
  controlsTutorial: !1,
396
403
  hash: !1,
397
- ...Ze(e.zoom),
398
- margin: qe
404
+ ...nt(e.zoom),
405
+ margin: tt
399
406
  };
400
407
  }
401
- function et() {
408
+ function it() {
402
409
  return {
403
410
  // Explicitly null rather than absent: the same page may have been
404
411
  // delivered in scroll view a moment ago, and an embedder that re-injects
@@ -410,11 +417,11 @@ function et() {
410
417
  // size with a percentage width renders its text far larger, relative to
411
418
  // the slide, than the same deck will on a projector. No zoom margin
412
419
  // though — presenting means filling whatever it is shown in.
413
- width: ae,
414
- height: ce
420
+ width: ce,
421
+ height: le
415
422
  };
416
423
  }
417
- const tt = [
424
+ const st = [
418
425
  "<style>",
419
426
  ".reveal-viewport.reveal-scroll .scroll-page section {",
420
427
  " box-shadow: inset 0 0 0 calc(1px / var(--slide-scale, 1))",
@@ -422,14 +429,14 @@ const tt = [
422
429
  "}",
423
430
  "</style>"
424
431
  ].join(`
425
- `), nt = [
432
+ `), ot = [
426
433
  " var paused = document.querySelectorAll('.reveal .fragment');",
427
434
  " for (var i = 0; i < paused.length; i++) {",
428
435
  " paused[i].classList.remove('fragment');",
429
436
  " }"
430
437
  ];
431
- function rt(e, n = {}) {
432
- const t = e === "scroll" ? Qe(n) : et();
438
+ function at(e, n = {}) {
439
+ const t = e === "scroll" ? rt(n) : it();
433
440
  return [
434
441
  "<script>",
435
442
  "(function () {",
@@ -457,7 +464,7 @@ function rt(e, n = {}) {
457
464
  // Inside the wrapper rather than at top level: this script sits in <head>,
458
465
  // where the slides have not been parsed yet, but the deck calls initialize
459
466
  // from the end of the document, by which time they have.
460
- ...e === "scroll" ? nt : [],
467
+ ...e === "scroll" ? ot : [],
461
468
  " return initialize(merged);",
462
469
  " };",
463
470
  "})();",
@@ -465,23 +472,23 @@ function rt(e, n = {}) {
465
472
  ].join(`
466
473
  `);
467
474
  }
468
- const it = /<script\b[^>]*\bsrc=["'][^"']*\breveal\.js["'][^>]*>\s*<\/script>/i, st = "<!--ptx-reveal-view-->", ot = "<!--/ptx-reveal-view-->", at = /\n?<!--ptx-reveal-view-->[\s\S]*?<!--\/ptx-reveal-view-->/;
469
- function ct(e, n, t = {}) {
470
- const r = at.exec(e), i = r ? e.slice(0, r.index) + e.slice(r.index + r[0].length) : e, s = it.exec(i);
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);
471
478
  if (!s)
472
479
  return i;
473
480
  const o = s.index + s[0].length, a = `
481
+ ${lt}
474
482
  ${st}
475
- ${tt}
476
- ${rt(n, t)}
477
- ${ot}`;
483
+ ${at(n, t)}
484
+ ${dt}`;
478
485
  return i.slice(0, o) + a + i.slice(o);
479
486
  }
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;
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;
483
490
  }
484
- async function de(e, n, t) {
491
+ async function ue(e, n, t) {
485
492
  const r = x(e), i = {
486
493
  projectDir: p(t),
487
494
  stack: [p(n)]
@@ -491,12 +498,12 @@ async function de(e, n, t) {
491
498
  { "": "" },
492
499
  i
493
500
  );
494
- return { tree: r, content: s ? $(r) : e };
501
+ return { tree: r, content: s ? S(r) : e };
495
502
  }
496
- function dt(e) {
503
+ function ht(e) {
497
504
  return e.data?.ptxIncludedFile;
498
505
  }
499
- function ut(e, n) {
506
+ function mt(e, n) {
500
507
  const t = e.data ?? (e.data = {});
501
508
  t.ptxIncludedFile = n;
502
509
  }
@@ -506,9 +513,9 @@ function _(e, n) {
506
513
  (r === "xmlns" || r.startsWith("xmlns:")) && (t === e && (t = { ...e }), t[r === "xmlns" ? "" : r.slice(6)] = i ?? "");
507
514
  return t;
508
515
  }
509
- function ue(e, n) {
516
+ function fe(e, n) {
510
517
  const t = e.name.indexOf(":"), r = t === -1 ? "" : e.name.slice(0, t);
511
- return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && n[r] === le;
518
+ return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && n[r] === de;
512
519
  }
513
520
  async function y(e, n, t, r) {
514
521
  let i = !1;
@@ -517,8 +524,8 @@ async function y(e, n, t, r) {
517
524
  if (o.type !== "element")
518
525
  continue;
519
526
  const a = _(t, o);
520
- if (ue(o, a)) {
521
- const d = await fe(
527
+ if (fe(o, a)) {
528
+ const d = await pe(
522
529
  o,
523
530
  n,
524
531
  a,
@@ -529,7 +536,7 @@ async function y(e, n, t, r) {
529
536
  }
530
537
  return i;
531
538
  }
532
- async function fe(e, n, t, r) {
539
+ async function pe(e, n, t, r) {
533
540
  const i = r.stack[r.stack.length - 1];
534
541
  if (e.attributes.xpointer)
535
542
  throw new Error(
@@ -544,7 +551,7 @@ async function fe(e, n, t, r) {
544
551
  } catch {
545
552
  }
546
553
  const a = p(n, o);
547
- if (a !== r.projectDir && !a.startsWith(r.projectDir + M))
554
+ if (a !== r.projectDir && !a.startsWith(r.projectDir + A))
548
555
  throw new Error(
549
556
  `xi:include escapes the project directory: ${s} (in ${i})`
550
557
  );
@@ -552,11 +559,11 @@ async function fe(e, n, t, r) {
552
559
  throw new Error(
553
560
  `Circular xi:include: ${[...r.stack, a].join(" -> ")}`
554
561
  );
555
- if (r.stack.length >= J)
556
- throw new Error(`xi:include nesting exceeds ${J} levels`);
557
- const d = await B(a);
562
+ if (r.stack.length >= K)
563
+ throw new Error(`xi:include nesting exceeds ${K} levels`);
564
+ const d = await C(a);
558
565
  if (d === void 0) {
559
- const f = pt(e, t);
566
+ const f = vt(e, t);
560
567
  if (f)
561
568
  return await y(f, n, t, r), f.children;
562
569
  throw new Error(`xi:include target not found: ${s} (in ${i})`);
@@ -581,13 +588,13 @@ async function fe(e, n, t, r) {
581
588
  (f) => f.type === "element"
582
589
  );
583
590
  for (const f of u)
584
- ut(f, a);
591
+ mt(f, a);
585
592
  return u;
586
593
  }
587
- function K(e) {
594
+ function G(e) {
588
595
  return e.name === "docinfo";
589
596
  }
590
- async function ft(e, n, t) {
597
+ async function wt(e, n, t) {
591
598
  try {
592
599
  const i = x(e).children.find(
593
600
  (l) => l.type === "element"
@@ -602,19 +609,19 @@ async function ft(e, n, t) {
602
609
  if (l.type !== "element")
603
610
  continue;
604
611
  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(
612
+ if (G(l))
613
+ return await y(l, o, u, a), S(l);
614
+ if (fe(l, u)) {
615
+ const h = (await pe(
609
616
  l,
610
617
  o,
611
618
  u,
612
619
  a
613
620
  )).find(
614
- (m) => m.type === "element" && K(m)
621
+ (m) => m.type === "element" && G(m)
615
622
  );
616
623
  if (h)
617
- return $(h);
624
+ return S(h);
618
625
  continue;
619
626
  }
620
627
  break;
@@ -624,33 +631,33 @@ async function ft(e, n, t) {
624
631
  return;
625
632
  }
626
633
  }
627
- function pt(e, n) {
634
+ function vt(e, n) {
628
635
  for (const t of e.children) {
629
636
  if (t.type !== "element")
630
637
  continue;
631
638
  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)
639
+ if ((i === -1 ? t.name : t.name.slice(i + 1)) === "fallback" && r[s] === de)
633
640
  return t;
634
641
  }
635
642
  }
636
- function pe(e) {
643
+ function he(e) {
637
644
  return typeof e == "object" && e !== null && e.type === "element";
638
645
  }
639
- function ht(e) {
646
+ function bt(e) {
640
647
  return /^(pf|xhtml):/.test(e.name);
641
648
  }
642
- function mt(e, n, t) {
643
- const r = [], i = e.children.find(pe);
649
+ function gt(e, n, t) {
650
+ const r = [], i = e.children.find(he);
644
651
  if (i) {
645
652
  const s = t?.parentId ?? "root";
646
- he(i, s, t?.position ?? 1, n, s, r);
653
+ me(i, s, t?.position ?? 1, n, s, r);
647
654
  }
648
655
  return r;
649
656
  }
650
- function he(e, n, t, r, i, s) {
651
- const o = dt(e) ?? r;
657
+ function me(e, n, t, r, i, s) {
658
+ const o = ht(e) ?? r;
652
659
  let a, d;
653
- if (ht(e))
660
+ if (bt(e))
654
661
  d = "root";
655
662
  else {
656
663
  const u = e.attributes.label ?? e.attributes["xml:id"];
@@ -665,7 +672,7 @@ function he(e, n, t, r, i, s) {
665
672
  }
666
673
  let l = 0;
667
674
  for (const u of e.children)
668
- pe(u) && (l += 1, he(
675
+ he(u) && (l += 1, me(
669
676
  u,
670
677
  d,
671
678
  l,
@@ -674,28 +681,28 @@ function he(e, n, t, r, i, s) {
674
681
  s
675
682
  ));
676
683
  }
677
- function Ot(e, n) {
684
+ function Ht(e, n) {
678
685
  let t;
679
686
  for (const r of e)
680
687
  r.line <= n && (t = r);
681
688
  return t ?? e[0];
682
689
  }
683
- function wt(e) {
690
+ function yt(e) {
684
691
  const n = e.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!\[CDATA\[[\s\S]*?\]\]>/g, " ");
685
692
  return /<\s*slide(?:show)?[\s/>]/.test(n) ? "slides" : "html";
686
693
  }
687
- const me = "pretext-html:set-theme";
688
- function Wt(e) {
694
+ const we = "pretext-html:set-theme";
695
+ function Xt(e) {
689
696
  return e === "dark" || e === "light" || e === "system";
690
697
  }
691
- function Ft(e) {
692
- return { type: me, theme: e };
698
+ function Vt(e) {
699
+ return { type: we, theme: e };
693
700
  }
694
- function vt(e) {
701
+ function xt(e) {
695
702
  return [
696
703
  "<script>",
697
704
  "(function () {",
698
- " var CFG = " + JSON.stringify({ msg: me, initial: e }) + ";",
705
+ " var CFG = " + JSON.stringify({ msg: we, initial: e }) + ";",
699
706
  // Where the last requested theme is remembered so it survives an in-place
700
707
  // document rewrite (same Window) and outranks the baked initial value.
701
708
  " var KEY = '__ptxPreviewTheme';",
@@ -765,56 +772,62 @@ function vt(e) {
765
772
  ].join(`
766
773
  `);
767
774
  }
768
- function bt(e, n) {
769
- const t = vt(n);
775
+ function Et(e, n) {
776
+ const t = xt(n);
770
777
  return /<head[^>]*>/i.test(e) ? e.replace(/<head([^>]*)>/i, `<head$1>
771
778
  ${t}`) : e;
772
779
  }
773
- function gt() {
774
- return te(S(), "xsl");
780
+ function Tt() {
781
+ return te($(), "xsl");
775
782
  }
776
- function yt() {
783
+ function St() {
777
784
  return "Suspending" in WebAssembly;
778
785
  }
779
- function xt() {
780
- if (!yt())
786
+ function $t() {
787
+ if (!St())
781
788
  throw new Error(
782
789
  "WebAssembly JSPI is not enabled. Run Node with --experimental-wasm-jspi (or use the pretext-html CLI, which re-launches itself with the flag)."
783
790
  );
784
791
  }
785
- function Y(e) {
792
+ function D(e) {
786
793
  return e.includes("'") ? e.includes('"') ? `concat(${e.split("'").map((t) => `'${t}'`).join(`, "'", `)})` : `"${e}"` : `'${e}'`;
787
794
  }
788
- function Et(e) {
795
+ function _t(e) {
789
796
  return e.replace(
790
797
  /from '\.\/(https:\/\/[^']+)'/g,
791
798
  (n, t) => `from '${t}'`
792
799
  );
793
800
  }
794
- const Tt = "https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@latest/dist/";
795
- function $t(e) {
801
+ const It = `https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@${re}/dist/`, Rt = {
802
+ "cli.version": re,
803
+ // Colon-delimited: pretext-runestone.xsl splits them with str:tokenize.
804
+ "rs-js": Be.join(":"),
805
+ "rs-css": Ce.join(":"),
806
+ "rs-version": je
807
+ };
808
+ function kt(e) {
796
809
  return e.replace(
797
810
  /(<link\b[^>]*\bhref=["'])_static\//gi,
798
- `$1${Tt}_static/`
811
+ `$1${It}_static/`
799
812
  );
800
813
  }
801
- function St(e) {
814
+ function Dt(e) {
802
815
  return e.slice(0, 65536).replace(/<\?[\s\S]*?\?>/g, " ").replace(/<!--[\s\S]*?-->/g, " ").replace(/<!DOCTYPE[^>]*>/gi, " ").match(/<\s*([A-Za-z][\w:-]*)/)?.[1];
803
816
  }
804
- async function G(e) {
805
- const n = await B(e);
817
+ async function Y(e) {
818
+ const n = await C(e);
806
819
  if (n === void 0)
807
820
  throw new Error(
808
821
  `Could not read ${e}. (In the browser build only absolute URLs are readable — pass sourceContent instead of relying on sourcePath.)`
809
822
  );
810
823
  return n;
811
824
  }
812
- async function _t(e, n) {
813
- const t = p(e), r = await B(t);
825
+ async function Mt(e, n) {
826
+ const t = p(e), r = await C(t);
814
827
  if (r !== void 0)
815
- return ft(r, t, n);
828
+ return wt(r, t, n);
816
829
  }
817
- function kt(e, n, t, r) {
830
+ function Lt(e, n, t, r) {
818
831
  const i = e.replace(/^\uFEFF/, "").replace(/<\?xml[\s\S]*?\?>/, "").replace(/<!DOCTYPE[^>]*>/i, ""), s = t === "slides" ? "slideshow" : n === "chapter" || n === "part" ? "book" : "article";
819
832
  return `<pretext>
820
833
  ${r?.trim() ? `${r.trim()}
@@ -825,63 +838,63 @@ ${i}
825
838
  </pretext>
826
839
  `;
827
840
  }
828
- let we = !1;
829
- function It(e) {
841
+ let ve = !1;
842
+ function At(e) {
830
843
  return e instanceof Error && /\bAborted\(/.test(e.message);
831
844
  }
832
- function Dt(e) {
845
+ function jt(e) {
833
846
  return e instanceof Error && /memory access|out of bounds/i.test(e.message);
834
847
  }
835
- function Rt() {
836
- if (we)
848
+ function Bt() {
849
+ if (ve)
837
850
  throw new Error(
838
851
  "The WebAssembly renderer aborted earlier in this process and cannot be reused. Restart the process (or reload the page) to render again."
839
852
  );
840
853
  }
841
854
  function q(e) {
842
- if (It(e))
843
- throw we = !0, new Error(
855
+ if (At(e))
856
+ throw ve = !0, new Error(
844
857
  "The WebAssembly renderer aborted and cannot be reused. Restart the process (or reload the page) to render again.",
845
858
  { cause: e }
846
859
  );
847
- if (Dt(e))
860
+ if (jt(e))
848
861
  throw new Error(
849
862
  "The WebAssembly renderer hit a memory fault. Most often the document is too large for this build's stack — whole-book builds are a known limitation, so try a smaller document, or see the README about rebuilding libxslt-wasm with a larger stack. The same fault also results from running two renders concurrently against the shared libxslt state.",
850
863
  { cause: e }
851
864
  );
852
865
  }
853
- let D;
854
- async function ve() {
855
- return D || (D = (async () => {
866
+ let M;
867
+ async function be() {
868
+ return M || (M = (async () => {
856
869
  const [e, n] = await Promise.all([
857
870
  import("@pretextbook/libxslt-wasm"),
858
871
  import("@pretextbook/libxslt-wasm/exslt")
859
872
  ]);
860
873
  return n.registerAll(), e;
861
- })()), D;
874
+ })()), M;
862
875
  }
863
- const R = /* @__PURE__ */ new Map(), Mt = {
876
+ const L = /* @__PURE__ */ new Map(), Ct = {
864
877
  html: "preview-html.xsl",
865
878
  slides: "preview-revealjs.xsl"
866
879
  };
867
- async function Lt(e, n) {
868
- const t = Mt[n], r = `${n}\0${e}`;
869
- let i = R.get(r);
880
+ async function Ot(e, n) {
881
+ const t = Ct[n], r = `${n}\0${e}`;
882
+ let i = L.get(r);
870
883
  return i || (i = (async () => {
871
- const { XmlDocument: s, XsltStylesheet: o } = await ve(), a = oe(e), d = await ne(S(), `/${t}`);
884
+ const { XmlDocument: s, XsltStylesheet: o } = await be(), a = ae(e), d = await ne($(), `/${t}`);
872
885
  if (d === void 0)
873
886
  throw new Error(
874
- `Could not read ${t} from ${S()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
887
+ `Could not read ${t} from ${$()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
875
888
  );
876
889
  const l = new TextDecoder().decode(d), u = await s.fromString(l, {
877
890
  url: `${a}/${t}`,
878
891
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
879
892
  });
880
893
  return o.fromXmlDocument(u);
881
- })(), R.set(r, i), i.catch(() => R.delete(r))), i;
894
+ })(), L.set(r, i), i.catch(() => L.delete(r))), i;
882
895
  }
883
896
  let Z = Promise.resolve();
884
- function Nt(e) {
897
+ function zt(e) {
885
898
  const n = Z.then(
886
899
  () => Q(e),
887
900
  () => Q(e)
@@ -890,55 +903,55 @@ function Nt(e) {
890
903
  }), n;
891
904
  }
892
905
  async function Q(e) {
893
- xt(), Rt();
894
- const { XmlDocument: n } = await ve(), t = p(e.sourcePath), r = p(
906
+ $t(), Bt();
907
+ const { XmlDocument: n } = await be(), t = p(e.sourcePath), r = p(
895
908
  e.projectDir ?? g(t)
896
- ), i = e.sourceContent ?? await G(t), s = I(r, t);
909
+ ), i = e.sourceContent ?? await Y(t), s = k(r, t);
897
910
  if (s.startsWith(".."))
898
911
  throw new Error(
899
912
  `sourcePath (${t}) must live inside projectDir (${r})`
900
913
  );
901
- const o = I(
914
+ const o = k(
902
915
  r,
903
916
  p(e.mainSourcePath ?? t)
904
- ), a = o.startsWith("..") ? s : o, d = oe(r);
917
+ ), a = o.startsWith("..") ? s : o, d = ae(r);
905
918
  try {
906
919
  let l, u = `${d}/__pretext-preview-publication.xml`;
907
920
  if (e.publicationPath) {
908
921
  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("/")}`);
922
+ l = await Y(c);
923
+ const w = k(r, c);
924
+ w.startsWith("..") || (u = `${d}/${w.split(A).join("/")}`);
912
925
  }
913
926
  let f, h;
914
927
  if (e.sourceMap) {
915
- const c = await de(
928
+ const c = await ue(
916
929
  i,
917
930
  t,
918
931
  r
919
932
  );
920
933
  f = c.tree, h = c.content;
921
934
  } else
922
- h = await lt(
935
+ h = await pt(
923
936
  i,
924
937
  t,
925
938
  r
926
939
  );
927
- const m = e.target ?? wt(h), be = await Lt(e.xslDir ?? gt(), m), P = Ke(l, {
940
+ const m = e.target ?? yt(h), ge = await Ot(e.xslDir ?? Tt(), m), P = Ze(l, {
928
941
  cssTheme: e.cssTheme,
929
942
  revealTheme: e.revealTheme,
930
943
  target: m
931
944
  });
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);
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);
937
950
  let W = { parentId: "root", position: 1 };
938
951
  if (T !== "pretext" && T !== "mathbook")
939
952
  if (e.fragment) {
940
- const c = e.docinfo ?? (e.docinfoSourcePath ? await _t(e.docinfoSourcePath, r) : void 0);
941
- h = kt(
953
+ const c = e.docinfo ?? (e.docinfoSourcePath ? await Mt(e.docinfoSourcePath, r) : void 0);
954
+ h = Lt(
942
955
  h,
943
956
  T,
944
957
  m,
@@ -948,64 +961,66 @@ async function Q(e) {
948
961
  throw new Error(
949
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.`
950
963
  );
951
- const F = f ? mt(f, t, W) : void 0, N = await n.fromString(h, {
952
- url: `${d}/${a.split(M).join("/")}`,
964
+ const U = f ? gt(f, t, W) : void 0, H = await n.fromString(h, {
965
+ url: `${d}/${a.split(A).join("/")}`,
953
966
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
954
- }), H = {
955
- publisher: Y(u)
967
+ }), I = {
968
+ publisher: D(u)
956
969
  };
957
- for (const [c, b] of Object.entries(e.stringParams ?? {}))
958
- H[c] = Y(b);
959
- let k;
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;
960
975
  try {
961
- k = await be.apply(N, H);
976
+ R = await ge.apply(H, I);
962
977
  } catch (c) {
963
978
  throw q(c), new Error(
964
979
  "PreTeXt XSLT transform failed; see the PTX:ERROR/PTX:FATAL messages on stderr for details.",
965
980
  { cause: c }
966
981
  );
967
982
  } finally {
968
- N.delete();
983
+ H.delete();
969
984
  }
970
985
  try {
971
- let c = Et(k.toHtmlString());
972
- return (e.openKnowls ?? !0) && (c = je(c)), m === "slides" ? (c = $t(c), c = ct(c, e.revealView ?? "scroll", {
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", {
973
988
  zoom: e.revealZoom
974
- })) : e.theme && (c = bt(c, e.theme)), e.previewBanner && (c = Ie(c, e.previewBanner)), {
989
+ })) : e.theme && (c = Et(c, e.theme)), e.previewBanner && (c = ke(c, e.previewBanner)), {
975
990
  html: c,
976
991
  target: m,
977
- ...F ? { sourceMap: F } : {},
978
- ...O ? { assetDirs: O } : {}
992
+ ...U ? { sourceMap: U } : {},
993
+ ...F ? { assetDirs: F } : {}
979
994
  };
980
995
  } catch (c) {
981
996
  throw q(c), c;
982
997
  } finally {
983
- k.delete();
998
+ R.delete();
984
999
  }
985
1000
  } finally {
986
- He(d);
1001
+ ze(d);
987
1002
  }
988
1003
  }
989
1004
  export {
990
- ye as PREVIEW_BANNER_STORAGE_KEY,
991
- me as PREVIEW_THEME_MESSAGE,
992
- gt as defaultXslDir,
993
- wt as detectRenderTarget,
994
- Ot as findSourceMapEntry,
995
- Ke as forcePortablePublication,
996
- Ie as injectPreviewBanner,
997
- ct as injectRevealBridge,
998
- bt as injectThemeBridge,
999
- yt as isJspiAvailable,
1000
- Wt as isPreviewTheme,
1001
- jt as isRevealView,
1002
- je as openBornHiddenKnowls,
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,
1003
1018
  $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
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
1011
1026
  };