@pretextbook/pretext-html 0.16.1 → 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 +163 -18
- package/assets/preview-html.xsl +81 -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-CKAOX3L6.js +1494 -0
- package/dist/cli.d.ts +12 -1
- package/dist/cli.js +8 -3
- package/dist/index.browser.d.ts +10 -5
- package/dist/index.browser.js +1182 -856
- package/dist/index.d.ts +10 -4
- package/dist/index.js +49 -44
- package/dist/publication.d.ts +75 -21
- package/dist/renderer.d.ts +151 -23
- package/dist/skeleton.d.ts +68 -7
- package/dist/source-cache.d.ts +36 -0
- package/dist/sourcemap.d.ts +11 -1
- package/dist/subtree.d.ts +79 -0
- package/dist/target.d.ts +1 -1
- package/dist/xinclude.d.ts +40 -3
- package/package.json +1 -1
- package/dist/cli-DzlCZymu.js +0 -1145
package/dist/cli-DzlCZymu.js
DELETED
|
@@ -1,1145 +0,0 @@
|
|
|
1
|
-
import { readFile as W, writeFile as Q } from "node:fs/promises";
|
|
2
|
-
import * as b from "node:process";
|
|
3
|
-
import { listPrintouts as je, rootPrintoutId as Me, injectPrintPreview as fe } from "./printout.js";
|
|
4
|
-
import * as f from "node:path";
|
|
5
|
-
import { fileURLToPath as _e } from "node:url";
|
|
6
|
-
import { fromXml as E } from "xast-util-from-xml";
|
|
7
|
-
import { toXml as I } from "xast-util-to-xml";
|
|
8
|
-
import { injectRevealBridge as Be } from "./reveal.js";
|
|
9
|
-
import { injectThemeBridge as Oe } from "./theme.js";
|
|
10
|
-
const Ce = "ptxPreviewBannerDismissed", Fe = "About live preview";
|
|
11
|
-
function ee(e) {
|
|
12
|
-
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
13
|
-
}
|
|
14
|
-
function Ne(e) {
|
|
15
|
-
return [
|
|
16
|
-
'<div id="ptx-preview-banner" class="ptx-preview-banner" role="note">',
|
|
17
|
-
` <span class="ptx-preview-banner-text">${ee(e)}</span>`,
|
|
18
|
-
' <button type="button" class="ptx-preview-banner-dismiss" aria-label="Dismiss">×</button>',
|
|
19
|
-
"</div>",
|
|
20
|
-
`<button type="button" id="ptx-preview-banner-restore" class="ptx-preview-banner-restore" hidden>${ee(Fe)}</button>`
|
|
21
|
-
].join(`
|
|
22
|
-
`);
|
|
23
|
-
}
|
|
24
|
-
function Xe() {
|
|
25
|
-
return [
|
|
26
|
-
"<style>",
|
|
27
|
-
".ptx-preview-banner {",
|
|
28
|
-
" display: flex;",
|
|
29
|
-
" align-items: center;",
|
|
30
|
-
" gap: 0.75em;",
|
|
31
|
-
" padding: 0.5em 1em;",
|
|
32
|
-
" font-size: 0.9em;",
|
|
33
|
-
" background: #fff8e1;",
|
|
34
|
-
" color: #6b5300;",
|
|
35
|
-
" border-bottom: 1px solid #f0c36d;",
|
|
36
|
-
"}",
|
|
37
|
-
// The [hidden] content attribute only hides an element via the
|
|
38
|
-
// user-agent stylesheet's `[hidden] { display: none }` rule, and a
|
|
39
|
-
// normal-priority *author* rule always wins over a normal-priority UA
|
|
40
|
-
// rule regardless of selector specificity — so the unconditional
|
|
41
|
-
// `display: flex` above would otherwise keep the banner visible even
|
|
42
|
-
// after previewBannerScript sets `banner.hidden = true`.
|
|
43
|
-
".ptx-preview-banner[hidden] {",
|
|
44
|
-
" display: none;",
|
|
45
|
-
"}",
|
|
46
|
-
".ptx-preview-banner-text {",
|
|
47
|
-
" flex: 1 1 auto;",
|
|
48
|
-
"}",
|
|
49
|
-
".ptx-preview-banner-dismiss {",
|
|
50
|
-
" flex: 0 0 auto;",
|
|
51
|
-
" background: transparent;",
|
|
52
|
-
" border: none;",
|
|
53
|
-
" font-size: 1.2em;",
|
|
54
|
-
" line-height: 1;",
|
|
55
|
-
" cursor: pointer;",
|
|
56
|
-
" color: inherit;",
|
|
57
|
-
" padding: 0 0.25em;",
|
|
58
|
-
"}",
|
|
59
|
-
"html.dark-mode .ptx-preview-banner {",
|
|
60
|
-
" background: #3a2f00;",
|
|
61
|
-
" color: #f2d27a;",
|
|
62
|
-
" border-bottom-color: #6b5300;",
|
|
63
|
-
"}",
|
|
64
|
-
".ptx-preview-banner-restore {",
|
|
65
|
-
" position: fixed;",
|
|
66
|
-
" right: 0.5em;",
|
|
67
|
-
" bottom: 0.5em;",
|
|
68
|
-
" z-index: 1000;",
|
|
69
|
-
" background: transparent;",
|
|
70
|
-
" border: none;",
|
|
71
|
-
" padding: 0.15em 0.4em;",
|
|
72
|
-
" font-size: 0.75em;",
|
|
73
|
-
" color: inherit;",
|
|
74
|
-
" opacity: 0.45;",
|
|
75
|
-
" text-decoration: underline;",
|
|
76
|
-
" cursor: pointer;",
|
|
77
|
-
"}",
|
|
78
|
-
".ptx-preview-banner-restore:hover {",
|
|
79
|
-
" opacity: 0.85;",
|
|
80
|
-
"}",
|
|
81
|
-
// Printing a preview is a real workflow — the print-preview layout exists
|
|
82
|
-
// to be printed from (see printout.ts) — and a warning about the preview
|
|
83
|
-
// has no business on the paper.
|
|
84
|
-
"@media print {",
|
|
85
|
-
" .ptx-preview-banner, .ptx-preview-banner-restore {",
|
|
86
|
-
" display: none !important;",
|
|
87
|
-
" }",
|
|
88
|
-
"}",
|
|
89
|
-
"</style>"
|
|
90
|
-
].join(`
|
|
91
|
-
`);
|
|
92
|
-
}
|
|
93
|
-
function Ue() {
|
|
94
|
-
return [
|
|
95
|
-
"<script>",
|
|
96
|
-
"(function () {",
|
|
97
|
-
" var KEY = " + JSON.stringify(Ce) + ";",
|
|
98
|
-
' var banner = document.getElementById("ptx-preview-banner");',
|
|
99
|
-
' var restore = document.getElementById("ptx-preview-banner-restore");',
|
|
100
|
-
" if (!banner || !restore) { return; }",
|
|
101
|
-
// localStorage can throw (disabled cookies/storage, sandboxed iframe);
|
|
102
|
-
// fall back to always showing the banner rather than crashing the page.
|
|
103
|
-
" function isDismissed() {",
|
|
104
|
-
" try { return window.localStorage.getItem(KEY) === '1'; }",
|
|
105
|
-
" catch (e) { return false; }",
|
|
106
|
-
" }",
|
|
107
|
-
" function setDismissed(value) {",
|
|
108
|
-
" try {",
|
|
109
|
-
" if (value) { window.localStorage.setItem(KEY, '1'); }",
|
|
110
|
-
" else { window.localStorage.removeItem(KEY); }",
|
|
111
|
-
" } catch (e) {}",
|
|
112
|
-
" }",
|
|
113
|
-
" function apply(dismissed) {",
|
|
114
|
-
" banner.hidden = dismissed;",
|
|
115
|
-
" restore.hidden = !dismissed;",
|
|
116
|
-
" }",
|
|
117
|
-
" apply(isDismissed());",
|
|
118
|
-
' var dismissBtn = banner.querySelector(".ptx-preview-banner-dismiss");',
|
|
119
|
-
" if (dismissBtn) {",
|
|
120
|
-
" dismissBtn.addEventListener('click', function () {",
|
|
121
|
-
" setDismissed(true);",
|
|
122
|
-
" apply(true);",
|
|
123
|
-
" });",
|
|
124
|
-
" }",
|
|
125
|
-
" restore.addEventListener('click', function () {",
|
|
126
|
-
" setDismissed(false);",
|
|
127
|
-
" apply(false);",
|
|
128
|
-
" });",
|
|
129
|
-
"})();",
|
|
130
|
-
"<\/script>"
|
|
131
|
-
].join(`
|
|
132
|
-
`);
|
|
133
|
-
}
|
|
134
|
-
const We = "<!--ptx-preview-banner-->", He = "<!--/ptx-preview-banner-->", Je = /\n?<!--ptx-preview-banner-->[\s\S]*?<!--\/ptx-preview-banner-->/;
|
|
135
|
-
function ze(e, r) {
|
|
136
|
-
const t = Je.exec(e), n = t ? e.slice(0, t.index) + e.slice(t.index + t[0].length) : e;
|
|
137
|
-
if (!/<body[^>]*>/i.test(n))
|
|
138
|
-
return n;
|
|
139
|
-
const o = `
|
|
140
|
-
${We}
|
|
141
|
-
${Xe()}
|
|
142
|
-
${Ne(r.message)}
|
|
143
|
-
${Ue()}
|
|
144
|
-
${He}`;
|
|
145
|
-
return n.replace(/<body([^>]*)>/i, `<body$1>${o}`);
|
|
146
|
-
}
|
|
147
|
-
async function pe(e, r) {
|
|
148
|
-
const t = f.resolve(e), n = f.resolve(t, `.${f.posix.normalize(r)}`);
|
|
149
|
-
if (n !== t && !n.startsWith(t + f.sep)) {
|
|
150
|
-
console.error(
|
|
151
|
-
`pretext-html: refusing to serve ${r} from outside ${t}`
|
|
152
|
-
);
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
try {
|
|
156
|
-
return new Uint8Array(await W(n));
|
|
157
|
-
} catch {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
async function j(e) {
|
|
162
|
-
try {
|
|
163
|
-
return await W(e, "utf8");
|
|
164
|
-
} catch {
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
let he;
|
|
169
|
-
function sn(e) {
|
|
170
|
-
he = e;
|
|
171
|
-
}
|
|
172
|
-
function C() {
|
|
173
|
-
return he ?? process.env.PRETEXT_HTML_ASSETS ?? f.resolve(f.dirname(_e(import.meta.url)), "..", "assets");
|
|
174
|
-
}
|
|
175
|
-
function Ke(e, r) {
|
|
176
|
-
return f.join(e, r);
|
|
177
|
-
}
|
|
178
|
-
const me = "2.55.0", Ve = "8.3.3", Ge = [
|
|
179
|
-
"prefix-runtime.dd07797f77620576.bundle.js",
|
|
180
|
-
"prefix-926.5c7038c8ef173faf.bundle.js",
|
|
181
|
-
"prefix-runestone.11d27cdc38930c2c.bundle.js"
|
|
182
|
-
], Ye = [
|
|
183
|
-
"prefix-926.229729d09512acc9.css",
|
|
184
|
-
"prefix-runestone.347e2ecdeacfed99.css"
|
|
185
|
-
], qe = "born-hidden-knowl", Ze = /<details\b([^>]*)>(\s*)(?:<summary\b([^>]*)>)?/g;
|
|
186
|
-
function Qe(e) {
|
|
187
|
-
const r = /\bclass="([^"]*)"/.exec(e);
|
|
188
|
-
return r ? r[1].trim().split(/\s+/) : [];
|
|
189
|
-
}
|
|
190
|
-
function et(e) {
|
|
191
|
-
return /(^|\s)open(\s|=|$)/.test(e);
|
|
192
|
-
}
|
|
193
|
-
function te(e) {
|
|
194
|
-
return et(e) ? e : ` open${e}`;
|
|
195
|
-
}
|
|
196
|
-
function tt(e) {
|
|
197
|
-
return e.replace(
|
|
198
|
-
Ze,
|
|
199
|
-
(r, t, n, o) => {
|
|
200
|
-
if (!Qe(t).includes(qe))
|
|
201
|
-
return r;
|
|
202
|
-
const i = `<details${te(t)}>`;
|
|
203
|
-
return o === void 0 ? `${i}${n}` : `${i}${n}<summary${te(o)}>`;
|
|
204
|
-
}
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
const H = /* @__PURE__ */ new Map(), we = /* @__PURE__ */ new Map();
|
|
208
|
-
let F, nt = 0, be = pe;
|
|
209
|
-
function an(e) {
|
|
210
|
-
be = e;
|
|
211
|
-
}
|
|
212
|
-
function rt(e, r) {
|
|
213
|
-
const t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, n = we.get(t);
|
|
214
|
-
if (n !== void 0)
|
|
215
|
-
return Promise.resolve(new Response(n, { status: 200 }));
|
|
216
|
-
let o;
|
|
217
|
-
try {
|
|
218
|
-
o = new URL(t).host;
|
|
219
|
-
} catch {
|
|
220
|
-
o = "";
|
|
221
|
-
}
|
|
222
|
-
const i = H.get(o);
|
|
223
|
-
return i !== void 0 ? it(i, t) : F(e, r);
|
|
224
|
-
}
|
|
225
|
-
const ot = '<?xml version="1.0"?><pretext-preview-missing-file/>';
|
|
226
|
-
async function it(e, r) {
|
|
227
|
-
const t = decodeURIComponent(new URL(r).pathname), n = await be(e, t);
|
|
228
|
-
if (n === void 0)
|
|
229
|
-
return new Response(ot, { status: 200 });
|
|
230
|
-
const o = typeof n == "string" ? n : new Uint8Array(n);
|
|
231
|
-
return new Response(o, { status: 200 });
|
|
232
|
-
}
|
|
233
|
-
function ve() {
|
|
234
|
-
F || (F = globalThis.fetch, globalThis.fetch = rt);
|
|
235
|
-
}
|
|
236
|
-
function ge(e) {
|
|
237
|
-
ve();
|
|
238
|
-
const r = `mnt${++nt}.ptx.invalid`;
|
|
239
|
-
return H.set(r, e), `http://${r}`;
|
|
240
|
-
}
|
|
241
|
-
function st(e) {
|
|
242
|
-
H.delete(new URL(e).host);
|
|
243
|
-
}
|
|
244
|
-
function at(e, r) {
|
|
245
|
-
ve(), we.set(e, r);
|
|
246
|
-
}
|
|
247
|
-
const N = `<?xml version="1.0" encoding="UTF-8"?>
|
|
248
|
-
<publication>
|
|
249
|
-
<source>
|
|
250
|
-
<directories external="../assets" generated="../generated-assets" />
|
|
251
|
-
</source>
|
|
252
|
-
<common>
|
|
253
|
-
<tableofcontents level="0"/>
|
|
254
|
-
</common>
|
|
255
|
-
<html>
|
|
256
|
-
<platform portable="yes"/>
|
|
257
|
-
</html>
|
|
258
|
-
</publication>
|
|
259
|
-
`, ct = ["theme", "style", "shell"];
|
|
260
|
-
function y(e, r) {
|
|
261
|
-
for (const t of e.children)
|
|
262
|
-
if (t.type === "element" && t.name === r)
|
|
263
|
-
return t;
|
|
264
|
-
}
|
|
265
|
-
function T(e, r) {
|
|
266
|
-
let t = y(e, r);
|
|
267
|
-
return t || (t = { type: "element", name: r, attributes: {}, children: [] }, e.children.push(t)), t;
|
|
268
|
-
}
|
|
269
|
-
function lt(e, r) {
|
|
270
|
-
const t = y(e, "css");
|
|
271
|
-
if (t && ct.some((o) => t.attributes?.[o]))
|
|
272
|
-
return;
|
|
273
|
-
const n = t ?? T(e, "css");
|
|
274
|
-
n.attributes = { ...n.attributes, theme: r };
|
|
275
|
-
}
|
|
276
|
-
function ut(e, r) {
|
|
277
|
-
const t = y(e, "appearance");
|
|
278
|
-
if (t?.attributes?.theme)
|
|
279
|
-
return;
|
|
280
|
-
const n = t ?? T(e, "appearance");
|
|
281
|
-
n.attributes = { ...n.attributes, theme: r };
|
|
282
|
-
}
|
|
283
|
-
function dt(e) {
|
|
284
|
-
const r = T(e, "resources");
|
|
285
|
-
r.attributes = {
|
|
286
|
-
...r.attributes,
|
|
287
|
-
host: "cdn",
|
|
288
|
-
math: "online"
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
function ft(e, r = {}) {
|
|
292
|
-
const t = r.cssTheme?.trim(), n = r.revealTheme?.trim(), o = r.target === "slides";
|
|
293
|
-
if (!e && !t && !o)
|
|
294
|
-
return N;
|
|
295
|
-
const i = E(e ?? N), s = y(i, "publication");
|
|
296
|
-
if (!s)
|
|
297
|
-
throw new Error(
|
|
298
|
-
"Invalid publication file: no root <publication> element found"
|
|
299
|
-
);
|
|
300
|
-
const a = T(s, "html"), c = T(a, "platform");
|
|
301
|
-
if (c.attributes = { ...c.attributes, portable: "yes" }, t && lt(a, t), o) {
|
|
302
|
-
const l = T(s, "revealjs");
|
|
303
|
-
dt(l), n && ut(l, n);
|
|
304
|
-
}
|
|
305
|
-
return I(i);
|
|
306
|
-
}
|
|
307
|
-
function ne(e) {
|
|
308
|
-
if (!(e === void 0 || e === "" || e.startsWith("/")))
|
|
309
|
-
return e.endsWith("/") ? e : `${e}/`;
|
|
310
|
-
}
|
|
311
|
-
function pt(e) {
|
|
312
|
-
const r = E(e ?? N), t = y(r, "publication"), n = t && y(t, "source"), o = n && y(n, "directories"), i = ne(
|
|
313
|
-
o?.attributes?.external ?? void 0
|
|
314
|
-
), s = ne(
|
|
315
|
-
o?.attributes?.generated ?? void 0
|
|
316
|
-
);
|
|
317
|
-
return {
|
|
318
|
-
external: i,
|
|
319
|
-
generated: s,
|
|
320
|
-
managed: i !== void 0 && s !== void 0
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
const xe = "http://www.w3.org/2001/XInclude", re = 64;
|
|
324
|
-
async function ht(e, r, t) {
|
|
325
|
-
return e.includes("include") ? (await J(e, r, t)).content : e;
|
|
326
|
-
}
|
|
327
|
-
async function J(e, r, t) {
|
|
328
|
-
const n = E(e), o = {
|
|
329
|
-
projectDir: f.resolve(t),
|
|
330
|
-
stack: [f.resolve(r)]
|
|
331
|
-
}, i = await R(
|
|
332
|
-
n,
|
|
333
|
-
f.dirname(f.resolve(r)),
|
|
334
|
-
{ "": "" },
|
|
335
|
-
o
|
|
336
|
-
);
|
|
337
|
-
return { tree: n, content: i ? I(n) : e };
|
|
338
|
-
}
|
|
339
|
-
function mt(e) {
|
|
340
|
-
return e.data?.ptxIncludedFile;
|
|
341
|
-
}
|
|
342
|
-
function wt(e, r) {
|
|
343
|
-
const t = e.data ?? (e.data = {});
|
|
344
|
-
t.ptxIncludedFile = r;
|
|
345
|
-
}
|
|
346
|
-
function L(e, r) {
|
|
347
|
-
let t = e;
|
|
348
|
-
for (const [n, o] of Object.entries(r.attributes))
|
|
349
|
-
(n === "xmlns" || n.startsWith("xmlns:")) && (t === e && (t = { ...e }), t[n === "xmlns" ? "" : n.slice(6)] = o ?? "");
|
|
350
|
-
return t;
|
|
351
|
-
}
|
|
352
|
-
function ye(e, r) {
|
|
353
|
-
const t = e.name.indexOf(":"), n = t === -1 ? "" : e.name.slice(0, t);
|
|
354
|
-
return (t === -1 ? e.name : e.name.slice(t + 1)) === "include" && r[n] === xe;
|
|
355
|
-
}
|
|
356
|
-
async function R(e, r, t, n) {
|
|
357
|
-
let o = !1;
|
|
358
|
-
for (let i = 0; i < e.children.length; i++) {
|
|
359
|
-
const s = e.children[i];
|
|
360
|
-
if (s.type !== "element")
|
|
361
|
-
continue;
|
|
362
|
-
const a = L(t, s);
|
|
363
|
-
if (ye(s, a)) {
|
|
364
|
-
const c = await Te(
|
|
365
|
-
s,
|
|
366
|
-
r,
|
|
367
|
-
a,
|
|
368
|
-
n
|
|
369
|
-
);
|
|
370
|
-
e.children.splice(i, 1, ...c), i += c.length - 1, o = !0;
|
|
371
|
-
} else await R(s, r, a, n) && (o = !0);
|
|
372
|
-
}
|
|
373
|
-
return o;
|
|
374
|
-
}
|
|
375
|
-
async function Te(e, r, t, n) {
|
|
376
|
-
const o = n.stack[n.stack.length - 1];
|
|
377
|
-
if (e.attributes.xpointer)
|
|
378
|
-
throw new Error(
|
|
379
|
-
`xi:include with xpointer is not supported by the JS preview build (in ${o})`
|
|
380
|
-
);
|
|
381
|
-
const i = e.attributes.href;
|
|
382
|
-
if (!i)
|
|
383
|
-
throw new Error(`xi:include without href (in ${o})`);
|
|
384
|
-
let s = i;
|
|
385
|
-
try {
|
|
386
|
-
s = decodeURIComponent(i);
|
|
387
|
-
} catch {
|
|
388
|
-
}
|
|
389
|
-
const a = f.resolve(r, s);
|
|
390
|
-
if (a !== n.projectDir && !a.startsWith(n.projectDir + f.sep))
|
|
391
|
-
throw new Error(
|
|
392
|
-
`xi:include escapes the project directory: ${i} (in ${o})`
|
|
393
|
-
);
|
|
394
|
-
if (n.stack.includes(a))
|
|
395
|
-
throw new Error(
|
|
396
|
-
`Circular xi:include: ${[...n.stack, a].join(" -> ")}`
|
|
397
|
-
);
|
|
398
|
-
if (n.stack.length >= re)
|
|
399
|
-
throw new Error(`xi:include nesting exceeds ${re} levels`);
|
|
400
|
-
const c = await j(a);
|
|
401
|
-
if (c === void 0) {
|
|
402
|
-
const p = vt(e, t);
|
|
403
|
-
if (p)
|
|
404
|
-
return await R(p, r, t, n), p.children;
|
|
405
|
-
throw new Error(`xi:include target not found: ${i} (in ${o})`);
|
|
406
|
-
}
|
|
407
|
-
if (e.attributes.parse === "text")
|
|
408
|
-
return [{ type: "text", value: c }];
|
|
409
|
-
let l;
|
|
410
|
-
try {
|
|
411
|
-
l = E(c);
|
|
412
|
-
} catch (p) {
|
|
413
|
-
throw new Error(
|
|
414
|
-
`Could not parse xi:include target ${a} as XML: ${p instanceof Error ? p.message : p}. (Included files must be well-formed, with a single root element.)`
|
|
415
|
-
);
|
|
416
|
-
}
|
|
417
|
-
n.stack.push(a);
|
|
418
|
-
try {
|
|
419
|
-
await R(l, f.dirname(a), { "": "" }, n);
|
|
420
|
-
} finally {
|
|
421
|
-
n.stack.pop();
|
|
422
|
-
}
|
|
423
|
-
const u = l.children.filter(
|
|
424
|
-
(p) => p.type === "element"
|
|
425
|
-
);
|
|
426
|
-
for (const p of u)
|
|
427
|
-
wt(p, a);
|
|
428
|
-
return u;
|
|
429
|
-
}
|
|
430
|
-
function oe(e) {
|
|
431
|
-
return e.name === "docinfo";
|
|
432
|
-
}
|
|
433
|
-
async function bt(e, r, t) {
|
|
434
|
-
try {
|
|
435
|
-
const o = E(e).children.find(
|
|
436
|
-
(l) => l.type === "element"
|
|
437
|
-
);
|
|
438
|
-
if (!o)
|
|
439
|
-
return;
|
|
440
|
-
const i = f.resolve(r), s = f.dirname(i), a = {
|
|
441
|
-
projectDir: f.resolve(t),
|
|
442
|
-
stack: [i]
|
|
443
|
-
}, c = L({ "": "" }, o);
|
|
444
|
-
for (const l of o.children) {
|
|
445
|
-
if (l.type !== "element")
|
|
446
|
-
continue;
|
|
447
|
-
const u = L(c, l);
|
|
448
|
-
if (oe(l))
|
|
449
|
-
return await R(l, s, u, a), I(l);
|
|
450
|
-
if (ye(l, u)) {
|
|
451
|
-
const h = (await Te(
|
|
452
|
-
l,
|
|
453
|
-
s,
|
|
454
|
-
u,
|
|
455
|
-
a
|
|
456
|
-
)).find(
|
|
457
|
-
(m) => m.type === "element" && oe(m)
|
|
458
|
-
);
|
|
459
|
-
if (h)
|
|
460
|
-
return I(h);
|
|
461
|
-
continue;
|
|
462
|
-
}
|
|
463
|
-
break;
|
|
464
|
-
}
|
|
465
|
-
return;
|
|
466
|
-
} catch {
|
|
467
|
-
return;
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
function vt(e, r) {
|
|
471
|
-
for (const t of e.children) {
|
|
472
|
-
if (t.type !== "element")
|
|
473
|
-
continue;
|
|
474
|
-
const n = L(r, t), o = t.name.indexOf(":"), i = o === -1 ? "" : t.name.slice(0, o);
|
|
475
|
-
if ((o === -1 ? t.name : t.name.slice(o + 1)) === "fallback" && n[i] === xe)
|
|
476
|
-
return t;
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
function Ee(e) {
|
|
480
|
-
return typeof e == "object" && e !== null && e.type === "element";
|
|
481
|
-
}
|
|
482
|
-
function gt(e) {
|
|
483
|
-
return /^(pf|xhtml):/.test(e.name);
|
|
484
|
-
}
|
|
485
|
-
function xt(e, r, t) {
|
|
486
|
-
const n = [], o = e.children.find(Ee);
|
|
487
|
-
if (o) {
|
|
488
|
-
const i = t?.parentId ?? "root";
|
|
489
|
-
Se(o, i, t?.position ?? 1, r, i, n);
|
|
490
|
-
}
|
|
491
|
-
return n;
|
|
492
|
-
}
|
|
493
|
-
function Se(e, r, t, n, o, i) {
|
|
494
|
-
const s = mt(e) ?? n;
|
|
495
|
-
let a, c;
|
|
496
|
-
if (gt(e))
|
|
497
|
-
c = "root";
|
|
498
|
-
else {
|
|
499
|
-
const u = e.attributes.label ?? e.attributes["xml:id"];
|
|
500
|
-
a = u ?? `${r}-${t}`, i.push({
|
|
501
|
-
id: a,
|
|
502
|
-
file: s,
|
|
503
|
-
line: e.position?.start.line ?? 1,
|
|
504
|
-
column: e.position?.start.column ?? 1,
|
|
505
|
-
endLine: e.position?.end.line ?? e.position?.start.line ?? 1,
|
|
506
|
-
parent: o
|
|
507
|
-
}), c = a;
|
|
508
|
-
}
|
|
509
|
-
let l = 0;
|
|
510
|
-
for (const u of e.children)
|
|
511
|
-
Ee(u) && (l += 1, Se(
|
|
512
|
-
u,
|
|
513
|
-
c,
|
|
514
|
-
l,
|
|
515
|
-
s,
|
|
516
|
-
a ?? o,
|
|
517
|
-
i
|
|
518
|
-
));
|
|
519
|
-
}
|
|
520
|
-
function cn(e, r) {
|
|
521
|
-
let t;
|
|
522
|
-
for (const n of e)
|
|
523
|
-
n.line <= r && (t = n);
|
|
524
|
-
return t ?? e[0];
|
|
525
|
-
}
|
|
526
|
-
function yt(e) {
|
|
527
|
-
const r = e.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!\[CDATA\[[\s\S]*?\]\]>/g, " ");
|
|
528
|
-
return /<\s*slide(?:show)?[\s/>]/.test(r) ? "slides" : "html";
|
|
529
|
-
}
|
|
530
|
-
const ke = /* @__PURE__ */ new Set([
|
|
531
|
-
"colophon",
|
|
532
|
-
"biography",
|
|
533
|
-
"dedication",
|
|
534
|
-
"acknowledgement",
|
|
535
|
-
"preface",
|
|
536
|
-
"chapter",
|
|
537
|
-
"section",
|
|
538
|
-
"subsection",
|
|
539
|
-
"subsubsection",
|
|
540
|
-
"slide",
|
|
541
|
-
"appendix",
|
|
542
|
-
"index",
|
|
543
|
-
"exercises",
|
|
544
|
-
"reading-questions",
|
|
545
|
-
"references",
|
|
546
|
-
"solutions",
|
|
547
|
-
"glossary",
|
|
548
|
-
"worksheet",
|
|
549
|
-
"handout"
|
|
550
|
-
]), $e = /* @__PURE__ */ new Set([
|
|
551
|
-
"book",
|
|
552
|
-
"article",
|
|
553
|
-
"slideshow",
|
|
554
|
-
"letter",
|
|
555
|
-
"memo"
|
|
556
|
-
]), Pe = /* @__PURE__ */ new Set([
|
|
557
|
-
...$e,
|
|
558
|
-
...ke,
|
|
559
|
-
"part",
|
|
560
|
-
"frontmatter",
|
|
561
|
-
"backmatter"
|
|
562
|
-
]), Tt = /* @__PURE__ */ new Set(["docinfo"]), Ie = /* @__PURE__ */ new Set([
|
|
563
|
-
"title",
|
|
564
|
-
"shorttitle",
|
|
565
|
-
"plaintitle",
|
|
566
|
-
"subtitle",
|
|
567
|
-
"caption"
|
|
568
|
-
]);
|
|
569
|
-
function g(e) {
|
|
570
|
-
return e.type === "element";
|
|
571
|
-
}
|
|
572
|
-
function Re(e) {
|
|
573
|
-
return e.attributes["xml:id"] ?? void 0;
|
|
574
|
-
}
|
|
575
|
-
function X(e, r) {
|
|
576
|
-
for (const t of e.children) {
|
|
577
|
-
if (!g(t)) continue;
|
|
578
|
-
if (Re(t) === r) return t;
|
|
579
|
-
const n = X(t, r);
|
|
580
|
-
if (n) return n;
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
function A(e, r) {
|
|
584
|
-
for (const t of e.children) {
|
|
585
|
-
if (!g(t)) continue;
|
|
586
|
-
if (t === r) return [t];
|
|
587
|
-
const n = A(t, r);
|
|
588
|
-
if (n) return [t, ...n];
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
function Et(e, r) {
|
|
592
|
-
let t = 0;
|
|
593
|
-
for (const [n, o] of e.entries()) {
|
|
594
|
-
const i = n === 0 ? void 0 : e[n - 1];
|
|
595
|
-
$e.has(o.name) ? t = 0 : o.name === "frontmatter" || o.name === "backmatter" || o.name === "part" ? t = i?.name === "book" && r ? 1 : 0 : ke.has(o.name) && (t += 1);
|
|
596
|
-
}
|
|
597
|
-
return t;
|
|
598
|
-
}
|
|
599
|
-
function De(e) {
|
|
600
|
-
if (!Ie.has(e.name)) {
|
|
601
|
-
e.children = e.children.filter(g);
|
|
602
|
-
for (const r of e.children)
|
|
603
|
-
De(r);
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
function U(e, r) {
|
|
607
|
-
const t = [];
|
|
608
|
-
for (const n of e.children)
|
|
609
|
-
g(n) && (r.has(n) || Tt.has(n.name) || Ie.has(n.name) ? t.push(n) : Pe.has(n.name) && (U(n, r), t.push(n)));
|
|
610
|
-
e.children = t;
|
|
611
|
-
}
|
|
612
|
-
function St(e) {
|
|
613
|
-
const r = /* @__PURE__ */ new Set(), t = (n) => {
|
|
614
|
-
if (n.name === "xref") {
|
|
615
|
-
const o = [
|
|
616
|
-
n.attributes.ref,
|
|
617
|
-
n.attributes.first,
|
|
618
|
-
n.attributes.last
|
|
619
|
-
];
|
|
620
|
-
for (const i of o)
|
|
621
|
-
for (const s of i?.split(/[\s,]+/) ?? [])
|
|
622
|
-
s && r.add(s);
|
|
623
|
-
}
|
|
624
|
-
for (const o of n.children)
|
|
625
|
-
g(o) && t(o);
|
|
626
|
-
};
|
|
627
|
-
return t(e), r;
|
|
628
|
-
}
|
|
629
|
-
function kt(e, r, t) {
|
|
630
|
-
const n = (o) => {
|
|
631
|
-
for (const [i, s] of o.children.entries())
|
|
632
|
-
if (g(s)) {
|
|
633
|
-
if (Re(s) === r)
|
|
634
|
-
return o.children[i] = t, !0;
|
|
635
|
-
if (n(s)) return !0;
|
|
636
|
-
}
|
|
637
|
-
return !1;
|
|
638
|
-
};
|
|
639
|
-
return n(e);
|
|
640
|
-
}
|
|
641
|
-
function $t(e, r) {
|
|
642
|
-
const t = X(e, r);
|
|
643
|
-
if (!t) return;
|
|
644
|
-
const n = A(e, t);
|
|
645
|
-
if (!n) return;
|
|
646
|
-
const o = n.filter(
|
|
647
|
-
(h) => h.name !== "pretext" && h.name !== "mathbook"
|
|
648
|
-
), i = o[0], s = i?.name === "book" && i.children.some(
|
|
649
|
-
(h) => g(h) && h.name === "part"
|
|
650
|
-
), a = Et(o, s), c = new Set(n), l = St(t), u = /* @__PURE__ */ new Set();
|
|
651
|
-
if (l.size > 0)
|
|
652
|
-
for (const h of l) {
|
|
653
|
-
const m = X(e, h);
|
|
654
|
-
if (!m || m === t) continue;
|
|
655
|
-
const D = A(e, m);
|
|
656
|
-
if (!D) continue;
|
|
657
|
-
const x = [...D].reverse().find((v) => Pe.has(v.name));
|
|
658
|
-
if (x && x !== t) {
|
|
659
|
-
u.add(x);
|
|
660
|
-
for (const v of A(e, x) ?? [])
|
|
661
|
-
c.add(v);
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
for (const h of n) {
|
|
665
|
-
if (h === t) break;
|
|
666
|
-
U(h, c);
|
|
667
|
-
}
|
|
668
|
-
for (const h of u)
|
|
669
|
-
De(h);
|
|
670
|
-
const p = e.children.find(g);
|
|
671
|
-
return p && !n.includes(p) && U(p, c), { content: I(e), divisionId: r, level: a };
|
|
672
|
-
}
|
|
673
|
-
const Pt = "This live preview shows a single division, so links into the rest of the document do not work here.", It = /<a\b([^>]*)>/g, Rt = /\sid="([^"]*)"/g, _ = /\shref="([^"]*)"/, Dt = /\\href\{([^{}]*)\}/g, ie = /\stitle="([^"]*)"/;
|
|
674
|
-
function At(e) {
|
|
675
|
-
const r = /* @__PURE__ */ new Set();
|
|
676
|
-
for (const t of e.matchAll(Rt))
|
|
677
|
-
r.add(t[1]);
|
|
678
|
-
return r;
|
|
679
|
-
}
|
|
680
|
-
function Lt(e) {
|
|
681
|
-
return e.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
682
|
-
}
|
|
683
|
-
function se(e, r) {
|
|
684
|
-
if (e.startsWith("#") || e === "") return { kind: "keep" };
|
|
685
|
-
if (/^[a-z][a-z0-9+.-]*:/i.test(e) || e.startsWith("//"))
|
|
686
|
-
return { kind: "keep" };
|
|
687
|
-
const t = e.indexOf("#");
|
|
688
|
-
if (t === -1) return { kind: "off-page" };
|
|
689
|
-
const n = e.slice(t + 1);
|
|
690
|
-
return r.has(n) && n !== "" ? { kind: "same-page", id: n } : { kind: "off-page" };
|
|
691
|
-
}
|
|
692
|
-
function jt(e, r = {}) {
|
|
693
|
-
const t = r.offPageMessage ?? Pt, n = At(e);
|
|
694
|
-
return e.replace(It, (i, s) => {
|
|
695
|
-
const a = _.exec(s);
|
|
696
|
-
if (!a) return i;
|
|
697
|
-
const c = se(a[1], n);
|
|
698
|
-
if (c.kind === "keep") return i;
|
|
699
|
-
if (c.kind === "same-page")
|
|
700
|
-
return `<a${s.replace(_, ` href="#${c.id}"`)}>`;
|
|
701
|
-
const l = ie.exec(s), u = Lt(t), p = l ? `${l[1]} — ${u}` : u;
|
|
702
|
-
return `<a${s.replace(_, "").replace(ie, "")} title="${p}" aria-disabled="true" style="cursor:default">`;
|
|
703
|
-
}).replace(Dt, (i, s) => {
|
|
704
|
-
const a = se(s, n);
|
|
705
|
-
return a.kind === "same-page" ? `\\href{#${a.id}}` : i;
|
|
706
|
-
});
|
|
707
|
-
}
|
|
708
|
-
function Mt() {
|
|
709
|
-
return Ke(C(), "xsl");
|
|
710
|
-
}
|
|
711
|
-
function _t() {
|
|
712
|
-
return "Suspending" in WebAssembly;
|
|
713
|
-
}
|
|
714
|
-
function Bt() {
|
|
715
|
-
if (!_t())
|
|
716
|
-
throw new Error(
|
|
717
|
-
"WebAssembly JSPI is not enabled. Run Node with --experimental-wasm-jspi (or use the pretext-html CLI, which re-launches itself with the flag)."
|
|
718
|
-
);
|
|
719
|
-
}
|
|
720
|
-
function P(e) {
|
|
721
|
-
return e.includes("'") ? e.includes('"') ? `concat(${e.split("'").map((t) => `'${t}'`).join(`, "'", `)})` : `"${e}"` : `'${e}'`;
|
|
722
|
-
}
|
|
723
|
-
function Ot(e) {
|
|
724
|
-
return e.replace(
|
|
725
|
-
/from '\.\/(https:\/\/[^']+)'/g,
|
|
726
|
-
(r, t) => `from '${t}'`
|
|
727
|
-
);
|
|
728
|
-
}
|
|
729
|
-
const Ct = `https://cdn.jsdelivr.net/gh/PreTeXtBook/html-static@${me}/dist/`, Ft = {
|
|
730
|
-
"cli.version": me,
|
|
731
|
-
// Colon-delimited: pretext-runestone.xsl splits them with str:tokenize.
|
|
732
|
-
"rs-js": Ge.join(":"),
|
|
733
|
-
"rs-css": Ye.join(":"),
|
|
734
|
-
"rs-version": Ve
|
|
735
|
-
};
|
|
736
|
-
function Nt(e) {
|
|
737
|
-
return e.replace(
|
|
738
|
-
/(<link\b[^>]*\bhref=["'])_static\//gi,
|
|
739
|
-
`$1${Ct}_static/`
|
|
740
|
-
);
|
|
741
|
-
}
|
|
742
|
-
function Xt(e) {
|
|
743
|
-
return e.slice(0, 65536).replace(/<\?[\s\S]*?\?>/g, " ").replace(/<!--[\s\S]*?-->/g, " ").replace(/<!DOCTYPE[^>]*>/gi, " ").match(/<\s*([A-Za-z][\w:-]*)/)?.[1];
|
|
744
|
-
}
|
|
745
|
-
async function ae(e) {
|
|
746
|
-
const r = await j(e);
|
|
747
|
-
if (r === void 0)
|
|
748
|
-
throw new Error(
|
|
749
|
-
`Could not read ${e}. (In the browser build only absolute URLs are readable — pass sourceContent instead of relying on sourcePath.)`
|
|
750
|
-
);
|
|
751
|
-
return r;
|
|
752
|
-
}
|
|
753
|
-
async function Ut(e, r) {
|
|
754
|
-
const t = f.resolve(e), n = await j(t);
|
|
755
|
-
if (n !== void 0)
|
|
756
|
-
return bt(n, t, r);
|
|
757
|
-
}
|
|
758
|
-
function Wt(e, r, t, n) {
|
|
759
|
-
const o = e.replace(/^\uFEFF/, "").replace(/<\?xml[\s\S]*?\?>/, "").replace(/<!DOCTYPE[^>]*>/i, ""), i = t === "slides" ? "slideshow" : r === "chapter" || r === "part" ? "book" : "article";
|
|
760
|
-
return `<pretext>
|
|
761
|
-
${n?.trim() ? `${n.trim()}
|
|
762
|
-
` : ""}<${i}>
|
|
763
|
-
<title/>
|
|
764
|
-
${o}
|
|
765
|
-
</${i}>
|
|
766
|
-
</pretext>
|
|
767
|
-
`;
|
|
768
|
-
}
|
|
769
|
-
async function Ht(e, r, t, n) {
|
|
770
|
-
const o = E(e).children.find(
|
|
771
|
-
(u) => u.type === "element"
|
|
772
|
-
), i = o?.attributes["xml:id"];
|
|
773
|
-
if (!o || !i) return;
|
|
774
|
-
const s = f.resolve(r), a = n ?? await j(s);
|
|
775
|
-
if (a === void 0) return;
|
|
776
|
-
let c;
|
|
777
|
-
try {
|
|
778
|
-
c = (await J(a, s, t)).tree;
|
|
779
|
-
} catch {
|
|
780
|
-
return;
|
|
781
|
-
}
|
|
782
|
-
if (!kt(c, i, o)) return;
|
|
783
|
-
const l = $t(c, i);
|
|
784
|
-
if (l)
|
|
785
|
-
return { ...l, tree: c };
|
|
786
|
-
}
|
|
787
|
-
let Ae = !1;
|
|
788
|
-
function Jt(e) {
|
|
789
|
-
return e instanceof Error && /\bAborted\(/.test(e.message);
|
|
790
|
-
}
|
|
791
|
-
function zt(e) {
|
|
792
|
-
return e instanceof Error && /memory access|out of bounds/i.test(e.message);
|
|
793
|
-
}
|
|
794
|
-
function Kt() {
|
|
795
|
-
if (Ae)
|
|
796
|
-
throw new Error(
|
|
797
|
-
"The WebAssembly renderer aborted earlier in this process and cannot be reused. Restart the process (or reload the page) to render again."
|
|
798
|
-
);
|
|
799
|
-
}
|
|
800
|
-
function ce(e) {
|
|
801
|
-
if (Jt(e))
|
|
802
|
-
throw Ae = !0, new Error(
|
|
803
|
-
"The WebAssembly renderer aborted and cannot be reused. Restart the process (or reload the page) to render again.",
|
|
804
|
-
{ cause: e }
|
|
805
|
-
);
|
|
806
|
-
if (zt(e))
|
|
807
|
-
throw new Error(
|
|
808
|
-
"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.",
|
|
809
|
-
{ cause: e }
|
|
810
|
-
);
|
|
811
|
-
}
|
|
812
|
-
let B;
|
|
813
|
-
async function Le() {
|
|
814
|
-
return B || (B = (async () => {
|
|
815
|
-
const [e, r] = await Promise.all([
|
|
816
|
-
import("@pretextbook/libxslt-wasm"),
|
|
817
|
-
import("@pretextbook/libxslt-wasm/exslt")
|
|
818
|
-
]);
|
|
819
|
-
return r.registerAll(), e;
|
|
820
|
-
})()), B;
|
|
821
|
-
}
|
|
822
|
-
const O = /* @__PURE__ */ new Map(), Vt = {
|
|
823
|
-
html: "preview-html.xsl",
|
|
824
|
-
slides: "preview-revealjs.xsl"
|
|
825
|
-
};
|
|
826
|
-
async function Gt(e, r) {
|
|
827
|
-
const t = Vt[r], n = `${r}\0${e}`;
|
|
828
|
-
let o = O.get(n);
|
|
829
|
-
return o || (o = (async () => {
|
|
830
|
-
const { XmlDocument: i, XsltStylesheet: s } = await Le(), a = ge(e), c = await pe(C(), `/${t}`);
|
|
831
|
-
if (c === void 0)
|
|
832
|
-
throw new Error(
|
|
833
|
-
`Could not read ${t} from ${C()}. Check the assets location (PRETEXT_HTML_ASSETS under Node, setAssetsBase() in the browser).`
|
|
834
|
-
);
|
|
835
|
-
const l = new TextDecoder().decode(c), u = await i.fromString(l, {
|
|
836
|
-
url: `${a}/${t}`,
|
|
837
|
-
options: { noEnt: !0, dtdLoad: !0, huge: !0 }
|
|
838
|
-
});
|
|
839
|
-
return s.fromXmlDocument(u);
|
|
840
|
-
})(), O.set(n, o), o.catch(() => O.delete(n))), o;
|
|
841
|
-
}
|
|
842
|
-
let le = Promise.resolve();
|
|
843
|
-
function Yt(e) {
|
|
844
|
-
const r = le.then(
|
|
845
|
-
() => ue(e),
|
|
846
|
-
() => ue(e)
|
|
847
|
-
);
|
|
848
|
-
return le = r.catch(() => {
|
|
849
|
-
}), r;
|
|
850
|
-
}
|
|
851
|
-
async function ue(e) {
|
|
852
|
-
Bt(), Kt();
|
|
853
|
-
const { XmlDocument: r } = await Le(), t = f.resolve(e.sourcePath), n = f.resolve(
|
|
854
|
-
e.projectDir ?? f.dirname(t)
|
|
855
|
-
), o = e.sourceContent ?? await ae(t), i = f.relative(n, t);
|
|
856
|
-
if (i.startsWith(".."))
|
|
857
|
-
throw new Error(
|
|
858
|
-
`sourcePath (${t}) must live inside projectDir (${n})`
|
|
859
|
-
);
|
|
860
|
-
const s = f.relative(
|
|
861
|
-
n,
|
|
862
|
-
f.resolve(e.mainSourcePath ?? t)
|
|
863
|
-
), a = s.startsWith("..") ? i : s, c = ge(n);
|
|
864
|
-
try {
|
|
865
|
-
let l, u = `${c}/__pretext-preview-publication.xml`;
|
|
866
|
-
if (e.publicationPath) {
|
|
867
|
-
const d = f.resolve(e.publicationPath);
|
|
868
|
-
l = await ae(d);
|
|
869
|
-
const w = f.relative(n, d);
|
|
870
|
-
w.startsWith("..") || (u = `${c}/${w.split(f.sep).join("/")}`);
|
|
871
|
-
}
|
|
872
|
-
let p, h;
|
|
873
|
-
if (e.sourceMap) {
|
|
874
|
-
const d = await J(
|
|
875
|
-
o,
|
|
876
|
-
t,
|
|
877
|
-
n
|
|
878
|
-
);
|
|
879
|
-
p = d.tree, h = d.content;
|
|
880
|
-
} else
|
|
881
|
-
h = await ht(
|
|
882
|
-
o,
|
|
883
|
-
t,
|
|
884
|
-
n
|
|
885
|
-
);
|
|
886
|
-
const m = e.target ?? yt(h), D = await Gt(e.xslDir ?? Mt(), m), x = ft(l, {
|
|
887
|
-
cssTheme: e.cssTheme,
|
|
888
|
-
revealTheme: e.revealTheme,
|
|
889
|
-
target: m
|
|
890
|
-
});
|
|
891
|
-
at(u, x);
|
|
892
|
-
const v = pt(x), z = f.dirname(f.resolve(n, a)), K = v.external !== void 0 && v.generated !== void 0 ? {
|
|
893
|
-
external: f.resolve(z, v.external),
|
|
894
|
-
generated: f.resolve(z, v.generated)
|
|
895
|
-
} : void 0, S = Xt(h);
|
|
896
|
-
let V = { parentId: "root", position: 1 }, k, G = t;
|
|
897
|
-
if (S !== "pretext" && S !== "mathbook") {
|
|
898
|
-
if (!e.fragment)
|
|
899
|
-
throw new Error(
|
|
900
|
-
`The document root is <${S ?? "?"}>, not <pretext> — this looks like an xi:included fragment. Render the project's main source file instead, or pass the fragment option.`
|
|
901
|
-
);
|
|
902
|
-
if (e.contextSourcePath || e.contextSourceContent) {
|
|
903
|
-
const d = e.contextSourcePath ?? f.join(f.dirname(t), "__pretext-preview-context.ptx"), w = await Ht(
|
|
904
|
-
h,
|
|
905
|
-
d,
|
|
906
|
-
n,
|
|
907
|
-
e.contextSourceContent
|
|
908
|
-
);
|
|
909
|
-
w && (h = w.content, p = e.sourceMap ? w.tree : void 0, G = f.resolve(d), k = { divisionId: w.divisionId, level: w.level });
|
|
910
|
-
}
|
|
911
|
-
if (!k) {
|
|
912
|
-
const d = e.docinfo ?? (e.docinfoSourcePath ? await Ut(e.docinfoSourcePath, n) : void 0);
|
|
913
|
-
h = Wt(
|
|
914
|
-
h,
|
|
915
|
-
S,
|
|
916
|
-
m,
|
|
917
|
-
d
|
|
918
|
-
), V = { parentId: d?.trim() ? "root-1-2" : "root-1-1", position: 2 };
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
const Y = p ? xt(p, G, V) : void 0, q = await r.fromString(h, {
|
|
922
|
-
url: `${c}/${a.split(f.sep).join("/")}`,
|
|
923
|
-
options: { noEnt: !0, dtdLoad: !0, huge: !0 }
|
|
924
|
-
}), $ = {
|
|
925
|
-
publisher: P(u)
|
|
926
|
-
};
|
|
927
|
-
for (const [d, w] of Object.entries(Ft))
|
|
928
|
-
$[d] = P(w);
|
|
929
|
-
k && ($.subtree = P(k.divisionId), $["subtree-level"] = P(String(k.level)));
|
|
930
|
-
for (const [d, w] of Object.entries(e.stringParams ?? {}))
|
|
931
|
-
$[d] = P(w);
|
|
932
|
-
let M;
|
|
933
|
-
try {
|
|
934
|
-
M = await D.apply(q, $);
|
|
935
|
-
} catch (d) {
|
|
936
|
-
throw ce(d), new Error(
|
|
937
|
-
"PreTeXt XSLT transform failed; see the PTX:ERROR/PTX:FATAL messages on stderr for details.",
|
|
938
|
-
{ cause: d }
|
|
939
|
-
);
|
|
940
|
-
} finally {
|
|
941
|
-
q.delete();
|
|
942
|
-
}
|
|
943
|
-
try {
|
|
944
|
-
let d = Ot(M.toHtmlString());
|
|
945
|
-
d = jt(d, {
|
|
946
|
-
...e.offPageMessage !== void 0 ? { offPageMessage: e.offPageMessage } : {}
|
|
947
|
-
}), (e.openKnowls ?? !0) && (d = tt(d)), m === "slides" ? (d = Nt(d), d = Be(d, e.revealView ?? "scroll", {
|
|
948
|
-
zoom: e.revealZoom
|
|
949
|
-
})) : e.theme && (d = Oe(d, e.theme)), e.previewBanner && (d = ze(d, e.previewBanner));
|
|
950
|
-
const w = m === "slides" ? [] : je(d), Z = Me(w, S);
|
|
951
|
-
return e.printPreview && (d = fe(d, e.printPreview)), {
|
|
952
|
-
html: d,
|
|
953
|
-
target: m,
|
|
954
|
-
printouts: w,
|
|
955
|
-
...Y ? { sourceMap: Y } : {},
|
|
956
|
-
...K ? { assetDirs: K } : {},
|
|
957
|
-
...Z ? { rootPrintout: Z } : {}
|
|
958
|
-
};
|
|
959
|
-
} catch (d) {
|
|
960
|
-
throw ce(d), d;
|
|
961
|
-
} finally {
|
|
962
|
-
M.delete();
|
|
963
|
-
}
|
|
964
|
-
} finally {
|
|
965
|
-
st(c);
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
const de = `Usage: pretext-html <source.ptx> [options]
|
|
969
|
-
|
|
970
|
-
Render a PreTeXt document to a single standalone HTML page (portable build:
|
|
971
|
-
one page, css/js/MathJax from CDN). No PreTeXt installation required.
|
|
972
|
-
|
|
973
|
-
Options:
|
|
974
|
-
-o, --output <file> Write HTML to a file instead of stdout
|
|
975
|
-
--publication <file> Publication file (portable html is forced on)
|
|
976
|
-
--css-theme <name> HTML theme to use when the publication file names
|
|
977
|
-
none of its own: default-modern (PreTeXt's default),
|
|
978
|
-
denver, tacoma, salem, greeley or boulder
|
|
979
|
-
--project-dir <dir> Directory served to the transform for xi:includes
|
|
980
|
-
(default: the source file's directory)
|
|
981
|
-
--param <name=value> Extra XSLT string parameter (repeatable)
|
|
982
|
-
--xsl-dir <dir> Use PreTeXt stylesheets from this directory
|
|
983
|
-
instead of the vendored copy
|
|
984
|
-
--fragment Allow a non-root source file: wrap the fragment
|
|
985
|
-
in a minimal <pretext> document (an <article>,
|
|
986
|
-
or a <book> for <chapter>/<part> fragments)
|
|
987
|
-
--docinfo <file> File whose contents (a <docinfo> element) are
|
|
988
|
-
injected into the wrapper in --fragment mode, so
|
|
989
|
-
the fragment keeps the project's LaTeX macros
|
|
990
|
-
--docinfo-source <file> Complete source file (e.g. main.ptx) to lift the
|
|
991
|
-
<docinfo> from for --fragment mode, resolving
|
|
992
|
-
xi:includes (used when --docinfo is not given)
|
|
993
|
-
--context <file> Complete document (e.g. main.ptx) the fragment
|
|
994
|
-
belongs to. Renders it in place, so it is numbered
|
|
995
|
-
and its cross-references resolve as in the built
|
|
996
|
-
book. Supersedes --docinfo-source
|
|
997
|
-
--off-page-message <text> Tooltip on links whose target is not on the
|
|
998
|
-
previewed page, which cannot navigate in a
|
|
999
|
-
single-page preview
|
|
1000
|
-
--source-map <file> Also write a JSON source map: HTML id → source
|
|
1001
|
-
file/line for every element (for editor sync)
|
|
1002
|
-
--no-open-knowls Leave solutions, hints and other born-hidden
|
|
1003
|
-
knowls collapsed, as a real PreTeXt build does.
|
|
1004
|
-
They are expanded by default, since these pages
|
|
1005
|
-
are previews of work in progress
|
|
1006
|
-
--print-preview[=id] Open the page in the print-preview layout: the
|
|
1007
|
-
named printout paginated to a paper size, with
|
|
1008
|
-
workspaces at their true height. Without an id, the
|
|
1009
|
-
document's own printout is used (a lone worksheet
|
|
1010
|
-
or handout), or failing that its first. The page's
|
|
1011
|
-
printouts are listed on stderr
|
|
1012
|
-
-h, --help Show this help
|
|
1013
|
-
`;
|
|
1014
|
-
function qt(e) {
|
|
1015
|
-
let r, t, n, o, i;
|
|
1016
|
-
const s = {}, a = {};
|
|
1017
|
-
for (let c = 0; c < e.length; c++) {
|
|
1018
|
-
const l = e[c], u = () => {
|
|
1019
|
-
if (c += 1, c >= e.length)
|
|
1020
|
-
throw new Error(`Missing value for ${l}`);
|
|
1021
|
-
return e[c];
|
|
1022
|
-
};
|
|
1023
|
-
switch (l) {
|
|
1024
|
-
case "-h":
|
|
1025
|
-
case "--help":
|
|
1026
|
-
b.stdout.write(de), b.exit(0);
|
|
1027
|
-
break;
|
|
1028
|
-
case "-o":
|
|
1029
|
-
case "--output":
|
|
1030
|
-
t = u();
|
|
1031
|
-
break;
|
|
1032
|
-
case "--publication":
|
|
1033
|
-
s.publicationPath = u();
|
|
1034
|
-
break;
|
|
1035
|
-
case "--css-theme":
|
|
1036
|
-
s.cssTheme = u();
|
|
1037
|
-
break;
|
|
1038
|
-
case "--project-dir":
|
|
1039
|
-
s.projectDir = u();
|
|
1040
|
-
break;
|
|
1041
|
-
case "--xsl-dir":
|
|
1042
|
-
s.xslDir = u();
|
|
1043
|
-
break;
|
|
1044
|
-
case "--fragment":
|
|
1045
|
-
s.fragment = !0;
|
|
1046
|
-
break;
|
|
1047
|
-
case "--no-open-knowls":
|
|
1048
|
-
s.openKnowls = !1;
|
|
1049
|
-
break;
|
|
1050
|
-
case "--docinfo":
|
|
1051
|
-
n = u();
|
|
1052
|
-
break;
|
|
1053
|
-
case "--docinfo-source":
|
|
1054
|
-
s.docinfoSourcePath = u();
|
|
1055
|
-
break;
|
|
1056
|
-
case "--context":
|
|
1057
|
-
s.contextSourcePath = u();
|
|
1058
|
-
break;
|
|
1059
|
-
case "--off-page-message":
|
|
1060
|
-
s.offPageMessage = u();
|
|
1061
|
-
break;
|
|
1062
|
-
case "--source-map":
|
|
1063
|
-
o = u(), s.sourceMap = !0;
|
|
1064
|
-
break;
|
|
1065
|
-
// Attached form only (--print-preview=<id>), so that a bare
|
|
1066
|
-
// --print-preview cannot swallow the source file as its id.
|
|
1067
|
-
case "--print-preview":
|
|
1068
|
-
i = !0;
|
|
1069
|
-
break;
|
|
1070
|
-
case "--param": {
|
|
1071
|
-
const p = u(), h = p.indexOf("=");
|
|
1072
|
-
if (h === -1)
|
|
1073
|
-
throw new Error(`--param expects name=value, got: ${p}`);
|
|
1074
|
-
a[p.slice(0, h)] = p.slice(h + 1);
|
|
1075
|
-
break;
|
|
1076
|
-
}
|
|
1077
|
-
default:
|
|
1078
|
-
if (l.startsWith("--print-preview=")) {
|
|
1079
|
-
i = l.slice(16);
|
|
1080
|
-
break;
|
|
1081
|
-
}
|
|
1082
|
-
if (l.startsWith("-"))
|
|
1083
|
-
throw new Error(`Unknown option: ${l}`);
|
|
1084
|
-
if (r)
|
|
1085
|
-
throw new Error(`Unexpected extra argument: ${l}`);
|
|
1086
|
-
r = l;
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
if (!r)
|
|
1090
|
-
throw new Error(`No source file given.
|
|
1091
|
-
|
|
1092
|
-
` + de);
|
|
1093
|
-
return Object.keys(a).length > 0 && (s.stringParams = a), {
|
|
1094
|
-
options: { ...s, sourcePath: r },
|
|
1095
|
-
output: t,
|
|
1096
|
-
docinfoPath: n,
|
|
1097
|
-
sourceMapPath: o,
|
|
1098
|
-
printPreview: i
|
|
1099
|
-
};
|
|
1100
|
-
}
|
|
1101
|
-
async function ln(e) {
|
|
1102
|
-
const { options: r, output: t, docinfoPath: n, sourceMapPath: o, printPreview: i } = qt(e);
|
|
1103
|
-
n && (r.docinfo = await W(n, "utf8"));
|
|
1104
|
-
const s = Date.now(), a = await Yt(r), { sourceMap: c, printouts: l, rootPrintout: u } = a;
|
|
1105
|
-
let p = a.html;
|
|
1106
|
-
if (b.stderr.write(`pretext-html: rendered in ${Date.now() - s}ms
|
|
1107
|
-
`), i !== void 0) {
|
|
1108
|
-
for (const m of l)
|
|
1109
|
-
b.stderr.write(
|
|
1110
|
-
`pretext-html: printout ${m.id} - ${m.label}
|
|
1111
|
-
`
|
|
1112
|
-
);
|
|
1113
|
-
const h = typeof i == "string" ? i : u ?? l[0]?.id;
|
|
1114
|
-
h ? (b.stderr.write(`pretext-html: print preview of ${h}
|
|
1115
|
-
`), p = fe(p, h)) : b.stderr.write(
|
|
1116
|
-
`pretext-html: --print-preview: this document has no printouts (worksheet, handout, or project with a workspace); writing the ordinary page.
|
|
1117
|
-
`
|
|
1118
|
-
);
|
|
1119
|
-
}
|
|
1120
|
-
o && c && (await Q(o, JSON.stringify(c, null, 2)), b.stderr.write(`pretext-html: wrote ${o}
|
|
1121
|
-
`)), t ? (await Q(t, p), b.stderr.write(`pretext-html: wrote ${t}
|
|
1122
|
-
`)) : b.stdout.write(p);
|
|
1123
|
-
}
|
|
1124
|
-
export {
|
|
1125
|
-
Pt as O,
|
|
1126
|
-
Ce as P,
|
|
1127
|
-
yt as a,
|
|
1128
|
-
$t as b,
|
|
1129
|
-
Et as c,
|
|
1130
|
-
Mt as d,
|
|
1131
|
-
ft as e,
|
|
1132
|
-
cn as f,
|
|
1133
|
-
_t as g,
|
|
1134
|
-
kt as h,
|
|
1135
|
-
ze as i,
|
|
1136
|
-
jt as j,
|
|
1137
|
-
an as k,
|
|
1138
|
-
qt as l,
|
|
1139
|
-
ln as m,
|
|
1140
|
-
tt as o,
|
|
1141
|
-
Ue as p,
|
|
1142
|
-
Yt as r,
|
|
1143
|
-
sn as s,
|
|
1144
|
-
P as x
|
|
1145
|
-
};
|