@5cover/lectern 0.0.0-stage → 0.2.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.
@@ -0,0 +1,774 @@
1
+ #!/usr/bin/env node
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __esm = (fn, res, err) => function __init() {
5
+ if (err) throw err[0];
6
+ try {
7
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
8
+ } catch (e) {
9
+ throw err = [e], e;
10
+ }
11
+ };
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+
17
+ // src/cli/rules.ts
18
+ var rules_exports = {};
19
+ __export(rules_exports, {
20
+ rules: () => rules
21
+ });
22
+ function rules(profile) {
23
+ console.log();
24
+ console.log(` ${bold(profile.label)} ${dim(`(${profile.name})`)} \u2014 presentation rules`);
25
+ console.log(` ${dim(profile.description)}`);
26
+ for (const group of profile.rules) {
27
+ console.log();
28
+ console.log(` ${blue(`\u25B8 ${group.title}`)}`);
29
+ for (const r of group.rules) {
30
+ const tag = `[${SEVERITY_LABEL[r.severity]}]`.padEnd(11);
31
+ console.log(` ${dim(tag)} ${r.statement}`);
32
+ }
33
+ }
34
+ console.log();
35
+ console.log(dim(` Guidelines are descriptive; linting is not implemented yet.`));
36
+ console.log();
37
+ }
38
+ var SEVERITY_LABEL, useColor, bold, dim, blue;
39
+ var init_rules = __esm({
40
+ "src/cli/rules.ts"() {
41
+ "use strict";
42
+ SEVERITY_LABEL = {
43
+ must: "MUST",
44
+ should: "SHOULD",
45
+ advisory: "ADVISORY"
46
+ };
47
+ useColor = process.stdout.isTTY;
48
+ bold = (s) => useColor ? `\x1B[1m${s}\x1B[0m` : s;
49
+ dim = (s) => useColor ? `\x1B[2m${s}\x1B[0m` : s;
50
+ blue = (s) => useColor ? `\x1B[38;5;39m${s}\x1B[0m` : s;
51
+ }
52
+ });
53
+
54
+ // src/render/template.ts
55
+ function escapeHtml(s) {
56
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
57
+ }
58
+ function configScript(meta) {
59
+ const config = {
60
+ profile: meta.profile,
61
+ transition: meta.transition ?? "slide",
62
+ reveal: meta.reveal ?? {}
63
+ };
64
+ const json = JSON.stringify(config).replace(/</g, "\\u003c");
65
+ return `<script type="application/json" id="lectern-config">${json}</script>`;
66
+ }
67
+ function footer(meta) {
68
+ if (!meta.footer && !meta.author) return "";
69
+ const parts = [];
70
+ if (meta.author) parts.push(`<span class="lectern-footer-brand">${escapeHtml(meta.author)}</span>`);
71
+ if (meta.footer) parts.push(`<span>${escapeHtml(meta.footer)}</span>`);
72
+ return `<div class="lectern-footer">${parts.join(`<span class="lectern-sep"> \xB7 </span>`)}</div>`;
73
+ }
74
+ function htmlShell({ meta, slidesHtml, bodyScripts, headTags }) {
75
+ return `<!doctype html>
76
+ <html lang="fr">
77
+ <head>
78
+ <meta charset="utf-8" />
79
+ <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
80
+ <title>${escapeHtml(meta.title)}</title>
81
+ ${headTags}
82
+ </head>
83
+ <body>
84
+ <div class="reveal profile-${meta.profile}">
85
+ <div class="slides">
86
+ ${slidesHtml}
87
+ </div>
88
+ ${footer(meta)}
89
+ </div>
90
+ ${configScript(meta)}
91
+ ${bodyScripts}
92
+ </body>
93
+ </html>`;
94
+ }
95
+ var init_template = __esm({
96
+ "src/render/template.ts"() {
97
+ "use strict";
98
+ }
99
+ });
100
+
101
+ // src/cli/paths.ts
102
+ import { existsSync } from "fs";
103
+ import { isAbsolute, join, resolve } from "path";
104
+ import { fileURLToPath } from "url";
105
+ function posix(p) {
106
+ return p.replace(/\\/g, "/");
107
+ }
108
+ function pickBase() {
109
+ const srcClient = join(PACKAGE_ROOT, "src", "client", "entry.ts");
110
+ if (existsSync(srcClient)) return join(PACKAGE_ROOT, "src");
111
+ return join(PACKAGE_ROOT, "dist");
112
+ }
113
+ function firstExisting(...candidates) {
114
+ for (const c of candidates) if (existsSync(c)) return c;
115
+ return candidates[0];
116
+ }
117
+ function clientEntrySource(profile) {
118
+ const imports = [posix(CLIENT_ENTRY)];
119
+ const { stylesheet } = profile;
120
+ if (stylesheet) {
121
+ const spec = String(stylesheet);
122
+ imports.push(spec.startsWith("file:") ? posix(fileURLToPath(spec)) : isAbsolute(spec) ? posix(spec) : spec);
123
+ }
124
+ return imports.map((i) => `import ${JSON.stringify(i)};`).join("\n");
125
+ }
126
+ function presentAlias() {
127
+ return [
128
+ { find: /^@5cover\/lectern$/, replacement: INDEX_MODULE },
129
+ { find: /^@5cover\/lectern\/jsx-runtime$/, replacement: JSX_MODULE },
130
+ { find: /^@5cover\/lectern\/jsx-dev-runtime$/, replacement: JSX_MODULE },
131
+ { find: /^@5cover\/lectern\/engie$/, replacement: ENGIE_MODULE },
132
+ { find: /^@5cover\/lectern\/engie\.css$/, replacement: ENGIE_STYLESHEET },
133
+ { find: /^lectern\/jsx-runtime$/, replacement: JSX_MODULE },
134
+ { find: /^lectern\/jsx-dev-runtime$/, replacement: JSX_MODULE },
135
+ { find: /^lectern\/engie$/, replacement: ENGIE_MODULE },
136
+ { find: /^lectern\/engie\.css$/, replacement: ENGIE_STYLESHEET },
137
+ { find: /^lectern$/, replacement: INDEX_MODULE }
138
+ ];
139
+ }
140
+ var PACKAGE_ROOT, BASE, CLIENT_ENTRY, RENDER_MODULE, INDEX_MODULE, JSX_MODULE, ENGIE_MODULE, ENGIE_STYLESHEET;
141
+ var init_paths = __esm({
142
+ "src/cli/paths.ts"() {
143
+ "use strict";
144
+ PACKAGE_ROOT = resolve(import.meta.dirname, "..", "..");
145
+ BASE = pickBase();
146
+ CLIENT_ENTRY = firstExisting(join(BASE, "client", "entry.ts"), join(BASE, "client", "entry.js"));
147
+ RENDER_MODULE = firstExisting(
148
+ join(BASE, "render", "renderDeck.tsx"),
149
+ join(BASE, "render", "renderDeck.ts"),
150
+ join(BASE, "render", "renderDeck.js"),
151
+ join(PACKAGE_ROOT, "dist", "index.js")
152
+ );
153
+ INDEX_MODULE = firstExisting(join(BASE, "index.ts"), join(PACKAGE_ROOT, "dist", "index.js"));
154
+ JSX_MODULE = firstExisting(join(BASE, "jsx-runtime.ts"), join(PACKAGE_ROOT, "dist", "jsx-runtime.js"));
155
+ ENGIE_MODULE = firstExisting(
156
+ join(BASE, "profiles", "engie", "index.ts"),
157
+ join(PACKAGE_ROOT, "dist", "profiles", "engie", "index.js")
158
+ );
159
+ ENGIE_STYLESHEET = firstExisting(
160
+ join(PACKAGE_ROOT, "src", "profiles", "engie", "engie.css"),
161
+ join(PACKAGE_ROOT, "dist", "profiles", "engie", "engie.css")
162
+ );
163
+ }
164
+ });
165
+
166
+ // src/cli/render.ts
167
+ import { mkdtempSync, rmSync, writeFileSync } from "fs";
168
+ import { tmpdir } from "os";
169
+ import { dirname, join as join2 } from "path";
170
+ async function renderDeckViaVite(server, deckPath) {
171
+ const harnessDir = mkdtempSync(join2(tmpdir(), "lectern-harness-"));
172
+ const harnessPath = join2(harnessDir, "harness.tsx");
173
+ const source = [
174
+ `import deckModule from ${JSON.stringify(posix(deckPath))};`,
175
+ `import { renderDeck } from ${JSON.stringify(posix(RENDER_MODULE))};`,
176
+ `export function run() { return renderDeck(deckModule); }`
177
+ ].join("\n");
178
+ writeFileSync(harnessPath, source, "utf8");
179
+ try {
180
+ const mod = await server.ssrLoadModule(posix(harnessPath));
181
+ return mod.run();
182
+ } finally {
183
+ rmSync(harnessDir, { recursive: true, force: true });
184
+ }
185
+ }
186
+ function fsAllow(deckPath) {
187
+ return [PACKAGE_ROOT, dirname(deckPath), dirname(CLIENT_ENTRY), tmpdir(), process.cwd()];
188
+ }
189
+ var init_render = __esm({
190
+ "src/cli/render.ts"() {
191
+ "use strict";
192
+ init_paths();
193
+ }
194
+ });
195
+
196
+ // src/cli/build.ts
197
+ var build_exports = {};
198
+ __export(build_exports, {
199
+ build: () => build,
200
+ renderStatic: () => renderStatic
201
+ });
202
+ import { mkdirSync, mkdtempSync as mkdtempSync2, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "fs";
203
+ import { join as join3, resolve as resolve2 } from "path";
204
+ import { createServer, build as viteBuild } from "vite";
205
+ import { viteSingleFile } from "vite-plugin-singlefile";
206
+ async function renderStatic(deckPath) {
207
+ const server = await createServer({
208
+ configFile: false,
209
+ root: process.cwd(),
210
+ logLevel: "warn",
211
+ appType: "custom",
212
+ esbuild: { jsx: "automatic", jsxImportSource: "@5cover/lectern" },
213
+ resolve: { alias: presentAlias() },
214
+ server: { middlewareMode: true, fs: { allow: fsAllow(deckPath) } }
215
+ });
216
+ try {
217
+ return await renderDeckViaVite(server, deckPath);
218
+ } finally {
219
+ await server.close();
220
+ }
221
+ }
222
+ async function build({ deckPath, outDir, singleFile = true }) {
223
+ const { meta, profile, slidesHtml } = await renderStatic(deckPath);
224
+ const tmpBase = join3(process.cwd(), "node_modules", ".lectern-tmp");
225
+ mkdirSync(tmpBase, { recursive: true });
226
+ const workDir = mkdtempSync2(join3(tmpBase, "build-"));
227
+ writeFileSync2(join3(workDir, "lectern-entry.ts"), `${clientEntrySource(profile)}
228
+ `, "utf8");
229
+ const clientTag = `<script type="module" src="./lectern-entry.ts"></script>`;
230
+ writeFileSync2(
231
+ join3(workDir, "index.html"),
232
+ htmlShell({ meta, slidesHtml, bodyScripts: clientTag, headTags: "" }),
233
+ "utf8"
234
+ );
235
+ const outAbs = resolve2(process.cwd(), outDir);
236
+ try {
237
+ await viteBuild({
238
+ configFile: false,
239
+ root: workDir,
240
+ logLevel: "warn",
241
+ esbuild: { jsx: "automatic", jsxImportSource: "@5cover/lectern" },
242
+ resolve: { alias: presentAlias() },
243
+ plugins: singleFile ? [viteSingleFile()] : [],
244
+ build: {
245
+ outDir: outAbs,
246
+ emptyOutDir: true,
247
+ assetsInlineLimit: singleFile ? Number.MAX_SAFE_INTEGER : 4096,
248
+ chunkSizeWarningLimit: 4096
249
+ },
250
+ server: { fs: { allow: fsAllow(deckPath) } }
251
+ });
252
+ } finally {
253
+ rmSync2(workDir, { recursive: true, force: true });
254
+ }
255
+ return join3(outAbs, "index.html");
256
+ }
257
+ var init_build = __esm({
258
+ "src/cli/build.ts"() {
259
+ "use strict";
260
+ init_template();
261
+ init_paths();
262
+ init_render();
263
+ }
264
+ });
265
+
266
+ // src/profiles/engie/profile.ts
267
+ var engie;
268
+ var init_profile = __esm({
269
+ "src/profiles/engie/profile.ts"() {
270
+ "use strict";
271
+ engie = {
272
+ name: "engie",
273
+ label: "ENGIE / Fluid",
274
+ description: "ENGIE corporate house style (Fluid design system): navy #17255F & ENGIE blue #007bc5, Fluid typography, 16:9.",
275
+ stylesheet: "@5cover/lectern/engie.css",
276
+ reveal: {
277
+ // 16:9 design canvas. Reveal scales this scene to the available viewport
278
+ // while preserving its proportions.
279
+ width: 1280,
280
+ height: 720,
281
+ slideNumber: "c/t",
282
+ // Corporate decks are top-anchored (title at top, logo pinned to the corner),
283
+ // not vertically centred — so disable reveal's vertical centering.
284
+ center: false,
285
+ margin: 0
286
+ },
287
+ rules: [
288
+ {
289
+ title: "Structure & titles",
290
+ rules: [
291
+ {
292
+ id: "presentation-title-lines",
293
+ statement: "The cover title fits in two or three lines maximum.",
294
+ severity: "should"
295
+ },
296
+ {
297
+ id: "slide-title-lines",
298
+ statement: "A slide title is two or three lines maximum \u2014 ideally one. The subtitle is one line maximum.",
299
+ severity: "should"
300
+ },
301
+ {
302
+ id: "two-title-levels",
303
+ statement: "Use a second title level (title + subtitle) only when it genuinely adds structure.",
304
+ severity: "advisory"
305
+ },
306
+ {
307
+ id: "chapters-numbered",
308
+ statement: "Introduce each chapter with a numbered section divider (01, 02, \u2026); a Summary slide lists the chapters.",
309
+ severity: "should"
310
+ },
311
+ {
312
+ id: "one-idea-per-slide",
313
+ statement: "Prefer one message per slide; keep body copy concise.",
314
+ severity: "advisory"
315
+ }
316
+ ]
317
+ },
318
+ {
319
+ title: "Confidentiality & rights",
320
+ rules: [
321
+ {
322
+ id: "confidentiality-level",
323
+ statement: "Every deck declares a confidentiality level: Non-confidential, Confidential, or Strictly confidential.",
324
+ severity: "must"
325
+ },
326
+ {
327
+ id: "visual-rights",
328
+ statement: "Iconography and visuals are for internal use only \u2014 verify the rights of every visual you include.",
329
+ severity: "must"
330
+ }
331
+ ]
332
+ },
333
+ {
334
+ title: "Footer",
335
+ rules: [
336
+ {
337
+ id: "footer-format",
338
+ statement: 'Footer format: "\xA9 ENGIE {year} - {presentation title} - {date} - {page}".',
339
+ severity: "should"
340
+ }
341
+ ]
342
+ },
343
+ {
344
+ title: "Colours",
345
+ rules: [
346
+ {
347
+ id: "primary-colours",
348
+ statement: "Primary palette: navy #17255F, ENGIE blue #007bc5, teal #00817d, purple #6c4796.",
349
+ severity: "should"
350
+ },
351
+ {
352
+ id: "accent-colours",
353
+ statement: "Accent palette: coral #eb5d40, magenta #e94287, yellow #f4c867 \u2014 use for emphasis, sparingly.",
354
+ severity: "advisory"
355
+ },
356
+ {
357
+ id: "secondary-colours",
358
+ statement: "Secondary palette: #e18554, #4bb0b9, #67ae6e, #278cbc. Tints at 50% and 20% are available for backgrounds.",
359
+ severity: "advisory"
360
+ }
361
+ ]
362
+ },
363
+ {
364
+ title: "Typography",
365
+ rules: [
366
+ {
367
+ id: "fonts",
368
+ statement: "Typography follows the Fluid design system (Lato, with system fallbacks); titles are bold, body is regular.",
369
+ severity: "should"
370
+ }
371
+ ]
372
+ },
373
+ {
374
+ title: "Format & figures",
375
+ rules: [
376
+ {
377
+ id: "aspect-ratio",
378
+ statement: "Slides are 16:9.",
379
+ severity: "must"
380
+ },
381
+ {
382
+ id: "kpi-style",
383
+ statement: 'Highlight key figures as a large number with a short label (e.g. "9-10 Md\u20AC").',
384
+ severity: "advisory"
385
+ }
386
+ ]
387
+ }
388
+ ]
389
+ };
390
+ }
391
+ });
392
+
393
+ // src/profiles/index.ts
394
+ var profiles_exports = {};
395
+ __export(profiles_exports, {
396
+ DEFAULT_PROFILE: () => DEFAULT_PROFILE,
397
+ getProfile: () => getProfile,
398
+ profileNames: () => profileNames,
399
+ profiles: () => profiles,
400
+ resolveProfile: () => resolveProfile
401
+ });
402
+ function getProfile(name) {
403
+ return profiles[name ?? DEFAULT_PROFILE];
404
+ }
405
+ function profileNames() {
406
+ return Object.keys(profiles);
407
+ }
408
+ function resolveProfile(profile) {
409
+ if (typeof profile === "object") return profile;
410
+ const found = getProfile(profile);
411
+ if (!found) throw new Error(`Unknown profile: "${profile}". Available: ${profileNames().join(", ")}`);
412
+ return found;
413
+ }
414
+ var profiles, DEFAULT_PROFILE;
415
+ var init_profiles = __esm({
416
+ "src/profiles/index.ts"() {
417
+ "use strict";
418
+ init_profile();
419
+ profiles = {
420
+ engie
421
+ };
422
+ DEFAULT_PROFILE = "engie";
423
+ }
424
+ });
425
+
426
+ // src/cli/dev.ts
427
+ var dev_exports = {};
428
+ __export(dev_exports, {
429
+ dev: () => dev
430
+ });
431
+ import http from "http";
432
+ import { relative } from "path";
433
+ import { createServer as createServer2 } from "vite";
434
+ async function dev({ deckPath, port }) {
435
+ const server = await createServer2({
436
+ configFile: false,
437
+ root: process.cwd(),
438
+ logLevel: "warn",
439
+ appType: "custom",
440
+ esbuild: { jsx: "automatic", jsxImportSource: "@5cover/lectern" },
441
+ resolve: { alias: presentAlias() },
442
+ // The deck HTML is generated on demand, so Vite cannot discover this entry from disk.
443
+ optimizeDeps: { entries: [posix(relative(process.cwd(), CLIENT_ENTRY))] },
444
+ server: { middlewareMode: true, fs: { allow: fsAllow(deckPath) } }
445
+ });
446
+ async function renderPage(url2) {
447
+ const { meta, profile, slidesHtml } = await renderDeckViaVite(server, deckPath);
448
+ const clientTag = `<script type="module">${clientEntrySource(profile)}</script>`;
449
+ const html = htmlShell({ meta, slidesHtml, bodyScripts: clientTag, headTags: "" });
450
+ return server.transformIndexHtml(url2, html);
451
+ }
452
+ const httpServer = http.createServer((req, res) => {
453
+ server.middlewares(req, res, async () => {
454
+ try {
455
+ const html = await renderPage(req.url ?? "/");
456
+ res.statusCode = 200;
457
+ res.setHeader("content-type", "text/html; charset=utf-8");
458
+ res.end(html);
459
+ } catch (err) {
460
+ server.ssrFixStacktrace(err);
461
+ res.statusCode = 500;
462
+ res.setHeader("content-type", "text/plain; charset=utf-8");
463
+ res.end(`lectern dev error:
464
+
465
+ ${err.stack ?? String(err)}`);
466
+ }
467
+ });
468
+ });
469
+ server.watcher.on("change", () => {
470
+ server.moduleGraph.invalidateAll();
471
+ server.ws.send({ type: "full-reload" });
472
+ });
473
+ await new Promise((res) => httpServer.listen(port, res));
474
+ const url = `http://localhost:${port}/`;
475
+ console.log(
476
+ `
477
+ lectern dev server running
478
+ \u279C ${url}
479
+ Editing ${deckPath} reloads automatically. Ctrl+C to stop.
480
+ `
481
+ );
482
+ }
483
+ var init_dev = __esm({
484
+ "src/cli/dev.ts"() {
485
+ "use strict";
486
+ init_template();
487
+ init_paths();
488
+ init_render();
489
+ }
490
+ });
491
+
492
+ // src/cli/serve.ts
493
+ var serve_exports = {};
494
+ __export(serve_exports, {
495
+ serve: () => serve
496
+ });
497
+ import http2 from "http";
498
+ import { mkdtempSync as mkdtempSync3, readFileSync, rmSync as rmSync3 } from "fs";
499
+ import { tmpdir as tmpdir2 } from "os";
500
+ import { join as join4 } from "path";
501
+ async function serve({ deckPath, port, host }) {
502
+ const outDir = mkdtempSync3(join4(tmpdir2(), "lectern-serve-"));
503
+ let document2;
504
+ try {
505
+ const indexHtml = await build({ deckPath, outDir, singleFile: true });
506
+ document2 = readFileSync(indexHtml);
507
+ } catch (err) {
508
+ rmSync3(outDir, { recursive: true, force: true });
509
+ throw err;
510
+ }
511
+ const server = http2.createServer((req, res) => {
512
+ const path = new URL(req.url ?? "/", `http://${req.headers.host ?? host}`).pathname;
513
+ if (req.method !== "GET" && req.method !== "HEAD") {
514
+ res.statusCode = 405;
515
+ res.setHeader("allow", "GET, HEAD");
516
+ res.end();
517
+ return;
518
+ }
519
+ if (path !== "/" && path !== "/index.html") {
520
+ res.statusCode = 404;
521
+ res.end("Not found");
522
+ return;
523
+ }
524
+ res.statusCode = 200;
525
+ res.setHeader("content-type", "text/html; charset=utf-8");
526
+ res.setHeader("content-length", document2.length);
527
+ if (req.method === "HEAD") {
528
+ res.end();
529
+ return;
530
+ }
531
+ res.end(document2);
532
+ });
533
+ let closed = false;
534
+ const cleanup = () => rmSync3(outDir, { recursive: true, force: true });
535
+ const close = () => new Promise((resolve5, reject) => {
536
+ if (closed) {
537
+ resolve5();
538
+ return;
539
+ }
540
+ closed = true;
541
+ process.removeListener("SIGINT", shutdown);
542
+ process.removeListener("SIGTERM", shutdown);
543
+ server.close((err) => err ? reject(err) : resolve5());
544
+ });
545
+ const shutdown = () => {
546
+ void close();
547
+ };
548
+ server.once("close", cleanup);
549
+ process.once("SIGINT", shutdown);
550
+ process.once("SIGTERM", shutdown);
551
+ try {
552
+ await listen(server, port, host);
553
+ } catch (err) {
554
+ process.removeListener("SIGINT", shutdown);
555
+ process.removeListener("SIGTERM", shutdown);
556
+ server.removeListener("close", cleanup);
557
+ cleanup();
558
+ throw err;
559
+ }
560
+ const displayHost = host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
561
+ const address = server.address();
562
+ const actualPort = typeof address === "object" && address ? address.port : port;
563
+ return { url: `http://${displayHost}:${actualPort}/`, close };
564
+ }
565
+ function listen(server, port, host) {
566
+ return new Promise((resolve5, reject) => {
567
+ const onError = (err) => {
568
+ server.off("listening", onListening);
569
+ reject(err);
570
+ };
571
+ const onListening = () => {
572
+ server.off("error", onError);
573
+ resolve5();
574
+ };
575
+ server.once("error", onError);
576
+ server.once("listening", onListening);
577
+ server.listen(port, host);
578
+ });
579
+ }
580
+ var init_serve = __esm({
581
+ "src/cli/serve.ts"() {
582
+ "use strict";
583
+ init_build();
584
+ }
585
+ });
586
+
587
+ // src/cli/pdf.ts
588
+ var pdf_exports = {};
589
+ __export(pdf_exports, {
590
+ pdf: () => pdf
591
+ });
592
+ import { mkdtempSync as mkdtempSync4, rmSync as rmSync4 } from "fs";
593
+ import { tmpdir as tmpdir3 } from "os";
594
+ import { join as join5, resolve as resolve3 } from "path";
595
+ import { pathToFileURL } from "url";
596
+ async function pdf({ deckPath, out }) {
597
+ const workDir = mkdtempSync4(join5(tmpdir3(), "lectern-pdf-"));
598
+ const indexHtml = await build({ deckPath, outDir: workDir, singleFile: true });
599
+ let chromium;
600
+ try {
601
+ ;
602
+ ({ chromium } = await import("playwright"));
603
+ } catch {
604
+ rmSync4(workDir, { recursive: true, force: true });
605
+ throw new Error(
606
+ "PDF export needs Playwright. Install it with:\n pnpm add -D playwright\n npx playwright install chromium"
607
+ );
608
+ }
609
+ let browser;
610
+ try {
611
+ browser = await chromium.launch();
612
+ } catch (err) {
613
+ rmSync4(workDir, { recursive: true, force: true });
614
+ throw new Error(
615
+ `Could not launch Chromium. Install the browser once with:
616
+ npx playwright install chromium
617
+
618
+ Original error: ${err.message}`
619
+ );
620
+ }
621
+ const outAbs = resolve3(process.cwd(), out);
622
+ try {
623
+ const page = await browser.newPage();
624
+ const url = `${pathToFileURL(indexHtml).href}?print-pdf`;
625
+ await page.goto(url, { waitUntil: "load" });
626
+ await page.waitForFunction(
627
+ () => {
628
+ const w = window;
629
+ const revealReady = !!w.Reveal?.isReady?.();
630
+ const pages = document.querySelectorAll(".pdf-page").length;
631
+ const pendingMermaid = document.querySelectorAll(".mermaid:not([data-processed])").length;
632
+ return revealReady && pages > 0 && pendingMermaid === 0;
633
+ },
634
+ { timeout: 45e3 }
635
+ );
636
+ await page.pdf({
637
+ path: outAbs,
638
+ printBackground: true,
639
+ preferCSSPageSize: true
640
+ });
641
+ } finally {
642
+ await browser.close();
643
+ rmSync4(workDir, { recursive: true, force: true });
644
+ }
645
+ return outAbs;
646
+ }
647
+ var init_pdf = __esm({
648
+ "src/cli/pdf.ts"() {
649
+ "use strict";
650
+ init_build();
651
+ }
652
+ });
653
+
654
+ // src/cli/index.ts
655
+ import { existsSync as existsSync2 } from "fs";
656
+ import { resolve as resolve4 } from "path";
657
+ import { parseArgs } from "util";
658
+ var HELP = `lectern - reveal.js decks authored as TSX, styled with ENGIE Fluid.
659
+
660
+ Usage:
661
+ lectern dev [deck.tsx] [--port 4321]
662
+ lectern build [deck.tsx] [--out dist] [--no-single-file]
663
+ lectern serve [deck.tsx] [--port 4321] [--host 127.0.0.1]
664
+ lectern pdf [deck.tsx] [--out deck.pdf]
665
+ lectern rules [profile | deck.tsx] (default profile: engie)
666
+
667
+ Arguments:
668
+ deck.tsx Path to the deck entry (default: ./deck.tsx)
669
+ profile Built-in profile name to describe (default: engie);
670
+ pass a deck path to describe the profile it uses
671
+
672
+ Options:
673
+ --port, -p Dev or production server port (default 4321)
674
+ --host Production server host (default 127.0.0.1)
675
+ --out, -o Output dir (build) or file (pdf)
676
+ --no-single-file Emit separate assets instead of one inlined index.html
677
+ --help, -h Show this help
678
+ `;
679
+ function resolveDeck(input) {
680
+ const candidate = resolve4(process.cwd(), input ?? "deck.tsx");
681
+ if (!existsSync2(candidate)) {
682
+ console.error(`Deck not found: ${candidate}`);
683
+ process.exit(1);
684
+ }
685
+ return candidate;
686
+ }
687
+ async function main() {
688
+ const argv = process.argv.slice(2);
689
+ const command = argv[0];
690
+ if (!command || command === "--help" || command === "-h" || command === "help") {
691
+ console.log(HELP);
692
+ return;
693
+ }
694
+ const { values, positionals } = parseArgs({
695
+ args: argv.slice(1),
696
+ allowPositionals: true,
697
+ options: {
698
+ port: { type: "string", short: "p" },
699
+ host: { type: "string" },
700
+ out: { type: "string", short: "o" },
701
+ "single-file": { type: "boolean", default: true },
702
+ help: { type: "boolean", short: "h" }
703
+ }
704
+ });
705
+ if (values.help) {
706
+ console.log(HELP);
707
+ return;
708
+ }
709
+ if (command === "rules") {
710
+ const { rules: rules2 } = await Promise.resolve().then(() => (init_rules(), rules_exports));
711
+ const target = positionals[0];
712
+ if (target && existsSync2(resolve4(process.cwd(), target))) {
713
+ const { renderStatic: renderStatic2 } = await Promise.resolve().then(() => (init_build(), build_exports));
714
+ rules2((await renderStatic2(resolveDeck(target))).profile);
715
+ } else {
716
+ const { resolveProfile: resolveProfile2 } = await Promise.resolve().then(() => (init_profiles(), profiles_exports));
717
+ try {
718
+ rules2(resolveProfile2(target));
719
+ } catch (err) {
720
+ console.error(err.message);
721
+ process.exit(1);
722
+ }
723
+ }
724
+ return;
725
+ }
726
+ const deckPath = resolveDeck(positionals[0]);
727
+ switch (command) {
728
+ case "dev": {
729
+ const { dev: dev2 } = await Promise.resolve().then(() => (init_dev(), dev_exports));
730
+ await dev2({ deckPath, port: values.port ? Number(values.port) : 4321 });
731
+ break;
732
+ }
733
+ case "build": {
734
+ const { build: build2 } = await Promise.resolve().then(() => (init_build(), build_exports));
735
+ const outDir = values.out ?? "dist";
736
+ const file = await build2({ deckPath, outDir, singleFile: values["single-file"] });
737
+ console.log(`\u2714 Built ${file}`);
738
+ break;
739
+ }
740
+ case "serve": {
741
+ const { serve: serve2 } = await Promise.resolve().then(() => (init_serve(), serve_exports));
742
+ const { url } = await serve2({
743
+ deckPath,
744
+ port: values.port ? Number(values.port) : 4321,
745
+ host: values.host ?? "127.0.0.1"
746
+ });
747
+ console.log(
748
+ `
749
+ lectern production server running
750
+ \u279C ${url}
751
+ Built from ${deckPath}. Source changes require a restart. Ctrl+C to stop.
752
+ `
753
+ );
754
+ break;
755
+ }
756
+ case "pdf": {
757
+ const { pdf: pdf2 } = await Promise.resolve().then(() => (init_pdf(), pdf_exports));
758
+ const out = values.out ?? "deck.pdf";
759
+ const file = await pdf2({ deckPath, out });
760
+ console.log(`\u2714 Exported ${file}`);
761
+ break;
762
+ }
763
+ default:
764
+ console.error(`Unknown command: ${command}
765
+ `);
766
+ console.log(HELP);
767
+ process.exit(1);
768
+ }
769
+ }
770
+ main().catch((err) => {
771
+ console.error(err);
772
+ process.exit(1);
773
+ });
774
+ //# sourceMappingURL=index.js.map