@pretextbook/pretext-html 0.17.0 → 0.18.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.
- package/README.md +86 -15
- package/assets/preview-html.xsl +25 -14
- package/assets/preview-revealjs.xsl +7 -2
- package/dist/assets.d.ts +9 -5
- package/dist/banner.d.ts +2 -2
- package/dist/{cli-C0JwLhuv.js → cli-CKAOX3L6.js} +549 -511
- package/dist/cli.d.ts +12 -1
- package/dist/cli.js +8 -3
- package/dist/index.browser.d.ts +1 -1
- package/dist/index.browser.js +764 -748
- package/dist/index.d.ts +1 -1
- package/dist/index.js +42 -41
- package/dist/publication.d.ts +54 -21
- package/dist/renderer.d.ts +18 -11
- package/dist/target.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
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
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
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, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
13
15
|
}
|
|
14
|
-
function
|
|
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">${
|
|
19
|
+
` <span class="ptx-preview-banner-text">${Se(e)}</span>`,
|
|
18
20
|
' <button type="button" class="ptx-preview-banner-dismiss" aria-label="Dismiss">×</button>',
|
|
19
21
|
"</div>",
|
|
20
|
-
`<button type="button" id="ptx-preview-banner-restore" class="ptx-preview-banner-restore" hidden>${
|
|
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
|
|
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
|
|
95
|
+
function Tt() {
|
|
94
96
|
return [
|
|
95
97
|
"<script>",
|
|
96
98
|
"(function () {",
|
|
97
|
-
" var KEY = " + JSON.stringify(
|
|
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
|
|
135
|
-
function
|
|
136
|
-
const t =
|
|
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
|
-
${
|
|
141
|
-
${
|
|
142
|
-
${
|
|
143
|
-
${
|
|
144
|
-
${
|
|
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
|
|
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
|
|
158
|
+
return new Uint8Array(await de(r));
|
|
157
159
|
} catch {
|
|
158
160
|
return;
|
|
159
161
|
}
|
|
160
162
|
}
|
|
161
|
-
async function
|
|
163
|
+
async function $t(e) {
|
|
162
164
|
try {
|
|
163
|
-
return await
|
|
165
|
+
return await de(e, "utf8");
|
|
164
166
|
} catch {
|
|
165
167
|
return;
|
|
166
168
|
}
|
|
167
169
|
}
|
|
168
|
-
let
|
|
169
|
-
function
|
|
170
|
-
|
|
170
|
+
let Oe;
|
|
171
|
+
function Zn(e) {
|
|
172
|
+
Oe = e;
|
|
171
173
|
}
|
|
172
|
-
function
|
|
173
|
-
return
|
|
174
|
+
function ae() {
|
|
175
|
+
return Oe ?? process.env.PRETEXT_HTML_ASSETS ?? f.resolve(f.dirname(ut(import.meta.url)), "..", "assets");
|
|
174
176
|
}
|
|
175
|
-
function
|
|
177
|
+
function It(e, n) {
|
|
176
178
|
return f.join(e, n);
|
|
177
179
|
}
|
|
178
|
-
const
|
|
180
|
+
const _e = "2.55.0", Lt = "8.3.3", Dt = [
|
|
179
181
|
"prefix-runtime.dd07797f77620576.bundle.js",
|
|
180
182
|
"prefix-926.5c7038c8ef173faf.bundle.js",
|
|
181
183
|
"prefix-runestone.11d27cdc38930c2c.bundle.js"
|
|
182
|
-
],
|
|
184
|
+
], Rt = [
|
|
183
185
|
"prefix-926.229729d09512acc9.css",
|
|
184
186
|
"prefix-runestone.347e2ecdeacfed99.css"
|
|
185
|
-
],
|
|
186
|
-
function
|
|
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
|
|
192
|
+
function Mt(e) {
|
|
191
193
|
return /(^|\s)open(\s|=|$)/.test(e);
|
|
192
194
|
}
|
|
193
|
-
function
|
|
194
|
-
return
|
|
195
|
+
function Ee(e) {
|
|
196
|
+
return Mt(e) ? e : ` open${e}`;
|
|
195
197
|
}
|
|
196
|
-
function
|
|
198
|
+
function Ot(e) {
|
|
197
199
|
return e.replace(
|
|
198
|
-
|
|
200
|
+
jt,
|
|
199
201
|
(n, t, r, i) => {
|
|
200
|
-
if (!
|
|
202
|
+
if (!Ct(t).includes(At))
|
|
201
203
|
return n;
|
|
202
|
-
const o = `<details${
|
|
203
|
-
return i === void 0 ? `${o}${r}` : `${o}${r}<summary${
|
|
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
|
|
208
|
-
let
|
|
209
|
-
function
|
|
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
|
|
213
|
-
const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, r =
|
|
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 =
|
|
223
|
-
return o !== void 0 ?
|
|
224
|
+
const o = fe.get(i);
|
|
225
|
+
return o !== void 0 ? Ft(o, t) : ce(e, n);
|
|
224
226
|
}
|
|
225
|
-
const
|
|
226
|
-
async function
|
|
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(
|
|
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
|
|
234
|
-
|
|
235
|
+
function Fe() {
|
|
236
|
+
ce || (ce = globalThis.fetch, globalThis.fetch = Nt);
|
|
235
237
|
}
|
|
236
|
-
function
|
|
237
|
-
|
|
238
|
-
const n = `mnt${++
|
|
239
|
-
return
|
|
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
|
|
242
|
-
|
|
243
|
+
function Ut(e) {
|
|
244
|
+
fe.delete(new URL(e).host);
|
|
243
245
|
}
|
|
244
|
-
function
|
|
245
|
-
|
|
246
|
+
function Xt(e, n) {
|
|
247
|
+
Fe(), Ne.set(e, n);
|
|
246
248
|
}
|
|
247
|
-
const
|
|
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
|
-
`,
|
|
260
|
-
|
|
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 =
|
|
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
|
|
270
|
-
const t =
|
|
271
|
-
if (t &&
|
|
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
|
|
277
|
-
const t =
|
|
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
|
|
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
|
|
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
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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
|
|
313
|
+
return N(o);
|
|
306
314
|
}
|
|
307
|
-
|
|
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
|
|
318
|
-
const n =
|
|
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
|
|
323
|
-
|
|
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
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
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
|
|
344
|
-
async function
|
|
345
|
-
return (e?.readSource ? await e.readSource(n) : void 0) ?? await
|
|
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
|
|
348
|
-
return e.cache ? e.cache.parse(n, t) :
|
|
363
|
+
function pe(e, n, t) {
|
|
364
|
+
return e.cache ? e.cache.parse(n, t) : B(t);
|
|
349
365
|
}
|
|
350
|
-
async function
|
|
351
|
-
const i = f.resolve(n), o =
|
|
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 ?
|
|
381
|
+
content: a ? N(o) : e,
|
|
366
382
|
files: s.files,
|
|
367
383
|
bytes: s.bytes
|
|
368
384
|
};
|
|
369
385
|
}
|
|
370
|
-
function
|
|
386
|
+
function He(e) {
|
|
371
387
|
return e.data?.ptxIncludedFile;
|
|
372
388
|
}
|
|
373
|
-
function
|
|
389
|
+
function ze(e, n) {
|
|
374
390
|
const t = e.data ?? (e.data = {});
|
|
375
391
|
t.ptxIncludedFile = n;
|
|
376
392
|
}
|
|
377
|
-
function
|
|
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
|
|
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] ===
|
|
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 =
|
|
394
|
-
if (
|
|
395
|
-
const c = await
|
|
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
|
|
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 >=
|
|
430
|
-
throw new Error(`xi:include nesting exceeds ${
|
|
431
|
-
const c = await
|
|
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 =
|
|
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
|
|
456
|
+
let d;
|
|
441
457
|
try {
|
|
442
|
-
|
|
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(
|
|
466
|
+
await X(d, f.dirname(a), { "": "" }, r);
|
|
451
467
|
} finally {
|
|
452
468
|
r.stack.pop();
|
|
453
469
|
}
|
|
454
|
-
const
|
|
470
|
+
const u = d.children.filter(
|
|
455
471
|
(l) => l.type === "element"
|
|
456
472
|
);
|
|
457
|
-
for (const l of
|
|
458
|
-
|
|
459
|
-
return
|
|
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
|
|
480
|
+
async function qt(e, n, t, r = {}) {
|
|
465
481
|
try {
|
|
466
|
-
const i = f.resolve(n), s =
|
|
467
|
-
(
|
|
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
|
-
},
|
|
478
|
-
for (const
|
|
479
|
-
if (
|
|
493
|
+
}, d = J({ "": "" }, s);
|
|
494
|
+
for (const u of s.children) {
|
|
495
|
+
if (u.type !== "element")
|
|
480
496
|
continue;
|
|
481
|
-
const l =
|
|
482
|
-
if ($e(
|
|
483
|
-
return await X(
|
|
484
|
-
if (
|
|
485
|
-
const
|
|
486
|
-
|
|
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
|
-
(
|
|
507
|
+
(y) => y.type === "element" && $e(y)
|
|
492
508
|
);
|
|
493
|
-
if (
|
|
494
|
-
return
|
|
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
|
|
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 =
|
|
509
|
-
if ((i === -1 ? t.name : t.name.slice(i + 1)) === "fallback" && r[o] ===
|
|
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
|
|
529
|
+
function Ve(e) {
|
|
514
530
|
return typeof e == "object" && e !== null && e.type === "element";
|
|
515
531
|
}
|
|
516
|
-
function
|
|
532
|
+
function Qt(e) {
|
|
517
533
|
return /^(pf|xhtml):/.test(e.name);
|
|
518
534
|
}
|
|
519
|
-
function
|
|
535
|
+
function en(e, n, t) {
|
|
520
536
|
const r = [];
|
|
521
|
-
return
|
|
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
|
|
548
|
+
function tn(e, n, t) {
|
|
533
549
|
let r;
|
|
534
|
-
return
|
|
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
|
|
540
|
-
const i = e.children.find(
|
|
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
|
-
|
|
559
|
+
Ye(i, o, t?.position ?? 1, n, o, r);
|
|
544
560
|
}
|
|
545
561
|
}
|
|
546
|
-
function
|
|
547
|
-
const s =
|
|
562
|
+
function Ye(e, n, t, r, i, o) {
|
|
563
|
+
const s = He(e) ?? r;
|
|
548
564
|
let a, c;
|
|
549
|
-
if (
|
|
565
|
+
if (Qt(e))
|
|
550
566
|
c = "root";
|
|
551
567
|
else {
|
|
552
|
-
const
|
|
553
|
-
if (a =
|
|
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
|
|
558
|
-
for (const
|
|
559
|
-
if (
|
|
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
|
|
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
|
|
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
|
|
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
|
-
]),
|
|
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
|
-
...
|
|
608
|
-
...
|
|
623
|
+
...Ze,
|
|
624
|
+
...qe,
|
|
609
625
|
"part",
|
|
610
626
|
"foreword",
|
|
611
627
|
"frontmatter",
|
|
612
628
|
"backmatter"
|
|
613
629
|
]);
|
|
614
|
-
function
|
|
630
|
+
function Z(e) {
|
|
615
631
|
return A.has(e.name);
|
|
616
632
|
}
|
|
617
|
-
const
|
|
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
|
|
640
|
+
function g(e) {
|
|
625
641
|
return e.type === "element";
|
|
626
642
|
}
|
|
627
|
-
function
|
|
643
|
+
function et(e) {
|
|
628
644
|
return e.attributes["xml:id"] ?? void 0;
|
|
629
645
|
}
|
|
630
|
-
function
|
|
646
|
+
function K(e, n) {
|
|
631
647
|
for (const t of e.children) {
|
|
632
|
-
if (!
|
|
633
|
-
if (
|
|
634
|
-
const r =
|
|
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 (!
|
|
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
|
|
647
|
-
return
|
|
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
|
|
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 =
|
|
669
|
+
t = tt(t, o?.name, i.name, n);
|
|
654
670
|
}
|
|
655
671
|
return t;
|
|
656
672
|
}
|
|
657
|
-
function
|
|
673
|
+
function ve(e) {
|
|
658
674
|
return e?.name === "book" && e.children.some(
|
|
659
|
-
(n) =>
|
|
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) =>
|
|
680
|
+
(t) => g(t) && n.includes(t.name)
|
|
665
681
|
);
|
|
666
682
|
}
|
|
667
|
-
function
|
|
683
|
+
function on(e) {
|
|
668
684
|
if (!e) return 0;
|
|
669
685
|
const n = e.name;
|
|
670
686
|
if (n === "book") {
|
|
671
|
-
const t =
|
|
672
|
-
(o) =>
|
|
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) =>
|
|
690
|
+
(o) => g(o) && o.name === "part" ? o.children : []
|
|
675
691
|
) : e.children).some(
|
|
676
|
-
(o) =>
|
|
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) =>
|
|
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
|
|
692
|
-
return e ? e.name === "book" ?
|
|
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
|
|
695
|
-
if (!
|
|
696
|
-
e.children = e.children.filter(
|
|
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
|
-
|
|
714
|
+
be(n);
|
|
699
715
|
}
|
|
700
716
|
}
|
|
701
|
-
function
|
|
717
|
+
function an(e) {
|
|
702
718
|
for (const n of e.children)
|
|
703
|
-
|
|
719
|
+
g(n) && !A.has(n.name) && be(n);
|
|
704
720
|
}
|
|
705
|
-
function
|
|
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
|
-
|
|
735
|
+
g(o) && r(o);
|
|
720
736
|
}
|
|
721
737
|
};
|
|
722
738
|
return r(e), t;
|
|
723
739
|
}
|
|
724
|
-
function
|
|
740
|
+
function ln(e, n, t) {
|
|
725
741
|
const r = (i) => {
|
|
726
742
|
for (const [o, s] of i.children.entries())
|
|
727
|
-
if (
|
|
728
|
-
if (
|
|
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
|
|
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 (!
|
|
755
|
+
if (!g(s)) {
|
|
740
756
|
r && o.push(s);
|
|
741
757
|
continue;
|
|
742
758
|
}
|
|
743
|
-
if (t.verbatim.has(s) ||
|
|
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 =
|
|
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) && (
|
|
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
|
|
758
|
-
const r =
|
|
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) =>
|
|
764
|
-
), s = (p) => p.name === "pretext" || p.name === "mathbook", a = i.filter((p) => !s(p)), c = a[0],
|
|
765
|
-
const
|
|
766
|
-
return
|
|
767
|
-
}, m = t.maxNumberingLevel ?? 1 / 0,
|
|
768
|
-
t.numberingLevel ??
|
|
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
|
-
),
|
|
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:
|
|
775
|
-
hasParts:
|
|
776
|
-
},
|
|
777
|
-
o ?
|
|
778
|
-
const
|
|
779
|
-
const
|
|
780
|
-
if (!
|
|
781
|
-
const
|
|
782
|
-
if (!
|
|
783
|
-
if (i.includes(
|
|
784
|
-
|
|
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
|
|
788
|
-
for (let
|
|
789
|
-
|
|
790
|
-
if (!
|
|
791
|
-
|
|
792
|
-
for (const
|
|
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
|
|
796
|
-
const
|
|
797
|
-
|
|
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 [...
|
|
800
|
-
if (!A.has(p.name) || l(p) <=
|
|
815
|
+
for (const p of [...x.chain]) {
|
|
816
|
+
if (!A.has(p.name) || l(p) <= b)
|
|
801
817
|
continue;
|
|
802
|
-
const
|
|
803
|
-
if (
|
|
804
|
-
for (const
|
|
805
|
-
if (
|
|
806
|
-
!
|
|
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
|
|
810
|
-
|
|
811
|
-
for (const p of
|
|
812
|
-
|
|
813
|
-
for (const p of
|
|
814
|
-
|
|
815
|
-
return { content:
|
|
816
|
-
}
|
|
817
|
-
class
|
|
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),
|
|
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 =
|
|
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
|
|
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
|
|
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) =>
|
|
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
|
|
876
|
+
function G(e) {
|
|
861
877
|
return typeof e == "object" && e !== null && e.type === "element";
|
|
862
878
|
}
|
|
863
|
-
function
|
|
879
|
+
function fn(e) {
|
|
864
880
|
for (let n = e.length - 1; n >= 0; n--)
|
|
865
|
-
if (
|
|
881
|
+
if (Z(e[n])) return e[n];
|
|
866
882
|
}
|
|
867
|
-
function
|
|
883
|
+
function hn(e, n, t) {
|
|
868
884
|
const r = [], i = (s, a, c) => {
|
|
869
|
-
const
|
|
870
|
-
|
|
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
|
-
|
|
873
|
-
}, o = e.children.find(
|
|
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
|
|
877
|
-
const i =
|
|
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
|
|
881
|
-
|
|
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
|
|
901
|
+
function mn(e, n, t) {
|
|
886
902
|
let r;
|
|
887
903
|
if (n.id !== void 0) {
|
|
888
|
-
const l =
|
|
889
|
-
r = 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 =
|
|
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],
|
|
900
|
-
(l) =>
|
|
901
|
-
),
|
|
902
|
-
if (
|
|
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 (
|
|
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
|
|
911
|
-
return { element: r, id:
|
|
926
|
+
else u < i && (o = !0);
|
|
927
|
+
return { element: r, id: rt(e, r), collapse: o };
|
|
912
928
|
}
|
|
913
|
-
function
|
|
929
|
+
function rt(e, n) {
|
|
914
930
|
const t = n.attributes["xml:id"];
|
|
915
931
|
if (t) return t;
|
|
916
|
-
const r =
|
|
932
|
+
const r = tn(e, n) ?? "root-1";
|
|
917
933
|
return n.attributes["xml:id"] = r, r;
|
|
918
934
|
}
|
|
919
|
-
function
|
|
935
|
+
function Y(e) {
|
|
920
936
|
let n = 0;
|
|
921
937
|
for (const t of e.children)
|
|
922
|
-
|
|
938
|
+
G(t) && (n += 1 + Y(t));
|
|
923
939
|
return n;
|
|
924
940
|
}
|
|
925
|
-
const
|
|
926
|
-
function
|
|
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(
|
|
944
|
+
for (const t of e.matchAll(wn))
|
|
929
945
|
n.add(t[1]);
|
|
930
946
|
return n;
|
|
931
947
|
}
|
|
932
|
-
function
|
|
948
|
+
function ie(e) {
|
|
933
949
|
return e.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
934
950
|
}
|
|
935
|
-
function
|
|
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
|
|
945
|
-
const t = n.offPageMessage ??
|
|
946
|
-
return e.replace(
|
|
947
|
-
const a =
|
|
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 =
|
|
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(
|
|
953
|
-
const
|
|
954
|
-
return `<a${
|
|
955
|
-
}).replace(
|
|
956
|
-
const a =
|
|
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
|
|
961
|
-
return
|
|
976
|
+
function Tn() {
|
|
977
|
+
return It(ae(), "xsl");
|
|
962
978
|
}
|
|
963
|
-
function
|
|
979
|
+
function Sn() {
|
|
964
980
|
return "Suspending" in WebAssembly;
|
|
965
981
|
}
|
|
966
|
-
function
|
|
967
|
-
if (!
|
|
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
|
|
988
|
+
function U(e) {
|
|
973
989
|
return e.includes("'") ? e.includes('"') ? `concat(${e.split("'").map((t) => `'${t}'`).join(`, "'", `)})` : `"${e}"` : `'${e}'`;
|
|
974
990
|
}
|
|
975
|
-
function
|
|
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
|
|
982
|
-
"cli.version":
|
|
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":
|
|
985
|
-
"rs-css":
|
|
986
|
-
"rs-version":
|
|
1000
|
+
"rs-js": Dt.join(":"),
|
|
1001
|
+
"rs-css": Rt.join(":"),
|
|
1002
|
+
"rs-version": Lt
|
|
987
1003
|
};
|
|
988
|
-
function
|
|
1004
|
+
function In(e) {
|
|
989
1005
|
return e.replace(
|
|
990
1006
|
/(<link\b[^>]*\bhref=["'])_static\//gi,
|
|
991
|
-
`$1${
|
|
1007
|
+
`$1${Pn}_static/`
|
|
992
1008
|
);
|
|
993
1009
|
}
|
|
994
|
-
function
|
|
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
|
|
998
|
-
function
|
|
999
|
-
return
|
|
1013
|
+
let Dn;
|
|
1014
|
+
function Rn() {
|
|
1015
|
+
return Dn ??= new dn();
|
|
1000
1016
|
}
|
|
1001
|
-
function
|
|
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 ??
|
|
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
|
|
1011
|
-
const t = await
|
|
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
|
|
1019
|
-
const r = f.resolve(e), i = await
|
|
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
|
|
1037
|
+
return qt(i, r, n, t);
|
|
1022
1038
|
}
|
|
1023
|
-
async function
|
|
1024
|
-
const n =
|
|
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
|
|
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:
|
|
1050
|
+
elements: Y(o.tree),
|
|
1035
1051
|
files: o.files
|
|
1036
1052
|
};
|
|
1037
1053
|
}
|
|
1038
|
-
function
|
|
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
|
|
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
|
|
1068
|
+
const a = f.resolve(t), c = i ?? await q(o, a);
|
|
1053
1069
|
if (c === void 0) return;
|
|
1054
|
-
let
|
|
1070
|
+
let d, u, l;
|
|
1055
1071
|
try {
|
|
1056
|
-
({ tree:
|
|
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 (
|
|
1066
|
-
return
|
|
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
|
|
1069
|
-
function
|
|
1084
|
+
let ot = !1;
|
|
1085
|
+
function Mn(e) {
|
|
1070
1086
|
return e instanceof Error && /\bAborted\(/.test(e.message);
|
|
1071
1087
|
}
|
|
1072
|
-
function
|
|
1088
|
+
function On(e) {
|
|
1073
1089
|
return e instanceof Error && /memory access|out of bounds/i.test(e.message);
|
|
1074
1090
|
}
|
|
1075
|
-
function
|
|
1076
|
-
if (
|
|
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
|
|
1082
|
-
if (
|
|
1083
|
-
throw
|
|
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 (
|
|
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
|
|
1094
|
-
async function
|
|
1095
|
-
return
|
|
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
|
-
})()),
|
|
1117
|
+
})()), oe;
|
|
1102
1118
|
}
|
|
1103
|
-
const
|
|
1119
|
+
const se = /* @__PURE__ */ new Map(), Nn = {
|
|
1104
1120
|
html: "preview-html.xsl",
|
|
1105
1121
|
slides: "preview-revealjs.xsl"
|
|
1106
1122
|
};
|
|
1107
|
-
async function
|
|
1108
|
-
const t =
|
|
1109
|
-
let i =
|
|
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
|
|
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 ${
|
|
1130
|
+
`Could not read ${t} from ${ae()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
|
|
1115
1131
|
);
|
|
1116
|
-
const
|
|
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(
|
|
1121
|
-
})(),
|
|
1122
|
-
}
|
|
1123
|
-
let
|
|
1124
|
-
function
|
|
1125
|
-
const n =
|
|
1126
|
-
() =>
|
|
1127
|
-
() =>
|
|
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
|
|
1145
|
+
return Re = n.catch(() => {
|
|
1130
1146
|
}), n;
|
|
1131
1147
|
}
|
|
1132
|
-
async function
|
|
1133
|
-
|
|
1134
|
-
const { XmlDocument: n } = await
|
|
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
|
|
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,
|
|
1160
|
+
), c = a.startsWith("..") ? s : a, d = Ue(i);
|
|
1145
1161
|
try {
|
|
1146
|
-
let
|
|
1162
|
+
let u, l = `${d}/__pretext-preview-publication.xml`;
|
|
1147
1163
|
if (e.publicationPath) {
|
|
1148
1164
|
const h = f.resolve(e.publicationPath);
|
|
1149
|
-
|
|
1150
|
-
const
|
|
1151
|
-
|
|
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
|
|
1169
|
+
const m = await me(
|
|
1154
1170
|
o,
|
|
1155
1171
|
r,
|
|
1156
1172
|
i,
|
|
1157
1173
|
t
|
|
1158
1174
|
);
|
|
1159
|
-
let
|
|
1160
|
-
const
|
|
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:
|
|
1179
|
+
target: $
|
|
1164
1180
|
});
|
|
1165
|
-
|
|
1166
|
-
const p =
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
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
|
|
1176
|
-
if (
|
|
1177
|
-
const
|
|
1178
|
-
(
|
|
1179
|
-
).map((
|
|
1180
|
-
collapseChildren:
|
|
1181
|
-
...
|
|
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
|
|
1184
|
-
id:
|
|
1185
|
-
level:
|
|
1186
|
-
collapsed:
|
|
1187
|
-
children:
|
|
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 (
|
|
1203
|
+
if (p !== "pretext" && p !== "mathbook") {
|
|
1191
1204
|
if (!e.fragment)
|
|
1192
1205
|
throw new Error(
|
|
1193
|
-
`The document root is <${
|
|
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
|
|
1198
|
-
(
|
|
1199
|
-
), D =
|
|
1200
|
-
|
|
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
|
-
|
|
1215
|
+
w,
|
|
1203
1216
|
i,
|
|
1204
1217
|
e.contextSourceContent,
|
|
1205
1218
|
t
|
|
1206
1219
|
) : void 0;
|
|
1207
|
-
D && (h = !0,
|
|
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
|
|
1223
|
+
const w = e.docinfo ?? (e.docinfoSourcePath ? await An(
|
|
1211
1224
|
e.docinfoSourcePath,
|
|
1212
1225
|
i,
|
|
1213
1226
|
t
|
|
1214
1227
|
) : void 0);
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
),
|
|
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
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
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
|
-
}),
|
|
1228
|
-
publisher:
|
|
1244
|
+
}), F = {
|
|
1245
|
+
publisher: U(l)
|
|
1229
1246
|
};
|
|
1230
|
-
for (const [h,
|
|
1231
|
-
|
|
1232
|
-
v && (
|
|
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,
|
|
1236
|
-
|
|
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
|
|
1256
|
+
te = await Q.apply(ye, F);
|
|
1240
1257
|
} catch (h) {
|
|
1241
|
-
throw
|
|
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
|
-
|
|
1263
|
+
ye.delete();
|
|
1247
1264
|
}
|
|
1248
1265
|
try {
|
|
1249
|
-
let h =
|
|
1250
|
-
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 =
|
|
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 =
|
|
1255
|
-
const
|
|
1256
|
-
return e.printPreview && (h =
|
|
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:
|
|
1259
|
-
printouts:
|
|
1260
|
-
size:
|
|
1275
|
+
target: $,
|
|
1276
|
+
printouts: w,
|
|
1277
|
+
size: P,
|
|
1278
|
+
assetDirs: at,
|
|
1261
1279
|
...v ? { subtree: v } : {},
|
|
1262
|
-
...
|
|
1263
|
-
...
|
|
1264
|
-
...E ? { rootPrintout: E } : {}
|
|
1280
|
+
...xe ? { sourceMap: xe } : {},
|
|
1281
|
+
...k ? { rootPrintout: k } : {}
|
|
1265
1282
|
};
|
|
1266
1283
|
} catch (h) {
|
|
1267
|
-
throw
|
|
1284
|
+
throw De(h), h;
|
|
1268
1285
|
} finally {
|
|
1269
1286
|
te.delete();
|
|
1270
1287
|
}
|
|
1271
1288
|
} finally {
|
|
1272
|
-
|
|
1289
|
+
Ut(d);
|
|
1273
1290
|
}
|
|
1274
1291
|
}
|
|
1275
|
-
const
|
|
1292
|
+
const je = `Usage: pretext-html <source.ptx> [options]
|
|
1276
1293
|
|
|
1277
|
-
Render a PreTeXt document to a single standalone HTML page (
|
|
1278
|
-
|
|
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 (
|
|
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
|
|
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
|
|
1348
|
+
const d = e[c], u = () => {
|
|
1326
1349
|
if (c += 1, c >= e.length)
|
|
1327
|
-
throw new Error(`Missing value for ${
|
|
1350
|
+
throw new Error(`Missing value for ${d}`);
|
|
1328
1351
|
return e[c];
|
|
1329
1352
|
};
|
|
1330
|
-
switch (
|
|
1353
|
+
switch (d) {
|
|
1331
1354
|
case "-h":
|
|
1332
1355
|
case "--help":
|
|
1333
|
-
L.stdout.write(
|
|
1356
|
+
L.stdout.write(je), L.exit(0);
|
|
1334
1357
|
break;
|
|
1335
1358
|
case "-o":
|
|
1336
1359
|
case "--output":
|
|
1337
|
-
t =
|
|
1360
|
+
t = u();
|
|
1338
1361
|
break;
|
|
1339
1362
|
case "--publication":
|
|
1340
|
-
s.publicationPath =
|
|
1363
|
+
s.publicationPath = u();
|
|
1341
1364
|
break;
|
|
1342
1365
|
case "--css-theme":
|
|
1343
|
-
s.cssTheme =
|
|
1366
|
+
s.cssTheme = u();
|
|
1344
1367
|
break;
|
|
1345
1368
|
case "--project-dir":
|
|
1346
|
-
s.projectDir =
|
|
1369
|
+
s.projectDir = u();
|
|
1347
1370
|
break;
|
|
1348
1371
|
case "--xsl-dir":
|
|
1349
|
-
s.xslDir =
|
|
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 =
|
|
1381
|
+
r = u();
|
|
1359
1382
|
break;
|
|
1360
1383
|
case "--docinfo-source":
|
|
1361
|
-
s.docinfoSourcePath =
|
|
1384
|
+
s.docinfoSourcePath = u();
|
|
1362
1385
|
break;
|
|
1363
1386
|
case "--context":
|
|
1364
|
-
s.contextSourcePath =
|
|
1387
|
+
s.contextSourcePath = u();
|
|
1365
1388
|
break;
|
|
1366
1389
|
case "--off-page-message":
|
|
1367
|
-
s.offPageMessage =
|
|
1390
|
+
s.offPageMessage = u();
|
|
1368
1391
|
break;
|
|
1369
1392
|
case "--source-map":
|
|
1370
|
-
i =
|
|
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 =
|
|
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 (
|
|
1386
|
-
o =
|
|
1408
|
+
if (d.startsWith("--print-preview=")) {
|
|
1409
|
+
o = d.slice(16);
|
|
1387
1410
|
break;
|
|
1388
1411
|
}
|
|
1389
|
-
if (
|
|
1390
|
-
throw new Error(`Unknown option: ${
|
|
1412
|
+
if (d.startsWith("-"))
|
|
1413
|
+
throw new Error(`Unknown option: ${d}`);
|
|
1391
1414
|
if (n)
|
|
1392
|
-
throw new Error(`Unexpected extra argument: ${
|
|
1393
|
-
n =
|
|
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
|
-
` +
|
|
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
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
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
|
|
1447
|
+
for (const b of d)
|
|
1416
1448
|
L.stderr.write(
|
|
1417
|
-
`pretext-html: printout ${
|
|
1449
|
+
`pretext-html: printout ${b.id} - ${b.label}
|
|
1418
1450
|
`
|
|
1419
1451
|
);
|
|
1420
|
-
const m = typeof o == "string" ? o :
|
|
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 =
|
|
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
|
|
1428
|
-
`)), 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
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
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
|
};
|