@pretextbook/pretext-html 0.17.0 → 0.18.1

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,27 +1,29 @@
1
- import { readFile as ue, writeFile as xe } from "node:fs/promises";
2
- import * as L from "node:process";
3
- import { listPrintouts as st, rootPrintoutId as at, injectPrintPreview as Me } from "./printout.js";
1
+ import { existsSync as lt } from "node:fs";
2
+ import { readFile as de, writeFile as Te } from "node:fs/promises";
4
3
  import * as f from "node:path";
5
- import { fileURLToPath as ct } from "node:url";
6
- import { fromXml as U } from "xast-util-from-xml";
7
- import { toXml as B } from "xast-util-to-xml";
8
- import { injectRevealBridge as lt } from "./reveal.js";
9
- import { injectThemeBridge as ut } from "./theme.js";
10
- const dt = "ptxPreviewBannerDismissed", ft = "About live preview";
11
- function ye(e) {
4
+ import * as L from "node:process";
5
+ import { fileURLToPath as ut, pathToFileURL as dt } from "node:url";
6
+ import { rewriteAssetUrls as ft, missingAssetPlaceholder as ht } from "./assets.js";
7
+ import { listPrintouts as pt, rootPrintoutId as mt, injectPrintPreview as Ce } from "./printout.js";
8
+ import { fromXml as B } from "xast-util-from-xml";
9
+ import { toXml as N } from "xast-util-to-xml";
10
+ import { injectRevealBridge as vt } from "./reveal.js";
11
+ import { injectThemeBridge as bt } from "./theme.js";
12
+ const wt = "ptxPreviewBannerDismissed", gt = "About live preview";
13
+ function Se(e) {
12
14
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
13
15
  }
14
- function ht(e) {
16
+ function xt(e) {
15
17
  return [
16
18
  '<div id="ptx-preview-banner" class="ptx-preview-banner" role="note">',
17
- ` <span class="ptx-preview-banner-text">${ye(e)}</span>`,
19
+ ` <span class="ptx-preview-banner-text">${Se(e)}</span>`,
18
20
  ' <button type="button" class="ptx-preview-banner-dismiss" aria-label="Dismiss">&times;</button>',
19
21
  "</div>",
20
- `<button type="button" id="ptx-preview-banner-restore" class="ptx-preview-banner-restore" hidden>${ye(ft)}</button>`
22
+ `<button type="button" id="ptx-preview-banner-restore" class="ptx-preview-banner-restore" hidden>${Se(gt)}</button>`
21
23
  ].join(`
22
24
  `);
23
25
  }
24
- function pt() {
26
+ function yt() {
25
27
  return [
26
28
  "<style>",
27
29
  ".ptx-preview-banner {",
@@ -90,11 +92,11 @@ function pt() {
90
92
  ].join(`
91
93
  `);
92
94
  }
93
- function mt() {
95
+ function Tt() {
94
96
  return [
95
97
  "<script>",
96
98
  "(function () {",
97
- " var KEY = " + JSON.stringify(dt) + ";",
99
+ " var KEY = " + JSON.stringify(wt) + ";",
98
100
  ' var banner = document.getElementById("ptx-preview-banner");',
99
101
  ' var restore = document.getElementById("ptx-preview-banner-restore");',
100
102
  " if (!banner || !restore) { return; }",
@@ -131,20 +133,20 @@ function mt() {
131
133
  ].join(`
132
134
  `);
133
135
  }
134
- const bt = "<!--ptx-preview-banner-->", wt = "<!--/ptx-preview-banner-->", vt = /\n?<!--ptx-preview-banner-->[\s\S]*?<!--\/ptx-preview-banner-->/;
135
- function gt(e, n) {
136
- const t = vt.exec(e), r = t ? e.slice(0, t.index) + e.slice(t.index + t[0].length) : e;
136
+ const St = "<!--ptx-preview-banner-->", Et = "<!--/ptx-preview-banner-->", kt = /\n?<!--ptx-preview-banner-->[\s\S]*?<!--\/ptx-preview-banner-->/;
137
+ function Pt(e, n) {
138
+ const t = kt.exec(e), r = t ? e.slice(0, t.index) + e.slice(t.index + t[0].length) : e;
137
139
  if (!/<body[^>]*>/i.test(r))
138
140
  return r;
139
141
  const i = `
140
- ${bt}
141
- ${pt()}
142
- ${ht(n.message)}
143
- ${mt()}
144
- ${wt}`;
142
+ ${St}
143
+ ${yt()}
144
+ ${xt(n.message)}
145
+ ${Tt()}
146
+ ${Et}`;
145
147
  return r.replace(/<body([^>]*)>/i, `<body$1>${i}`);
146
148
  }
147
- async function je(e, n) {
149
+ async function Me(e, n) {
148
150
  const t = f.resolve(e), r = f.resolve(t, `.${f.posix.normalize(n)}`);
149
151
  if (r !== t && !r.startsWith(t + f.sep)) {
150
152
  console.error(
@@ -153,64 +155,64 @@ async function je(e, n) {
153
155
  return;
154
156
  }
155
157
  try {
156
- return new Uint8Array(await ue(r));
158
+ return new Uint8Array(await de(r));
157
159
  } catch {
158
160
  return;
159
161
  }
160
162
  }
161
- async function xt(e) {
163
+ async function $t(e) {
162
164
  try {
163
- return await ue(e, "utf8");
165
+ return await de(e, "utf8");
164
166
  } catch {
165
167
  return;
166
168
  }
167
169
  }
168
- let Ce;
169
- function Xn(e) {
170
- Ce = e;
170
+ let Oe;
171
+ function Zn(e) {
172
+ Oe = e;
171
173
  }
172
- function se() {
173
- return Ce ?? process.env.PRETEXT_HTML_ASSETS ?? f.resolve(f.dirname(ct(import.meta.url)), "..", "assets");
174
+ function ae() {
175
+ return Oe ?? process.env.PRETEXT_HTML_ASSETS ?? f.resolve(f.dirname(ut(import.meta.url)), "..", "assets");
174
176
  }
175
- function yt(e, n) {
177
+ function It(e, n) {
176
178
  return f.join(e, n);
177
179
  }
178
- const Oe = "2.55.0", Tt = "8.3.3", St = [
179
- "prefix-runtime.dd07797f77620576.bundle.js",
180
+ const _e = "2.56.1", Lt = "8.3.6", Dt = [
181
+ "prefix-runtime.4beca1fdeed766a2.bundle.js",
180
182
  "prefix-926.5c7038c8ef173faf.bundle.js",
181
- "prefix-runestone.11d27cdc38930c2c.bundle.js"
182
- ], kt = [
183
+ "prefix-runestone.ebd33f6a21eed414.bundle.js"
184
+ ], Rt = [
183
185
  "prefix-926.229729d09512acc9.css",
184
- "prefix-runestone.347e2ecdeacfed99.css"
185
- ], Et = "born-hidden-knowl", $t = /<details\b([^>]*)>(\s*)(?:<summary\b([^>]*)>)?/g;
186
- function Pt(e) {
186
+ "prefix-runestone.9963089870a016c8.css"
187
+ ], At = "born-hidden-knowl", jt = /<details\b([^>]*)>(\s*)(?:<summary\b([^>]*)>)?/g;
188
+ function Ct(e) {
187
189
  const n = /\bclass="([^"]*)"/.exec(e);
188
190
  return n ? n[1].trim().split(/\s+/) : [];
189
191
  }
190
- function It(e) {
192
+ function Mt(e) {
191
193
  return /(^|\s)open(\s|=|$)/.test(e);
192
194
  }
193
- function Te(e) {
194
- return It(e) ? e : ` open${e}`;
195
+ function Ee(e) {
196
+ return Mt(e) ? e : ` open${e}`;
195
197
  }
196
- function Lt(e) {
198
+ function Ot(e) {
197
199
  return e.replace(
198
- $t,
200
+ jt,
199
201
  (n, t, r, i) => {
200
- if (!Pt(t).includes(Et))
202
+ if (!Ct(t).includes(At))
201
203
  return n;
202
- const o = `<details${Te(t)}>`;
203
- return i === void 0 ? `${o}${r}` : `${o}${r}<summary${Te(i)}>`;
204
+ const o = `<details${Ee(t)}>`;
205
+ return i === void 0 ? `${o}${r}` : `${o}${r}<summary${Ee(i)}>`;
204
206
  }
205
207
  );
206
208
  }
207
- const de = /* @__PURE__ */ new Map(), _e = /* @__PURE__ */ new Map();
208
- let ae, Dt = 0, Be = je;
209
- function Un(e) {
209
+ const fe = /* @__PURE__ */ new Map(), Ne = /* @__PURE__ */ new Map();
210
+ let ce, _t = 0, Be = Me;
211
+ function Qn(e) {
210
212
  Be = e;
211
213
  }
212
- function Rt(e, n) {
213
- const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, r = _e.get(t);
214
+ function Nt(e, n) {
215
+ const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, r = Ne.get(t);
214
216
  if (r !== void 0)
215
217
  return Promise.resolve(new Response(r, { status: 200 }));
216
218
  let i;
@@ -219,32 +221,32 @@ function Rt(e, n) {
219
221
  } catch {
220
222
  i = "";
221
223
  }
222
- const o = de.get(i);
223
- return o !== void 0 ? Mt(o, t) : ae(e, n);
224
+ const o = fe.get(i);
225
+ return o !== void 0 ? Ft(o, t) : ce(e, n);
224
226
  }
225
- const At = '<?xml version="1.0"?><pretext-preview-missing-file/>';
226
- async function Mt(e, n) {
227
+ const Bt = '<?xml version="1.0"?><pretext-preview-missing-file/>';
228
+ async function Ft(e, n) {
227
229
  const t = decodeURIComponent(new URL(n).pathname), r = await Be(e, t);
228
230
  if (r === void 0)
229
- return new Response(At, { status: 200 });
231
+ return new Response(Bt, { status: 200 });
230
232
  const i = typeof r == "string" ? r : new Uint8Array(r);
231
233
  return new Response(i, { status: 200 });
232
234
  }
233
- function Ne() {
234
- ae || (ae = globalThis.fetch, globalThis.fetch = Rt);
235
+ function Fe() {
236
+ ce || (ce = globalThis.fetch, globalThis.fetch = Nt);
235
237
  }
236
- function Fe(e) {
237
- Ne();
238
- const n = `mnt${++Dt}.ptx.invalid`;
239
- return de.set(n, e), `http://${n}`;
238
+ function Ue(e) {
239
+ Fe();
240
+ const n = `mnt${++_t}.ptx.invalid`;
241
+ return fe.set(n, e), `http://${n}`;
240
242
  }
241
- function jt(e) {
242
- de.delete(new URL(e).host);
243
+ function Ut(e) {
244
+ fe.delete(new URL(e).host);
243
245
  }
244
- function Ct(e, n) {
245
- Ne(), _e.set(e, n);
246
+ function Xt(e, n) {
247
+ Fe(), Ne.set(e, n);
246
248
  }
247
- const J = `<?xml version="1.0" encoding="UTF-8"?>
249
+ const he = `<?xml version="1.0" encoding="UTF-8"?>
248
250
  <publication>
249
251
  <source>
250
252
  <directories external="../assets" generated="../generated-assets" />
@@ -252,35 +254,37 @@ const J = `<?xml version="1.0" encoding="UTF-8"?>
252
254
  <common>
253
255
  <tableofcontents level="0"/>
254
256
  </common>
255
- <html>
256
- <platform portable="yes"/>
257
- </html>
258
257
  </publication>
259
- `, Ot = ["theme", "style", "shell"];
260
- function $(e, n) {
258
+ `, Wt = [
259
+ [["html", "resources"], "host", "cdn"],
260
+ [["html", "platform"], "portable", "no"],
261
+ [["html", "cross-references"], "knowled", "never"],
262
+ [["common", "chunking"], "level", "0"]
263
+ ], Ht = ["theme", "style", "shell"];
264
+ function E(e, n) {
261
265
  for (const t of e.children)
262
266
  if (t.type === "element" && t.name === n)
263
267
  return t;
264
268
  }
265
269
  function _(e, n) {
266
- let t = $(e, n);
270
+ let t = E(e, n);
267
271
  return t || (t = { type: "element", name: n, attributes: {}, children: [] }, e.children.push(t)), t;
268
272
  }
269
- function _t(e, n) {
270
- const t = $(e, "css");
271
- if (t && Ot.some((i) => t.attributes?.[i]))
273
+ function zt(e, n) {
274
+ const t = E(e, "css");
275
+ if (t && Ht.some((i) => t.attributes?.[i]))
272
276
  return;
273
277
  const r = t ?? _(e, "css");
274
278
  r.attributes = { ...r.attributes, theme: n };
275
279
  }
276
- function Bt(e, n) {
277
- const t = $(e, "appearance");
280
+ function Jt(e, n) {
281
+ const t = E(e, "appearance");
278
282
  if (t?.attributes?.theme)
279
283
  return;
280
284
  const r = t ?? _(e, "appearance");
281
285
  r.attributes = { ...r.attributes, theme: n };
282
286
  }
283
- function Nt(e) {
287
+ function Kt(e) {
284
288
  const n = _(e, "resources");
285
289
  n.attributes = {
286
290
  ...n.attributes,
@@ -288,23 +292,28 @@ function Nt(e) {
288
292
  math: "online"
289
293
  };
290
294
  }
291
- function Ft(e, n = {}) {
292
- const t = n.cssTheme?.trim(), r = n.revealTheme?.trim(), i = n.target === "slides";
293
- if (!e && !t && !i)
294
- return J;
295
- const o = U(e ?? J), s = $(o, "publication");
295
+ function Xe(e, n = {}) {
296
+ const t = n.cssTheme?.trim(), r = n.revealTheme?.trim(), i = n.target === "slides", o = B(e ?? he), s = E(o, "publication");
296
297
  if (!s)
297
298
  throw new Error(
298
299
  "Invalid publication file: no root <publication> element found"
299
300
  );
300
- const a = _(s, "html"), c = _(a, "platform");
301
- if (c.attributes = { ...c.attributes, portable: "yes" }, t && _t(a, t), i) {
302
- const u = _(s, "revealjs");
303
- Nt(u), r && Bt(u, r);
301
+ for (const [c, d, u] of Wt) {
302
+ const l = c.reduce(
303
+ (m, b) => _(m, b),
304
+ s
305
+ );
306
+ l.attributes = { ...l.attributes, [d]: u };
307
+ }
308
+ const a = _(s, "html");
309
+ if (t && zt(a, t), i) {
310
+ const c = _(s, "revealjs");
311
+ Kt(c), r && Jt(c, r);
304
312
  }
305
- return B(o);
313
+ return N(o);
306
314
  }
307
- function Se(e) {
315
+ const er = Xe, Vt = "generated/";
316
+ function ne(e) {
308
317
  if (!(e === void 0 || e === "" || e.startsWith("/")))
309
318
  return e.endsWith("/") ? e : `${e}/`;
310
319
  }
@@ -314,13 +323,13 @@ function ke(e) {
314
323
  const t = Number(n);
315
324
  return Number.isFinite(t) && t >= 0 ? t : void 0;
316
325
  }
317
- function Xt(e) {
318
- const n = U(e ?? J), t = $(n, "publication"), r = t && $(t, "common"), i = r && $(r, "tableofcontents"), o = t && $(t, "numbering");
326
+ function Gt(e) {
327
+ const n = B(e ?? he), t = E(n, "publication"), r = t && E(t, "common"), i = r && E(r, "tableofcontents"), o = t && E(t, "numbering");
319
328
  let s, a;
320
329
  for (const c of o?.children ?? []) {
321
330
  if (c.type !== "element") continue;
322
- const u = ke(c);
323
- u !== void 0 && (c.name === "divisions" ? a = u : s = Math.max(s ?? 0, u));
331
+ const d = ke(c);
332
+ d !== void 0 && (c.name === "divisions" ? a = d : s = Math.max(s ?? 0, d));
324
333
  }
325
334
  return {
326
335
  tocLevel: ke(i),
@@ -328,27 +337,34 @@ function Xt(e) {
328
337
  maxNumberingLevel: a
329
338
  };
330
339
  }
331
- function Ut(e) {
332
- const n = U(e ?? J), t = $(n, "publication"), r = t && $(t, "source"), i = r && $(r, "directories"), o = Se(
333
- i?.attributes?.external ?? void 0
334
- ), s = Se(
335
- i?.attributes?.generated ?? void 0
336
- );
337
- return {
338
- external: o,
339
- generated: s,
340
- managed: o !== void 0 && s !== void 0
341
- };
340
+ function Yt(e, n) {
341
+ const t = B(e ?? he), r = E(t, "publication"), i = r && E(r, "source"), o = i && E(i, "directories"), s = (d) => {
342
+ const u = o?.attributes?.[d];
343
+ return u == null ? void 0 : String(u);
344
+ }, a = ne(n !== void 0 ? n : s("external")), c = ne(s("generated")) ?? Vt;
345
+ return a === void 0 ? { generated: c } : { external: a, generated: c };
346
+ }
347
+ function z(e) {
348
+ if (typeof e == "string")
349
+ try {
350
+ return z(B(e));
351
+ } catch {
352
+ return;
353
+ }
354
+ const n = e.children.find(
355
+ (o) => o.type === "element"
356
+ ), t = n?.name === "docinfo" ? n : n && E(n, "docinfo"), i = (t && E(t, "directories"))?.attributes?.external;
357
+ return i == null ? void 0 : String(i);
342
358
  }
343
- const Xe = "http://www.w3.org/2001/XInclude", Ee = 64;
344
- async function Z(e, n) {
345
- return (e?.readSource ? await e.readSource(n) : void 0) ?? await xt(n);
359
+ const We = "http://www.w3.org/2001/XInclude", Pe = 64;
360
+ async function q(e, n) {
361
+ return (e?.readSource ? await e.readSource(n) : void 0) ?? await $t(n);
346
362
  }
347
- function fe(e, n, t) {
348
- return e.cache ? e.cache.parse(n, t) : U(t);
363
+ function pe(e, n, t) {
364
+ return e.cache ? e.cache.parse(n, t) : B(t);
349
365
  }
350
- async function he(e, n, t, r = {}) {
351
- const i = f.resolve(n), o = fe(r, i, e), s = {
366
+ async function me(e, n, t, r = {}) {
367
+ const i = f.resolve(n), o = pe(r, i, e), s = {
352
368
  ...r,
353
369
  projectDir: f.resolve(t),
354
370
  stack: [i],
@@ -362,27 +378,27 @@ async function he(e, n, t, r = {}) {
362
378
  );
363
379
  return {
364
380
  tree: o,
365
- content: a ? B(o) : e,
381
+ content: a ? N(o) : e,
366
382
  files: s.files,
367
383
  bytes: s.bytes
368
384
  };
369
385
  }
370
- function Ue(e) {
386
+ function He(e) {
371
387
  return e.data?.ptxIncludedFile;
372
388
  }
373
- function We(e, n) {
389
+ function ze(e, n) {
374
390
  const t = e.data ?? (e.data = {});
375
391
  t.ptxIncludedFile = n;
376
392
  }
377
- function K(e, n) {
393
+ function J(e, n) {
378
394
  let t = e;
379
395
  for (const [r, i] of Object.entries(n.attributes))
380
396
  (r === "xmlns" || r.startsWith("xmlns:")) && (t === e && (t = { ...e }), t[r === "xmlns" ? "" : r.slice(6)] = i ?? "");
381
397
  return t;
382
398
  }
383
- function He(e, n) {
399
+ function Je(e, n) {
384
400
  const t = e.name.indexOf(":"), r = t === -1 ? "" : e.name.slice(0, t);
385
- return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && n[r] === Xe;
401
+ return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && n[r] === We;
386
402
  }
387
403
  async function X(e, n, t, r) {
388
404
  let i = !1;
@@ -390,9 +406,9 @@ async function X(e, n, t, r) {
390
406
  const s = e.children[o];
391
407
  if (s.type !== "element")
392
408
  continue;
393
- const a = K(t, s);
394
- if (He(s, a)) {
395
- const c = await ze(
409
+ const a = J(t, s);
410
+ if (Je(s, a)) {
411
+ const c = await Ke(
396
412
  s,
397
413
  n,
398
414
  a,
@@ -403,7 +419,7 @@ async function X(e, n, t, r) {
403
419
  }
404
420
  return i;
405
421
  }
406
- async function ze(e, n, t, r) {
422
+ async function Ke(e, n, t, r) {
407
423
  const i = r.stack[r.stack.length - 1];
408
424
  if (e.attributes.xpointer)
409
425
  throw new Error(
@@ -426,20 +442,20 @@ async function ze(e, n, t, r) {
426
442
  throw new Error(
427
443
  `Circular xi:include: ${[...r.stack, a].join(" -> ")}`
428
444
  );
429
- if (r.stack.length >= Ee)
430
- throw new Error(`xi:include nesting exceeds ${Ee} levels`);
431
- const c = await Z(r, a);
445
+ if (r.stack.length >= Pe)
446
+ throw new Error(`xi:include nesting exceeds ${Pe} levels`);
447
+ const c = await q(r, a);
432
448
  if (c === void 0) {
433
- const l = Ht(e, t);
449
+ const l = Zt(e, t);
434
450
  if (l)
435
451
  return await X(l, n, t, r), l.children;
436
452
  throw new Error(`xi:include target not found: ${o} (in ${i})`);
437
453
  }
438
454
  if (r.files.includes(a) || r.files.push(a), r.bytes += c.length, e.attributes.parse === "text")
439
455
  return [{ type: "text", value: c }];
440
- let u;
456
+ let d;
441
457
  try {
442
- u = fe(r, a, c);
458
+ d = pe(r, a, c);
443
459
  } catch (l) {
444
460
  throw new Error(
445
461
  `Could not parse xi:include target ${a} as XML: ${l instanceof Error ? l.message : l}. (Included files must be well-formed, with a single root element.)`
@@ -447,24 +463,24 @@ async function ze(e, n, t, r) {
447
463
  }
448
464
  r.stack.push(a);
449
465
  try {
450
- await X(u, f.dirname(a), { "": "" }, r);
466
+ await X(d, f.dirname(a), { "": "" }, r);
451
467
  } finally {
452
468
  r.stack.pop();
453
469
  }
454
- const d = u.children.filter(
470
+ const u = d.children.filter(
455
471
  (l) => l.type === "element"
456
472
  );
457
- for (const l of d)
458
- We(l, a);
459
- return d;
473
+ for (const l of u)
474
+ ze(l, a);
475
+ return u;
460
476
  }
461
477
  function $e(e) {
462
478
  return e.name === "docinfo";
463
479
  }
464
- async function Wt(e, n, t, r = {}) {
480
+ async function qt(e, n, t, r = {}) {
465
481
  try {
466
- const i = f.resolve(n), s = fe(r, i, e).children.find(
467
- (d) => d.type === "element"
482
+ const i = f.resolve(n), s = pe(r, i, e).children.find(
483
+ (u) => u.type === "element"
468
484
  );
469
485
  if (!s)
470
486
  return;
@@ -474,24 +490,24 @@ async function Wt(e, n, t, r = {}) {
474
490
  stack: [i],
475
491
  files: [i],
476
492
  bytes: e.length
477
- }, u = K({ "": "" }, s);
478
- for (const d of s.children) {
479
- if (d.type !== "element")
493
+ }, d = J({ "": "" }, s);
494
+ for (const u of s.children) {
495
+ if (u.type !== "element")
480
496
  continue;
481
- const l = K(u, d);
482
- if ($e(d))
483
- return await X(d, a, l, c), B(d);
484
- if (He(d, l)) {
485
- const w = (await ze(
486
- d,
497
+ const l = J(d, u);
498
+ if ($e(u))
499
+ return await X(u, a, l, c), N(u);
500
+ if (Je(u, l)) {
501
+ const b = (await Ke(
502
+ u,
487
503
  a,
488
504
  l,
489
505
  c
490
506
  )).find(
491
- (T) => T.type === "element" && $e(T)
507
+ (y) => y.type === "element" && $e(y)
492
508
  );
493
- if (w)
494
- return B(w);
509
+ if (b)
510
+ return N(b);
495
511
  continue;
496
512
  }
497
513
  break;
@@ -501,24 +517,24 @@ async function Wt(e, n, t, r = {}) {
501
517
  return;
502
518
  }
503
519
  }
504
- function Ht(e, n) {
520
+ function Zt(e, n) {
505
521
  for (const t of e.children) {
506
522
  if (t.type !== "element")
507
523
  continue;
508
- const r = K(n, t), i = t.name.indexOf(":"), o = i === -1 ? "" : t.name.slice(0, i);
509
- if ((i === -1 ? t.name : t.name.slice(i + 1)) === "fallback" && r[o] === Xe)
524
+ const r = J(n, t), i = t.name.indexOf(":"), o = i === -1 ? "" : t.name.slice(0, i);
525
+ if ((i === -1 ? t.name : t.name.slice(i + 1)) === "fallback" && r[o] === We)
510
526
  return t;
511
527
  }
512
528
  }
513
- function Je(e) {
529
+ function Ve(e) {
514
530
  return typeof e == "object" && e !== null && e.type === "element";
515
531
  }
516
- function zt(e) {
532
+ function Qt(e) {
517
533
  return /^(pf|xhtml):/.test(e.name);
518
534
  }
519
- function Jt(e, n, t) {
535
+ function en(e, n, t) {
520
536
  const r = [];
521
- return Ke(e, n, t, (i, o, s, a) => {
537
+ return Ge(e, n, t, (i, o, s, a) => {
522
538
  r.push({
523
539
  id: o,
524
540
  file: s,
@@ -529,37 +545,37 @@ function Jt(e, n, t) {
529
545
  });
530
546
  }), r;
531
547
  }
532
- function Kt(e, n, t) {
548
+ function tn(e, n, t) {
533
549
  let r;
534
- return Ke(e, "", t, (i, o) => {
550
+ return Ge(e, "", t, (i, o) => {
535
551
  if (i === n)
536
552
  return r = o, !1;
537
553
  }), r;
538
554
  }
539
- function Ke(e, n, t, r) {
540
- const i = e.children.find(Je);
555
+ function Ge(e, n, t, r) {
556
+ const i = e.children.find(Ve);
541
557
  if (i) {
542
558
  const o = t?.parentId ?? "root";
543
- Ve(i, o, t?.position ?? 1, n, o, r);
559
+ Ye(i, o, t?.position ?? 1, n, o, r);
544
560
  }
545
561
  }
546
- function Ve(e, n, t, r, i, o) {
547
- const s = Ue(e) ?? r;
562
+ function Ye(e, n, t, r, i, o) {
563
+ const s = He(e) ?? r;
548
564
  let a, c;
549
- if (zt(e))
565
+ if (Qt(e))
550
566
  c = "root";
551
567
  else {
552
- const d = e.attributes.label ?? e.attributes["xml:id"];
553
- if (a = d ?? `${n}-${t}`, o(e, a, s, i) === !1)
568
+ const u = e.attributes.label ?? e.attributes["xml:id"];
569
+ if (a = u ?? `${n}-${t}`, o(e, a, s, i) === !1)
554
570
  return !1;
555
571
  c = a;
556
572
  }
557
- let u = 0;
558
- for (const d of e.children)
559
- if (Je(d) && (u += 1, !Ve(
560
- d,
561
- c,
573
+ let d = 0;
574
+ for (const u of e.children)
575
+ if (Ve(u) && (d += 1, !Ye(
562
576
  u,
577
+ c,
578
+ d,
563
579
  s,
564
580
  a ?? i,
565
581
  o
@@ -567,17 +583,17 @@ function Ve(e, n, t, r, i, o) {
567
583
  return !1;
568
584
  return !0;
569
585
  }
570
- function Wn(e, n) {
586
+ function tr(e, n) {
571
587
  let t;
572
588
  for (const r of e)
573
589
  r.line <= n && (t = r);
574
590
  return t ?? e[0];
575
591
  }
576
- function Vt(e) {
592
+ function nn(e) {
577
593
  const n = e.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!\[CDATA\[[\s\S]*?\]\]>/g, " ");
578
594
  return /<\s*slide(?:show)?[\s/>]/.test(n) ? "slides" : "html";
579
595
  }
580
- const Ge = /* @__PURE__ */ new Set([
596
+ const qe = /* @__PURE__ */ new Set([
581
597
  "colophon",
582
598
  "biography",
583
599
  "dedication",
@@ -597,89 +613,89 @@ const Ge = /* @__PURE__ */ new Set([
597
613
  "glossary",
598
614
  "worksheet",
599
615
  "handout"
600
- ]), Ye = /* @__PURE__ */ new Set([
616
+ ]), Ze = /* @__PURE__ */ new Set([
601
617
  "book",
602
618
  "article",
603
619
  "slideshow",
604
620
  "letter",
605
621
  "memo"
606
622
  ]), A = /* @__PURE__ */ new Set([
607
- ...Ye,
608
- ...Ge,
623
+ ...Ze,
624
+ ...qe,
609
625
  "part",
610
626
  "foreword",
611
627
  "frontmatter",
612
628
  "backmatter"
613
629
  ]);
614
- function Q(e) {
630
+ function Z(e) {
615
631
  return A.has(e.name);
616
632
  }
617
- const Gt = /* @__PURE__ */ new Set(["docinfo"]), qe = /* @__PURE__ */ new Set([
633
+ const rn = /* @__PURE__ */ new Set(["docinfo"]), Qe = /* @__PURE__ */ new Set([
618
634
  "title",
619
635
  "shorttitle",
620
636
  "plaintitle",
621
637
  "subtitle",
622
638
  "caption"
623
639
  ]);
624
- function x(e) {
640
+ function g(e) {
625
641
  return e.type === "element";
626
642
  }
627
- function Ze(e) {
643
+ function et(e) {
628
644
  return e.attributes["xml:id"] ?? void 0;
629
645
  }
630
- function V(e, n) {
646
+ function K(e, n) {
631
647
  for (const t of e.children) {
632
- if (!x(t)) continue;
633
- if (Ze(t) === n) return t;
634
- const r = V(t, n);
648
+ if (!g(t)) continue;
649
+ if (et(t) === n) return t;
650
+ const r = K(t, n);
635
651
  if (r) return r;
636
652
  }
637
653
  }
638
654
  function R(e, n) {
639
655
  for (const t of e.children) {
640
- if (!x(t)) continue;
656
+ if (!g(t)) continue;
641
657
  if (t === n) return [t];
642
658
  const r = R(t, n);
643
659
  if (r) return [t, ...r];
644
660
  }
645
661
  }
646
- function Qe(e, n, t, r) {
647
- return Ye.has(t) ? 0 : t === "frontmatter" || t === "backmatter" || t === "part" ? n === "book" && r ? 1 : 0 : Ge.has(t) ? e + 1 : e;
662
+ function tt(e, n, t, r) {
663
+ return Ze.has(t) ? 0 : t === "frontmatter" || t === "backmatter" || t === "part" ? n === "book" && r ? 1 : 0 : qe.has(t) ? e + 1 : e;
648
664
  }
649
- function G(e, n) {
665
+ function V(e, n) {
650
666
  let t = 0;
651
667
  for (const [r, i] of e.entries()) {
652
668
  const o = r === 0 ? void 0 : e[r - 1];
653
- t = Qe(t, o?.name, i.name, n);
669
+ t = tt(t, o?.name, i.name, n);
654
670
  }
655
671
  return t;
656
672
  }
657
- function pe(e) {
673
+ function ve(e) {
658
674
  return e?.name === "book" && e.children.some(
659
- (n) => x(n) && n.name === "part"
675
+ (n) => g(n) && n.name === "part"
660
676
  );
661
677
  }
662
678
  function O(e, n) {
663
679
  return e.children.some(
664
- (t) => x(t) && n.includes(t.name)
680
+ (t) => g(t) && n.includes(t.name)
665
681
  );
666
682
  }
667
- function Yt(e) {
683
+ function on(e) {
668
684
  if (!e) return 0;
669
685
  const n = e.name;
670
686
  if (n === "book") {
671
- const t = pe(e), r = t ? e.children.some(
672
- (o) => x(o) && o.name === "part" && O(o, ["chapter"])
687
+ const t = ve(e), r = t ? e.children.some(
688
+ (o) => g(o) && o.name === "part" && O(o, ["chapter"])
673
689
  ) : O(e, ["chapter"]), i = (t ? e.children.flatMap(
674
- (o) => x(o) && o.name === "part" ? o.children : []
690
+ (o) => g(o) && o.name === "part" ? o.children : []
675
691
  ) : e.children).some(
676
- (o) => x(o) && o.name === "chapter" && O(o, ["section"])
692
+ (o) => g(o) && o.name === "chapter" && O(o, ["section"])
677
693
  );
678
694
  return t && i ? 3 : t && r || i ? 2 : r ? 1 : 0;
679
695
  }
680
696
  if (n === "article") {
681
697
  const t = e.children.filter(
682
- (r) => x(r) && r.name === "section"
698
+ (r) => g(r) && r.name === "section"
683
699
  );
684
700
  if (t.some((r) => O(r, ["subsection"])))
685
701
  return 2;
@@ -688,21 +704,21 @@ function Yt(e) {
688
704
  }
689
705
  return 0;
690
706
  }
691
- function qt(e) {
692
- return e ? e.name === "book" ? pe(e) ? 3 : 2 : e.name === "article" && O(e, ["section", "worksheet", "handout"]) ? 1 : 0 : 0;
707
+ function sn(e) {
708
+ return e ? e.name === "book" ? ve(e) ? 3 : 2 : e.name === "article" && O(e, ["section", "worksheet", "handout"]) ? 1 : 0 : 0;
693
709
  }
694
- function me(e) {
695
- if (!qe.has(e.name)) {
696
- e.children = e.children.filter(x);
710
+ function be(e) {
711
+ if (!Qe.has(e.name)) {
712
+ e.children = e.children.filter(g);
697
713
  for (const n of e.children)
698
- me(n);
714
+ be(n);
699
715
  }
700
716
  }
701
- function Zt(e) {
717
+ function an(e) {
702
718
  for (const n of e.children)
703
- x(n) && !A.has(n.name) && me(n);
719
+ g(n) && !A.has(n.name) && be(n);
704
720
  }
705
- function Qt(e, n = !1) {
721
+ function cn(e, n = !1) {
706
722
  const t = /* @__PURE__ */ new Set(), r = (i) => {
707
723
  if (!(n && i !== e && A.has(i.name))) {
708
724
  if (i.name === "xref") {
@@ -716,16 +732,16 @@ function Qt(e, n = !1) {
716
732
  a && t.add(a);
717
733
  }
718
734
  for (const o of i.children)
719
- x(o) && r(o);
735
+ g(o) && r(o);
720
736
  }
721
737
  };
722
738
  return r(e), t;
723
739
  }
724
- function en(e, n, t) {
740
+ function ln(e, n, t) {
725
741
  const r = (i) => {
726
742
  for (const [o, s] of i.children.entries())
727
- if (x(s)) {
728
- if (Ze(s) === n)
743
+ if (g(s)) {
744
+ if (et(s) === n)
729
745
  return i.children[o] = t, !0;
730
746
  if (r(s)) return !0;
731
747
  }
@@ -733,88 +749,88 @@ function en(e, n, t) {
733
749
  };
734
750
  return r(e);
735
751
  }
736
- function et(e, n, t) {
752
+ function nt(e, n, t) {
737
753
  const r = t.contentKept.has(e), i = t.chain.has(e), o = [];
738
754
  for (const s of e.children) {
739
- if (!x(s)) {
755
+ if (!g(s)) {
740
756
  r && o.push(s);
741
757
  continue;
742
758
  }
743
- if (t.verbatim.has(s) || Gt.has(s.name) || qe.has(s.name))
759
+ if (t.verbatim.has(s) || rn.has(s.name) || Qe.has(s.name))
744
760
  o.push(s);
745
761
  else if (A.has(s.name)) {
746
- const a = Qe(
762
+ const a = tt(
747
763
  n,
748
764
  e.name,
749
765
  s.name,
750
766
  t.hasParts
751
767
  );
752
- (t.chain.has(s) || i || a <= t.tocLevel) && (et(s, a, t), o.push(s));
768
+ (t.chain.has(s) || i || a <= t.tocLevel) && (nt(s, a, t), o.push(s));
753
769
  } else r && o.push(s);
754
770
  }
755
771
  e.children = o;
756
772
  }
757
- function tn(e, n, t = {}) {
758
- const r = V(e, n);
773
+ function un(e, n, t = {}) {
774
+ const r = K(e, n);
759
775
  if (!r) return;
760
776
  const i = R(e, r);
761
777
  if (!i) return;
762
778
  const o = (t.collapseChildren ?? !1) && r.children.some(
763
- (p) => x(p) && A.has(p.name)
764
- ), s = (p) => p.name === "pretext" || p.name === "mathbook", a = i.filter((p) => !s(p)), c = a[0], u = pe(c), d = G(a, u), l = (p) => {
765
- const S = R(e, p)?.filter((b) => !s(b)) ?? [];
766
- return G(S, u);
767
- }, m = t.maxNumberingLevel ?? 1 / 0, w = Math.min(
768
- t.numberingLevel ?? qt(c),
779
+ (p) => g(p) && A.has(p.name)
780
+ ), s = (p) => p.name === "pretext" || p.name === "mathbook", a = i.filter((p) => !s(p)), c = a[0], d = ve(c), u = V(a, d), l = (p) => {
781
+ const T = R(e, p)?.filter((v) => !s(v)) ?? [];
782
+ return V(T, d);
783
+ }, m = t.maxNumberingLevel ?? 1 / 0, b = Math.min(
784
+ t.numberingLevel ?? sn(c),
769
785
  m
770
- ), T = t.tocLevel ?? Yt(c), y = {
786
+ ), y = t.tocLevel ?? on(c), x = {
771
787
  verbatim: /* @__PURE__ */ new Set(),
772
788
  chain: new Set(i),
773
789
  contentKept: /* @__PURE__ */ new Set(),
774
- tocLevel: T,
775
- hasParts: u
776
- }, M = /* @__PURE__ */ new Set(), P = /* @__PURE__ */ new Set();
777
- o ? y.contentKept.add(r) : y.verbatim.add(r);
778
- const ee = (p) => {
779
- const S = R(e, p);
780
- if (!S) return;
781
- const b = S.filter((v) => A.has(v.name)), k = b[b.length - 1];
782
- if (!k || k === r) return;
783
- if (i.includes(k)) {
784
- y.contentKept.add(k), P.add(k);
790
+ tocLevel: y,
791
+ hasParts: d
792
+ }, j = /* @__PURE__ */ new Set(), $ = /* @__PURE__ */ new Set();
793
+ o ? x.contentKept.add(r) : x.verbatim.add(r);
794
+ const Q = (p) => {
795
+ const T = R(e, p);
796
+ if (!T) return;
797
+ const v = T.filter((S) => A.has(S.name)), I = v[v.length - 1];
798
+ if (!I || I === r) return;
799
+ if (i.includes(I)) {
800
+ x.contentKept.add(I), $.add(I);
785
801
  return;
786
802
  }
787
- let I = k;
788
- for (let v = b.length - 1; v >= 0 && !(l(b[v]) <= w || i.includes(b[v - 1])); v--)
789
- I = b[v - 1] ?? I;
790
- if (!y.verbatim.has(I)) {
791
- y.verbatim.add(I), M.add(I);
792
- for (const v of R(e, I) ?? []) y.chain.add(v);
803
+ let P = I;
804
+ for (let S = v.length - 1; S >= 0 && !(l(v[S]) <= b || i.includes(v[S - 1])); S--)
805
+ P = v[S - 1] ?? P;
806
+ if (!x.verbatim.has(P)) {
807
+ x.verbatim.add(P), j.add(P);
808
+ for (const S of R(e, P) ?? []) x.chain.add(S);
793
809
  }
794
810
  };
795
- for (const p of Qt(r, o)) {
796
- const S = V(e, p);
797
- S && S !== r && ee(S);
811
+ for (const p of cn(r, o)) {
812
+ const T = K(e, p);
813
+ T && T !== r && Q(T);
798
814
  }
799
- for (const p of [...y.chain]) {
800
- if (!A.has(p.name) || l(p) <= w)
815
+ for (const p of [...x.chain]) {
816
+ if (!A.has(p.name) || l(p) <= b)
801
817
  continue;
802
- const S = R(e, p)?.at(-2);
803
- if (S)
804
- for (const b of S.children) {
805
- if (b === p) break;
806
- !x(b) || !A.has(b.name) || y.verbatim.has(b) || y.chain.has(b) || (y.verbatim.add(b), M.add(b));
818
+ const T = R(e, p)?.at(-2);
819
+ if (T)
820
+ for (const v of T.children) {
821
+ if (v === p) break;
822
+ !g(v) || !A.has(v.name) || x.verbatim.has(v) || x.chain.has(v) || (x.verbatim.add(v), j.add(v));
807
823
  }
808
824
  }
809
- const j = e.children.find(x);
810
- j && et(j, 0, y);
811
- for (const p of M)
812
- me(p);
813
- for (const p of P)
814
- Zt(p);
815
- return { content: B(e), divisionId: n, level: d, collapsed: o };
816
- }
817
- class nn {
825
+ const C = e.children.find(g);
826
+ C && nt(C, 0, x);
827
+ for (const p of j)
828
+ be(p);
829
+ for (const p of $)
830
+ an(p);
831
+ return { content: N(e), divisionId: n, level: u, collapsed: o };
832
+ }
833
+ class dn {
818
834
  entries = /* @__PURE__ */ new Map();
819
835
  maxEntries;
820
836
  /** Cumulative hit/miss counts, for diagnostics and tests. */
@@ -834,15 +850,15 @@ class nn {
834
850
  parse(n, t) {
835
851
  const r = this.entries.get(n);
836
852
  if (r && r.content === t)
837
- return this.hits += 1, this.entries.delete(n), this.entries.set(n, r), ce(r.tree);
853
+ return this.hits += 1, this.entries.delete(n), this.entries.set(n, r), le(r.tree);
838
854
  this.misses += 1;
839
- const i = U(t);
855
+ const i = B(t);
840
856
  for (this.entries.delete(n), this.entries.set(n, { content: t, tree: i }); this.entries.size > this.maxEntries; ) {
841
857
  const o = this.entries.keys().next().value;
842
858
  if (o === void 0) break;
843
859
  this.entries.delete(o);
844
860
  }
845
- return ce(i);
861
+ return le(i);
846
862
  }
847
863
  /** Number of files currently held. */
848
864
  get size() {
@@ -853,86 +869,86 @@ class nn {
853
869
  n === void 0 ? this.entries.clear() : this.entries.delete(n);
854
870
  }
855
871
  }
856
- function ce(e) {
872
+ function le(e) {
857
873
  const n = { ...e };
858
- return n.attributes && (n.attributes = { ...n.attributes }), n.children && (n.children = n.children.map((t) => ce(t))), n.data && (n.data = { ...n.data }), n;
874
+ return n.attributes && (n.attributes = { ...n.attributes }), n.children && (n.children = n.children.map((t) => le(t))), n.data && (n.data = { ...n.data }), n;
859
875
  }
860
- function Y(e) {
876
+ function G(e) {
861
877
  return typeof e == "object" && e !== null && e.type === "element";
862
878
  }
863
- function rn(e) {
879
+ function fn(e) {
864
880
  for (let n = e.length - 1; n >= 0; n--)
865
- if (Q(e[n])) return e[n];
881
+ if (Z(e[n])) return e[n];
866
882
  }
867
- function on(e, n, t) {
883
+ function hn(e, n, t) {
868
884
  const r = [], i = (s, a, c) => {
869
- const u = Ue(s) ?? a, d = [...c, s];
870
- u === t && Q(s) && r.push({ element: s, chain: d });
885
+ const d = He(s) ?? a, u = [...c, s];
886
+ d === t && Z(s) && r.push({ element: s, chain: u });
871
887
  for (const l of s.children)
872
- Y(l) && i(l, u, d);
873
- }, o = e.children.find(Y);
888
+ G(l) && i(l, d, u);
889
+ }, o = e.children.find(G);
874
890
  return o && i(o, n, []), r;
875
891
  }
876
- function sn(e, n, t, r) {
877
- const i = on(e, n, t);
892
+ function pn(e, n, t, r) {
893
+ const i = hn(e, n, t);
878
894
  let o, s, a;
879
895
  for (const { element: c } of i) {
880
- const u = c.position?.start.line, d = c.position?.end.line ?? u;
881
- u === void 0 || d === void 0 || (u <= r && r <= d ? o = c : u > r ? s ??= c : a = c);
896
+ const d = c.position?.start.line, u = c.position?.end.line ?? d;
897
+ d === void 0 || u === void 0 || (d <= r && r <= u ? o = c : d > r ? s ??= c : a = c);
882
898
  }
883
899
  return o ?? s ?? a;
884
900
  }
885
- function an(e, n, t) {
901
+ function mn(e, n, t) {
886
902
  let r;
887
903
  if (n.id !== void 0) {
888
- const l = V(e, n.id), m = l && R(e, l);
889
- r = m && rn(m);
904
+ const l = K(e, n.id), m = l && R(e, l);
905
+ r = m && fn(m);
890
906
  } else if (n.line !== void 0) {
891
907
  const l = f.resolve(t), m = f.resolve(n.file ?? t);
892
- r = sn(e, l, m, n.line);
908
+ r = pn(e, l, m, n.line);
893
909
  }
894
910
  if (!r) return;
895
911
  const i = n.level ?? 1 / 0;
896
912
  let o = !1;
897
913
  const a = (R(e, r) ?? [r]).filter(
898
914
  (l) => l.name !== "pretext" && l.name !== "mathbook"
899
- ), c = a[0], u = c?.name === "book" && c.children.some(
900
- (l) => Y(l) && l.name === "part"
901
- ), d = G(a, u);
902
- if (d > i)
915
+ ), c = a[0], d = c?.name === "book" && c.children.some(
916
+ (l) => G(l) && l.name === "part"
917
+ ), u = V(a, d);
918
+ if (u > i)
903
919
  for (let l = 0; l < a.length; l++) {
904
920
  const m = a[l];
905
- if (Q(m) && G(a.slice(0, l + 1), u) >= i) {
921
+ if (Z(m) && V(a.slice(0, l + 1), d) >= i) {
906
922
  r = m;
907
923
  break;
908
924
  }
909
925
  }
910
- else d < i && (o = !0);
911
- return { element: r, id: tt(e, r), collapse: o };
926
+ else u < i && (o = !0);
927
+ return { element: r, id: rt(e, r), collapse: o };
912
928
  }
913
- function tt(e, n) {
929
+ function rt(e, n) {
914
930
  const t = n.attributes["xml:id"];
915
931
  if (t) return t;
916
- const r = Kt(e, n) ?? "root-1";
932
+ const r = tn(e, n) ?? "root-1";
917
933
  return n.attributes["xml:id"] = r, r;
918
934
  }
919
- function q(e) {
935
+ function Y(e) {
920
936
  let n = 0;
921
937
  for (const t of e.children)
922
- Y(t) && (n += 1 + q(t));
938
+ G(t) && (n += 1 + Y(t));
923
939
  return n;
924
940
  }
925
- const cn = "This live preview shows a single division, so links into the rest of the document do not work here.", ln = /<a\b([^>]*)>/g, un = /\sid="([^"]*)"/g, ne = /\shref="([^"]*)"/, dn = /\\href\{([^{}]*)\}/g, Pe = /\stitle="([^"]*)"/;
926
- function fn(e) {
941
+ const vn = "This live preview shows a single division, so links into the rest of the document do not work here.", bn = /<a\b([^>]*)>/g, wn = /\sid="([^"]*)"/g, re = /\shref="([^"]*)"/, gn = /\\href\{([^{}]*)\}/g, Ie = /\stitle="([^"]*)"/;
942
+ function xn(e) {
927
943
  const n = /* @__PURE__ */ new Set();
928
- for (const t of e.matchAll(un))
944
+ for (const t of e.matchAll(wn))
929
945
  n.add(t[1]);
930
946
  return n;
931
947
  }
932
- function re(e) {
948
+ function ie(e) {
933
949
  return e.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
934
950
  }
935
- function Ie(e, n) {
951
+ function Le(e, n) {
936
952
  if (e.startsWith("#") || e === "") return { kind: "keep" };
937
953
  if (/^[a-z][a-z0-9+.-]*:/i.test(e) || e.startsWith("//"))
938
954
  return { kind: "keep" };
@@ -941,89 +957,89 @@ function Ie(e, n) {
941
957
  const o = e.slice(t + 1);
942
958
  return n.has(o) && o !== "" ? { kind: "same-page", id: o } : { kind: "off-page", division: i, ...o ? { id: o } : {} };
943
959
  }
944
- function hn(e, n = {}) {
945
- const t = n.offPageMessage ?? cn, r = fn(e);
946
- return e.replace(ln, (o, s) => {
947
- const a = ne.exec(s);
960
+ function yn(e, n = {}) {
961
+ const t = n.offPageMessage ?? vn, r = xn(e);
962
+ return e.replace(bn, (o, s) => {
963
+ const a = re.exec(s);
948
964
  if (!a) return o;
949
- const c = Ie(a[1], r);
965
+ const c = Le(a[1], r);
950
966
  if (c.kind === "keep") return o;
951
967
  if (c.kind === "same-page")
952
- return `<a${s.replace(ne, ` href="#${c.id}"`)}>`;
953
- const u = Pe.exec(s), d = re(t), l = u ? `${u[1]} — ${d}` : d, w = s.replace(ne, "").replace(Pe, ""), T = ` data-ptx-division="${re(c.division)}"` + (c.id ? ` data-ptx-id="${re(c.id)}"` : "");
954
- return `<a${w} title="${l}" aria-disabled="true" style="cursor:default"${T}>`;
955
- }).replace(dn, (o, s) => {
956
- const a = Ie(s, r);
968
+ return `<a${s.replace(re, ` href="#${c.id}"`)}>`;
969
+ const d = Ie.exec(s), u = ie(t), l = d ? `${d[1]} — ${u}` : u, b = s.replace(re, "").replace(Ie, ""), y = ` data-ptx-division="${ie(c.division)}"` + (c.id ? ` data-ptx-id="${ie(c.id)}"` : "");
970
+ return `<a${b} title="${l}" aria-disabled="true" style="cursor:default"${y}>`;
971
+ }).replace(gn, (o, s) => {
972
+ const a = Le(s, r);
957
973
  return a.kind === "same-page" ? `\\href{#${a.id}}` : o;
958
974
  });
959
975
  }
960
- function pn() {
961
- return yt(se(), "xsl");
976
+ function Tn() {
977
+ return It(ae(), "xsl");
962
978
  }
963
- function mn() {
979
+ function Sn() {
964
980
  return "Suspending" in WebAssembly;
965
981
  }
966
- function bn() {
967
- if (!mn())
982
+ function En() {
983
+ if (!Sn())
968
984
  throw new Error(
969
985
  "WebAssembly JSPI is not enabled. Run Node with --experimental-wasm-jspi (or use the pretext-html CLI, which re-launches itself with the flag)."
970
986
  );
971
987
  }
972
- function F(e) {
988
+ function U(e) {
973
989
  return e.includes("'") ? e.includes('"') ? `concat(${e.split("'").map((t) => `'${t}'`).join(`, "'", `)})` : `"${e}"` : `'${e}'`;
974
990
  }
975
- function wn(e) {
991
+ function kn(e) {
976
992
  return e.replace(
977
993
  /from '\.\/(https:\/\/[^']+)'/g,
978
994
  (n, t) => `from '${t}'`
979
995
  );
980
996
  }
981
- const vn = `https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@${Oe}/dist/`, gn = {
982
- "cli.version": Oe,
997
+ const Pn = `https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@${_e}/dist/`, $n = {
998
+ "cli.version": _e,
983
999
  // Colon-delimited: pretext-runestone.xsl splits them with str:tokenize.
984
- "rs-js": St.join(":"),
985
- "rs-css": kt.join(":"),
986
- "rs-version": Tt
1000
+ "rs-js": Dt.join(":"),
1001
+ "rs-css": Rt.join(":"),
1002
+ "rs-version": Lt
987
1003
  };
988
- function xn(e) {
1004
+ function In(e) {
989
1005
  return e.replace(
990
1006
  /(<link\b[^>]*\bhref=["'])_static\//gi,
991
- `$1${vn}_static/`
1007
+ `$1${Pn}_static/`
992
1008
  );
993
1009
  }
994
- function yn(e) {
1010
+ function Ln(e) {
995
1011
  return e.slice(0, 65536).replace(/<\?[\s\S]*?\?>/g, " ").replace(/<!--[\s\S]*?-->/g, " ").replace(/<!DOCTYPE[^>]*>/gi, " ").match(/<\s*([A-Za-z][\w:-]*)/)?.[1];
996
1012
  }
997
- let Tn;
998
- function Sn() {
999
- return Tn ??= new nn();
1013
+ let Dn;
1014
+ function Rn() {
1015
+ return Dn ??= new dn();
1000
1016
  }
1001
- function nt(e) {
1017
+ function it(e) {
1002
1018
  const n = e.files ? new Map(
1003
1019
  Object.entries(e.files).map(([o, s]) => [
1004
1020
  f.resolve(o),
1005
1021
  s
1006
1022
  ])
1007
- ) : void 0, t = e.readSource, r = n || t ? async (o) => n?.get(o) ?? await t?.(o) : void 0, i = e.cache === !1 ? void 0 : e.cache ?? Sn();
1023
+ ) : void 0, t = e.readSource, r = n || t ? async (o) => n?.get(o) ?? await t?.(o) : void 0, i = e.cache === !1 ? void 0 : e.cache ?? Rn();
1008
1024
  return { readSource: r, cache: i };
1009
1025
  }
1010
- async function le(e, n) {
1011
- const t = await Z(e, n);
1026
+ async function ue(e, n) {
1027
+ const t = await q(e, n);
1012
1028
  if (t === void 0)
1013
1029
  throw new Error(
1014
1030
  `Could not read ${n}. (In the browser build only absolute URLs are readable — pass sourceContent instead of relying on sourcePath.)`
1015
1031
  );
1016
1032
  return t;
1017
1033
  }
1018
- async function kn(e, n, t) {
1019
- const r = f.resolve(e), i = await Z(t, r);
1034
+ async function An(e, n, t) {
1035
+ const r = f.resolve(e), i = await q(t, r);
1020
1036
  if (i !== void 0)
1021
- return Wt(i, r, n, t);
1037
+ return qt(i, r, n, t);
1022
1038
  }
1023
- async function Hn(e) {
1024
- const n = nt(e), t = f.resolve(e.sourcePath), r = f.resolve(
1039
+ async function nr(e) {
1040
+ const n = it(e), t = f.resolve(e.sourcePath), r = f.resolve(
1025
1041
  e.projectDir ?? f.dirname(t)
1026
- ), i = e.sourceContent ?? await le(n, t), o = await he(
1042
+ ), i = e.sourceContent ?? await ue(n, t), o = await me(
1027
1043
  i,
1028
1044
  t,
1029
1045
  r,
@@ -1031,11 +1047,11 @@ async function Hn(e) {
1031
1047
  );
1032
1048
  return {
1033
1049
  bytes: o.bytes,
1034
- elements: q(o.tree),
1050
+ elements: Y(o.tree),
1035
1051
  files: o.files
1036
1052
  };
1037
1053
  }
1038
- function En(e, n, t, r) {
1054
+ function jn(e, n, t, r) {
1039
1055
  const i = e.replace(/^\uFEFF/, "").replace(/<\?xml[\s\S]*?\?>/, "").replace(/<!DOCTYPE[^>]*>/i, ""), o = t === "slides" ? "slideshow" : n === "chapter" || n === "part" ? "book" : "article";
1040
1056
  return `<pretext>
1041
1057
  ${r?.trim() ? `${r.trim()}
@@ -1046,14 +1062,14 @@ ${i}
1046
1062
  </pretext>
1047
1063
  `;
1048
1064
  }
1049
- async function $n(e, n, t, r, i, o) {
1065
+ async function Cn(e, n, t, r, i, o) {
1050
1066
  const s = e.attributes["xml:id"];
1051
1067
  if (!s) return;
1052
- const a = f.resolve(t), c = i ?? await Z(o, a);
1068
+ const a = f.resolve(t), c = i ?? await q(o, a);
1053
1069
  if (c === void 0) return;
1054
- let u, d, l;
1070
+ let d, u, l;
1055
1071
  try {
1056
- ({ tree: u, files: d, bytes: l } = await he(
1072
+ ({ tree: d, files: u, bytes: l } = await me(
1057
1073
  c,
1058
1074
  a,
1059
1075
  r,
@@ -1062,78 +1078,78 @@ async function $n(e, n, t, r, i, o) {
1062
1078
  } catch {
1063
1079
  return;
1064
1080
  }
1065
- if (We(e, n), !!en(u, s, e))
1066
- return d.includes(n) || d.push(n), { tree: u, divisionId: s, files: d, bytes: l };
1081
+ if (ze(e, n), !!ln(d, s, e))
1082
+ return u.includes(n) || u.push(n), { tree: d, divisionId: s, files: u, bytes: l };
1067
1083
  }
1068
- let rt = !1;
1069
- function Pn(e) {
1084
+ let ot = !1;
1085
+ function Mn(e) {
1070
1086
  return e instanceof Error && /\bAborted\(/.test(e.message);
1071
1087
  }
1072
- function In(e) {
1088
+ function On(e) {
1073
1089
  return e instanceof Error && /memory access|out of bounds/i.test(e.message);
1074
1090
  }
1075
- function Ln() {
1076
- if (rt)
1091
+ function _n() {
1092
+ if (ot)
1077
1093
  throw new Error(
1078
1094
  "The WebAssembly renderer aborted earlier in this process and cannot be reused. Restart the process (or reload the page) to render again."
1079
1095
  );
1080
1096
  }
1081
- function Le(e) {
1082
- if (Pn(e))
1083
- throw rt = !0, new Error(
1097
+ function De(e) {
1098
+ if (Mn(e))
1099
+ throw ot = !0, new Error(
1084
1100
  "The WebAssembly renderer aborted and cannot be reused. Restart the process (or reload the page) to render again.",
1085
1101
  { cause: e }
1086
1102
  );
1087
- if (In(e))
1103
+ if (On(e))
1088
1104
  throw new Error(
1089
1105
  "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.",
1090
1106
  { cause: e }
1091
1107
  );
1092
1108
  }
1093
- let ie;
1094
- async function it() {
1095
- return ie || (ie = (async () => {
1109
+ let oe;
1110
+ async function st() {
1111
+ return oe || (oe = (async () => {
1096
1112
  const [e, n] = await Promise.all([
1097
1113
  import("@pretextbook/libxslt-wasm"),
1098
1114
  import("@pretextbook/libxslt-wasm/exslt")
1099
1115
  ]);
1100
1116
  return n.registerAll(), e;
1101
- })()), ie;
1117
+ })()), oe;
1102
1118
  }
1103
- const oe = /* @__PURE__ */ new Map(), Dn = {
1119
+ const se = /* @__PURE__ */ new Map(), Nn = {
1104
1120
  html: "preview-html.xsl",
1105
1121
  slides: "preview-revealjs.xsl"
1106
1122
  };
1107
- async function Rn(e, n) {
1108
- const t = Dn[n], r = `${n}\0${e}`;
1109
- let i = oe.get(r);
1123
+ async function Bn(e, n) {
1124
+ const t = Nn[n], r = `${n}\0${e}`;
1125
+ let i = se.get(r);
1110
1126
  return i || (i = (async () => {
1111
- const { XmlDocument: o, XsltStylesheet: s } = await it(), a = Fe(e), c = await je(se(), `/${t}`);
1127
+ const { XmlDocument: o, XsltStylesheet: s } = await st(), a = Ue(e), c = await Me(ae(), `/${t}`);
1112
1128
  if (c === void 0)
1113
1129
  throw new Error(
1114
- `Could not read ${t} from ${se()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
1130
+ `Could not read ${t} from ${ae()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
1115
1131
  );
1116
- const u = new TextDecoder().decode(c), d = await o.fromString(u, {
1132
+ const d = new TextDecoder().decode(c), u = await o.fromString(d, {
1117
1133
  url: `${a}/${t}`,
1118
1134
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
1119
1135
  });
1120
- return s.fromXmlDocument(d);
1121
- })(), oe.set(r, i), i.catch(() => oe.delete(r))), i;
1122
- }
1123
- let De = Promise.resolve();
1124
- function An(e) {
1125
- const n = De.then(
1126
- () => Re(e),
1127
- () => Re(e)
1136
+ return s.fromXmlDocument(u);
1137
+ })(), se.set(r, i), i.catch(() => se.delete(r))), i;
1138
+ }
1139
+ let Re = Promise.resolve();
1140
+ function Fn(e) {
1141
+ const n = Re.then(
1142
+ () => Ae(e),
1143
+ () => Ae(e)
1128
1144
  );
1129
- return De = n.catch(() => {
1145
+ return Re = n.catch(() => {
1130
1146
  }), n;
1131
1147
  }
1132
- async function Re(e) {
1133
- bn(), Ln();
1134
- const { XmlDocument: n } = await it(), t = nt(e), r = f.resolve(e.sourcePath), i = f.resolve(
1148
+ async function Ae(e) {
1149
+ En(), _n();
1150
+ const { XmlDocument: n } = await st(), t = it(e), r = f.resolve(e.sourcePath), i = f.resolve(
1135
1151
  e.projectDir ?? f.dirname(r)
1136
- ), o = e.sourceContent ?? await le(t, r), s = f.relative(i, r);
1152
+ ), o = e.sourceContent ?? await ue(t, r), s = f.relative(i, r);
1137
1153
  if (s.startsWith(".."))
1138
1154
  throw new Error(
1139
1155
  `sourcePath (${r}) must live inside projectDir (${i})`
@@ -1141,145 +1157,152 @@ async function Re(e) {
1141
1157
  const a = f.relative(
1142
1158
  i,
1143
1159
  f.resolve(e.mainSourcePath ?? r)
1144
- ), c = a.startsWith("..") ? s : a, u = Fe(i);
1160
+ ), c = a.startsWith("..") ? s : a, d = Ue(i);
1145
1161
  try {
1146
- let d, l = `${u}/__pretext-preview-publication.xml`;
1162
+ let u, l = `${d}/__pretext-preview-publication.xml`;
1147
1163
  if (e.publicationPath) {
1148
1164
  const h = f.resolve(e.publicationPath);
1149
- d = await le(t, h);
1150
- const g = f.relative(i, h);
1151
- g.startsWith("..") || (l = `${u}/${g.split(f.sep).join("/")}`);
1165
+ u = await ue(t, h);
1166
+ const w = f.relative(i, h);
1167
+ w.startsWith("..") || (l = `${d}/${w.split(f.sep).join("/")}`);
1152
1168
  }
1153
- const m = await he(
1169
+ const m = await me(
1154
1170
  o,
1155
1171
  r,
1156
1172
  i,
1157
1173
  t
1158
1174
  );
1159
- let w = m.tree, T = m.content, y = m.files, M = m.bytes;
1160
- const P = e.target ?? Vt(T), ee = await Rn(e.xslDir ?? pn(), P), j = Ft(d, {
1175
+ let b = m.tree, y = m.content, x = m.files, j = m.bytes;
1176
+ const $ = e.target ?? nn(y), Q = await Bn(e.xslDir ?? Tn(), $), C = Xe(u, {
1161
1177
  cssTheme: e.cssTheme,
1162
1178
  revealTheme: e.revealTheme,
1163
- target: P
1179
+ target: $
1164
1180
  });
1165
- Ct(l, j);
1166
- const p = Ut(j), S = f.dirname(f.resolve(i, c)), b = p.external !== void 0 && p.generated !== void 0 ? {
1167
- external: f.resolve(S, p.external),
1168
- generated: f.resolve(S, p.generated)
1169
- } : void 0, k = yn(T);
1170
- let I = { parentId: "root", position: 1 }, v, be = r, W;
1171
- const we = (h, g) => {
1172
- W = { bytes: M, elements: q(h), files: y };
1173
- const E = e.subtree ? an(h, e.subtree, r) : void 0, D = E?.id ?? g;
1181
+ Xt(l, C);
1182
+ const p = Ln(y);
1183
+ let T = { parentId: "root", position: 1 }, v, I = r, P, S;
1184
+ const we = (h, w) => {
1185
+ P = { bytes: j, elements: Y(h), files: x };
1186
+ const k = e.subtree ? mn(h, e.subtree, r) : void 0, D = k?.id ?? w;
1174
1187
  if (!D) return !1;
1175
- const H = e.subtree?.wholeDocumentUpTo;
1176
- if (H !== void 0 && W.elements <= H) return !1;
1177
- const ot = E?.collapse && E.element ? E.element.children.filter(
1178
- (z) => z.type === "element" && Q(z)
1179
- ).map((z) => tt(h, z)) : [], C = tn(h, D, {
1180
- collapseChildren: E?.collapse,
1181
- ...Xt(j)
1188
+ const W = e.subtree?.wholeDocumentUpTo;
1189
+ if (W !== void 0 && P.elements <= W) return !1;
1190
+ const ct = k?.collapse && k.element ? k.element.children.filter(
1191
+ (H) => H.type === "element" && Z(H)
1192
+ ).map((H) => rt(h, H)) : [], M = un(h, D, {
1193
+ collapseChildren: k?.collapse,
1194
+ ...Gt(C)
1182
1195
  });
1183
- return C ? (T = C.content, v = {
1184
- id: C.divisionId,
1185
- level: C.level,
1186
- collapsed: C.collapsed,
1187
- children: C.collapsed ? ot : []
1196
+ return M ? (y = M.content, v = {
1197
+ id: M.divisionId,
1198
+ level: M.level,
1199
+ collapsed: M.collapsed,
1200
+ children: M.collapsed ? ct : []
1188
1201
  }, !0) : !1;
1189
1202
  };
1190
- if (k !== "pretext" && k !== "mathbook") {
1203
+ if (p !== "pretext" && p !== "mathbook") {
1191
1204
  if (!e.fragment)
1192
1205
  throw new Error(
1193
- `The document root is <${k ?? "?"}>, not <pretext> — this looks like an xi:included fragment. Render the project's main source file instead, or pass the fragment option.`
1206
+ `The document root is <${p ?? "?"}>, not <pretext> — this looks like an xi:included fragment. Render the project's main source file instead, or pass the fragment option.`
1194
1207
  );
1195
1208
  let h = !1;
1196
1209
  if (e.contextSourcePath || e.contextSourceContent) {
1197
- const g = e.contextSourcePath ?? f.join(f.dirname(r), "__pretext-preview-context.ptx"), E = w.children.find(
1198
- (H) => H.type === "element"
1199
- ), D = E ? await $n(
1200
- E,
1210
+ const w = e.contextSourcePath ?? f.join(f.dirname(r), "__pretext-preview-context.ptx"), k = b.children.find(
1211
+ (W) => W.type === "element"
1212
+ ), D = k ? await Cn(
1213
+ k,
1201
1214
  r,
1202
- g,
1215
+ w,
1203
1216
  i,
1204
1217
  e.contextSourceContent,
1205
1218
  t
1206
1219
  ) : void 0;
1207
- D && (h = !0, w = D.tree, y = D.files, M = D.bytes, be = f.resolve(g), we(w, D.divisionId) || (T = B(w)));
1220
+ D && (h = !0, b = D.tree, S = z(b), x = D.files, j = D.bytes, I = f.resolve(w), we(b, D.divisionId) || (y = N(b)));
1208
1221
  }
1209
1222
  if (!h) {
1210
- const g = e.docinfo ?? (e.docinfoSourcePath ? await kn(
1223
+ const w = e.docinfo ?? (e.docinfoSourcePath ? await An(
1211
1224
  e.docinfoSourcePath,
1212
1225
  i,
1213
1226
  t
1214
1227
  ) : void 0);
1215
- T = En(
1216
- T,
1217
- k,
1218
- P,
1219
- g
1220
- ), I = { parentId: g?.trim() ? "root-1-2" : "root-1-1", position: 2 };
1228
+ y = jn(
1229
+ y,
1230
+ p,
1231
+ $,
1232
+ w
1233
+ ), S = w === void 0 ? void 0 : z(w), T = { parentId: w?.trim() ? "root-1-2" : "root-1-1", position: 2 };
1221
1234
  }
1222
- } else e.subtree && we(w);
1223
- W ??= { bytes: M, elements: q(w), files: y };
1224
- const ve = e.sourceMap ? Jt(w, be, I) : void 0, ge = await n.fromString(T, {
1225
- url: `${u}/${c.split(f.sep).join("/")}`,
1235
+ } else
1236
+ S = z(b), e.subtree && we(b);
1237
+ P ??= { bytes: j, elements: Y(b), files: x };
1238
+ const ee = Yt(C, S), ge = f.dirname(f.resolve(i, c)), at = {
1239
+ generated: f.resolve(ge, ee.generated),
1240
+ ...ee.external !== void 0 ? { external: f.resolve(ge, ee.external) } : {}
1241
+ }, xe = e.sourceMap ? en(b, I, T) : void 0, ye = await n.fromString(y, {
1242
+ url: `${d}/${c.split(f.sep).join("/")}`,
1226
1243
  options: { noEnt: !0, dtdLoad: !0, huge: !0 }
1227
- }), N = {
1228
- publisher: F(l)
1244
+ }), F = {
1245
+ publisher: U(l)
1229
1246
  };
1230
- for (const [h, g] of Object.entries(gn))
1231
- N[h] = F(g);
1232
- v && (N.subtree = F(v.id), N["subtree-level"] = F(
1247
+ for (const [h, w] of Object.entries($n))
1248
+ F[h] = U(w);
1249
+ v && (F.subtree = U(v.id), F["subtree-level"] = U(
1233
1250
  String(v.level + (v.collapsed ? 1 : 0))
1234
1251
  ));
1235
- for (const [h, g] of Object.entries(e.stringParams ?? {}))
1236
- N[h] = F(g);
1252
+ for (const [h, w] of Object.entries(e.stringParams ?? {}))
1253
+ F[h] = U(w);
1237
1254
  let te;
1238
1255
  try {
1239
- te = await ee.apply(ge, N);
1256
+ te = await Q.apply(ye, F);
1240
1257
  } catch (h) {
1241
- throw Le(h), new Error(
1258
+ throw De(h), new Error(
1242
1259
  "PreTeXt XSLT transform failed; see the PTX:ERROR/PTX:FATAL messages on stderr for details.",
1243
1260
  { cause: h }
1244
1261
  );
1245
1262
  } finally {
1246
- ge.delete();
1263
+ ye.delete();
1247
1264
  }
1248
1265
  try {
1249
- let h = wn(te.toHtmlString());
1250
- h = hn(h, {
1266
+ let h = kn(te.toHtmlString());
1267
+ h = yn(h, {
1251
1268
  ...e.offPageMessage !== void 0 ? { offPageMessage: e.offPageMessage } : {}
1252
- }), (e.openKnowls ?? !0) && (h = Lt(h)), P === "slides" ? (h = xn(h), h = lt(h, e.revealView ?? "scroll", {
1269
+ }), (e.openKnowls ?? !0) && (h = Ot(h)), $ === "slides" ? (h = In(h), h = vt(h, e.revealView ?? "scroll", {
1253
1270
  zoom: e.revealZoom
1254
- })) : e.theme && (h = ut(h, e.theme)), e.previewBanner && (h = gt(h, e.previewBanner));
1255
- const g = P === "slides" ? [] : st(h), E = at(g, k);
1256
- return e.printPreview && (h = Me(h, e.printPreview)), {
1271
+ })) : e.theme && (h = bt(h, e.theme)), e.previewBanner && (h = Pt(h, e.previewBanner));
1272
+ const w = $ === "slides" ? [] : pt(h), k = mt(w, p);
1273
+ return e.printPreview && (h = Ce(h, e.printPreview)), {
1257
1274
  html: h,
1258
- target: P,
1259
- printouts: g,
1260
- size: W,
1275
+ target: $,
1276
+ printouts: w,
1277
+ size: P,
1278
+ assetDirs: at,
1261
1279
  ...v ? { subtree: v } : {},
1262
- ...ve ? { sourceMap: ve } : {},
1263
- ...b ? { assetDirs: b } : {},
1264
- ...E ? { rootPrintout: E } : {}
1280
+ ...xe ? { sourceMap: xe } : {},
1281
+ ...k ? { rootPrintout: k } : {}
1265
1282
  };
1266
1283
  } catch (h) {
1267
- throw Le(h), h;
1284
+ throw De(h), h;
1268
1285
  } finally {
1269
1286
  te.delete();
1270
1287
  }
1271
1288
  } finally {
1272
- jt(u);
1289
+ Ut(d);
1273
1290
  }
1274
1291
  }
1275
- const Ae = `Usage: pretext-html <source.ptx> [options]
1292
+ const je = `Usage: pretext-html <source.ptx> [options]
1276
1293
 
1277
- Render a PreTeXt document to a single standalone HTML page (portable build:
1278
- one page, css/js/MathJax from CDN). No PreTeXt installation required.
1294
+ Render a PreTeXt document to a single standalone HTML page (one page,
1295
+ css/js/MathJax from CDN). No PreTeXt installation required.
1296
+
1297
+ Images, generated ones included, are linked rather than embedded. With
1298
+ --output, their URLs point at the project's own files, relative to the output
1299
+ file, and a missing one shows a placeholder naming what to generate. On stdout
1300
+ they are left as PreTeXt emits them, under external/ and generated/.
1279
1301
 
1280
1302
  Options:
1281
1303
  -o, --output <file> Write HTML to a file instead of stdout
1282
- --publication <file> Publication file (portable html is forced on)
1304
+ --publication <file> Publication file (CDN resources, chunk level 0 and
1305
+ cross-references as links are forced on)
1283
1306
  --css-theme <name> HTML theme to use when the publication file names
1284
1307
  none of its own: default-modern (PreTeXt's default),
1285
1308
  denver, tacoma, salem, greeley or boulder
@@ -1318,35 +1341,35 @@ Options:
1318
1341
  printouts are listed on stderr
1319
1342
  -h, --help Show this help
1320
1343
  `;
1321
- function Mn(e) {
1344
+ function Un(e) {
1322
1345
  let n, t, r, i, o;
1323
1346
  const s = {}, a = {};
1324
1347
  for (let c = 0; c < e.length; c++) {
1325
- const u = e[c], d = () => {
1348
+ const d = e[c], u = () => {
1326
1349
  if (c += 1, c >= e.length)
1327
- throw new Error(`Missing value for ${u}`);
1350
+ throw new Error(`Missing value for ${d}`);
1328
1351
  return e[c];
1329
1352
  };
1330
- switch (u) {
1353
+ switch (d) {
1331
1354
  case "-h":
1332
1355
  case "--help":
1333
- L.stdout.write(Ae), L.exit(0);
1356
+ L.stdout.write(je), L.exit(0);
1334
1357
  break;
1335
1358
  case "-o":
1336
1359
  case "--output":
1337
- t = d();
1360
+ t = u();
1338
1361
  break;
1339
1362
  case "--publication":
1340
- s.publicationPath = d();
1363
+ s.publicationPath = u();
1341
1364
  break;
1342
1365
  case "--css-theme":
1343
- s.cssTheme = d();
1366
+ s.cssTheme = u();
1344
1367
  break;
1345
1368
  case "--project-dir":
1346
- s.projectDir = d();
1369
+ s.projectDir = u();
1347
1370
  break;
1348
1371
  case "--xsl-dir":
1349
- s.xslDir = d();
1372
+ s.xslDir = u();
1350
1373
  break;
1351
1374
  case "--fragment":
1352
1375
  s.fragment = !0;
@@ -1355,19 +1378,19 @@ function Mn(e) {
1355
1378
  s.openKnowls = !1;
1356
1379
  break;
1357
1380
  case "--docinfo":
1358
- r = d();
1381
+ r = u();
1359
1382
  break;
1360
1383
  case "--docinfo-source":
1361
- s.docinfoSourcePath = d();
1384
+ s.docinfoSourcePath = u();
1362
1385
  break;
1363
1386
  case "--context":
1364
- s.contextSourcePath = d();
1387
+ s.contextSourcePath = u();
1365
1388
  break;
1366
1389
  case "--off-page-message":
1367
- s.offPageMessage = d();
1390
+ s.offPageMessage = u();
1368
1391
  break;
1369
1392
  case "--source-map":
1370
- i = d(), s.sourceMap = !0;
1393
+ i = u(), s.sourceMap = !0;
1371
1394
  break;
1372
1395
  // Attached form only (--print-preview=<id>), so that a bare
1373
1396
  // --print-preview cannot swallow the source file as its id.
@@ -1375,28 +1398,28 @@ function Mn(e) {
1375
1398
  o = !0;
1376
1399
  break;
1377
1400
  case "--param": {
1378
- const l = d(), m = l.indexOf("=");
1401
+ const l = u(), m = l.indexOf("=");
1379
1402
  if (m === -1)
1380
1403
  throw new Error(`--param expects name=value, got: ${l}`);
1381
1404
  a[l.slice(0, m)] = l.slice(m + 1);
1382
1405
  break;
1383
1406
  }
1384
1407
  default:
1385
- if (u.startsWith("--print-preview=")) {
1386
- o = u.slice(16);
1408
+ if (d.startsWith("--print-preview=")) {
1409
+ o = d.slice(16);
1387
1410
  break;
1388
1411
  }
1389
- if (u.startsWith("-"))
1390
- throw new Error(`Unknown option: ${u}`);
1412
+ if (d.startsWith("-"))
1413
+ throw new Error(`Unknown option: ${d}`);
1391
1414
  if (n)
1392
- throw new Error(`Unexpected extra argument: ${u}`);
1393
- n = u;
1415
+ throw new Error(`Unexpected extra argument: ${d}`);
1416
+ n = d;
1394
1417
  }
1395
1418
  }
1396
1419
  if (!n)
1397
1420
  throw new Error(`No source file given.
1398
1421
 
1399
- ` + Ae);
1422
+ ` + je);
1400
1423
  return Object.keys(a).length > 0 && (s.stringParams = a), {
1401
1424
  options: { ...s, sourcePath: n },
1402
1425
  output: t,
@@ -1405,52 +1428,67 @@ function Mn(e) {
1405
1428
  printPreview: o
1406
1429
  };
1407
1430
  }
1408
- async function zn(e) {
1409
- const { options: n, output: t, docinfoPath: r, sourceMapPath: i, printPreview: o } = Mn(e);
1410
- r && (n.docinfo = await ue(r, "utf8"));
1411
- const s = Date.now(), a = await An(n), { sourceMap: c, printouts: u, rootPrintout: d } = a;
1431
+ function Xn(e, n, t) {
1432
+ return ft(e, (r, i) => {
1433
+ const o = n[r], s = o === void 0 ? void 0 : f.resolve(o, i);
1434
+ if (s === void 0 || !lt(s))
1435
+ return ht(r, i);
1436
+ const a = f.relative(t, s);
1437
+ return f.isAbsolute(a) ? dt(s).href : a.split(f.sep).map(encodeURIComponent).join("/");
1438
+ });
1439
+ }
1440
+ async function rr(e) {
1441
+ const { options: n, output: t, docinfoPath: r, sourceMapPath: i, printPreview: o } = Un(e);
1442
+ r && (n.docinfo = await de(r, "utf8"));
1443
+ const s = Date.now(), a = await Fn(n), { sourceMap: c, printouts: d, rootPrintout: u } = a;
1412
1444
  let l = a.html;
1413
1445
  if (L.stderr.write(`pretext-html: rendered in ${Date.now() - s}ms
1414
1446
  `), o !== void 0) {
1415
- for (const w of u)
1447
+ for (const b of d)
1416
1448
  L.stderr.write(
1417
- `pretext-html: printout ${w.id} - ${w.label}
1449
+ `pretext-html: printout ${b.id} - ${b.label}
1418
1450
  `
1419
1451
  );
1420
- const m = typeof o == "string" ? o : d ?? u[0]?.id;
1452
+ const m = typeof o == "string" ? o : u ?? d[0]?.id;
1421
1453
  m ? (L.stderr.write(`pretext-html: print preview of ${m}
1422
- `), l = Me(l, m)) : L.stderr.write(
1454
+ `), l = Ce(l, m)) : L.stderr.write(
1423
1455
  `pretext-html: --print-preview: this document has no printouts (worksheet, handout, or project with a workspace); writing the ordinary page.
1424
1456
  `
1425
1457
  );
1426
1458
  }
1427
- i && c && (await xe(i, JSON.stringify(c, null, 2)), L.stderr.write(`pretext-html: wrote ${i}
1428
- `)), t ? (await xe(t, l), L.stderr.write(`pretext-html: wrote ${t}
1459
+ i && c && (await Te(i, JSON.stringify(c, null, 2)), L.stderr.write(`pretext-html: wrote ${i}
1460
+ `)), t ? (l = Xn(
1461
+ l,
1462
+ a.assetDirs,
1463
+ f.dirname(f.resolve(t))
1464
+ ), await Te(t, l), L.stderr.write(`pretext-html: wrote ${t}
1429
1465
  `)) : L.stdout.write(l);
1430
1466
  }
1431
1467
  export {
1432
- cn as O,
1433
- dt as P,
1434
- nn as S,
1435
- pn as a,
1436
- tn as b,
1437
- Vt as c,
1438
- Sn as d,
1439
- G as e,
1440
- Wn as f,
1441
- Ft as g,
1442
- mn as h,
1443
- gt as i,
1444
- An as j,
1445
- en as k,
1446
- hn as l,
1447
- Hn as m,
1448
- zn as n,
1449
- Lt as o,
1450
- mt as p,
1451
- Un as q,
1452
- Xt as r,
1453
- Xn as s,
1454
- Mn as t,
1455
- F as x
1468
+ vn as O,
1469
+ wt as P,
1470
+ dn as S,
1471
+ Tn as a,
1472
+ un as b,
1473
+ nn as c,
1474
+ Rn as d,
1475
+ V as e,
1476
+ tr as f,
1477
+ er as g,
1478
+ Xe as h,
1479
+ Pt as i,
1480
+ Sn as j,
1481
+ Fn as k,
1482
+ ln as l,
1483
+ nr as m,
1484
+ yn as n,
1485
+ Ot as o,
1486
+ Tt as p,
1487
+ rr as q,
1488
+ Gt as r,
1489
+ Zn as s,
1490
+ Qn as t,
1491
+ Xn as u,
1492
+ Un as v,
1493
+ U as x
1456
1494
  };