@hajimism/dek 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ /// <reference lib="dom" />
2
+ // Annotate mode's entry: compiled apart from the player and embedded only on the dev server's
3
+ // pages for the speaker, so a built file carries none of it.
4
+
5
+ import { PAGE_ID, readPageConfig } from "../core/page.ts";
6
+ import type { PresenterSlide } from "../core/presenter-state.ts";
7
+ import { createAnnotateView } from "./annotate-view.ts";
8
+
9
+ const dataEl = document.getElementById(PAGE_ID.data);
10
+ if (dataEl?.textContent) {
11
+ createAnnotateView({
12
+ deck: readPageConfig(document.body).deck,
13
+ slides: JSON.parse(dataEl.textContent) as PresenterSlide[],
14
+ });
15
+ }
@@ -2,27 +2,35 @@ import { join } from "node:path";
2
2
 
3
3
  export { liveReloadScript } from "./live-reload.ts";
4
4
 
5
- let compiled: Promise<string> | undefined;
5
+ let player: Promise<string> | undefined;
6
+ let annotate: Promise<string> | undefined;
6
7
 
8
+ /** The player every deck page runs. */
7
9
  export function playerScript(): Promise<string> {
8
- compiled ??= compilePlayer();
9
- return compiled;
10
+ player ??= compile("browser.ts", "player");
11
+ return player;
10
12
  }
11
13
 
12
- async function compilePlayer(): Promise<string> {
14
+ /** Annotate mode, which only the dev server's pages for the speaker run, after the player. */
15
+ export function annotateScript(): Promise<string> {
16
+ annotate ??= compile("annotate.ts", "annotate mode");
17
+ return annotate;
18
+ }
19
+
20
+ async function compile(entry: string, what: string): Promise<string> {
13
21
  const result = await Bun.build({
14
- entrypoints: [join(import.meta.dir, "browser.ts")],
22
+ entrypoints: [join(import.meta.dir, entry)],
15
23
  target: "browser",
16
24
  format: "iife",
17
25
  minify: true,
18
26
  });
19
27
  if (!result.success) {
20
28
  const details = result.logs.map((log) => String(log)).join("\n");
21
- throw new Error(`failed to compile player\n${details}`);
29
+ throw new Error(`failed to compile ${what}\n${details}`);
22
30
  }
23
31
  const output = result.outputs[0];
24
32
  if (!output) {
25
- throw new Error("failed to compile player: no output");
33
+ throw new Error(`failed to compile ${what}: no output`);
26
34
  }
27
35
  return output.text();
28
36
  }
package/src/server/dev.ts CHANGED
@@ -2,7 +2,7 @@ import { join } from "node:path";
2
2
  import { DekError } from "../core/error.ts";
3
3
  import type { PlaywrightRunner } from "../core/playwright.ts";
4
4
  import { locateDeck, type Project, resolveProject } from "../core/resolve.ts";
5
- import { liveReloadScript, playerScript } from "../runtime/player.ts";
5
+ import { annotateScript, liveReloadScript, playerScript } from "../runtime/player.ts";
6
6
  import {
7
7
  clearance,
8
8
  mayRead,
@@ -71,6 +71,7 @@ export async function startDevServer(options: DevServerOptions): Promise<DevServ
71
71
  const embed = {
72
72
  playerScript: await playerScript(),
73
73
  liveReloadScript: liveReloadScript(),
74
+ annotateScript: await annotateScript(),
74
75
  };
75
76
 
76
77
  const pages = createDevPages({
@@ -13,7 +13,7 @@ export type DevPages = {
13
13
 
14
14
  /** The pages a dev server renders, each kept until `clear`. */
15
15
  export function createDevPages(options: {
16
- embed: { playerScript: string; liveReloadScript: string };
16
+ embed: { playerScript: string; liveReloadScript: string; annotateScript: string };
17
17
  remote: boolean;
18
18
  /** Embedded on the presenter page, so its stream and moves are let through. */
19
19
  password: string | undefined;
@@ -44,6 +44,7 @@ export function createDevPages(options: {
44
44
  mode,
45
45
  includeNotes: mode === "presenter" || !remote,
46
46
  liveReloadScript: embed.liveReloadScript,
47
+ annotateScript: embed.annotateScript,
47
48
  ...(mode === "presenter" && password ? { liveToken: password } : {}),
48
49
  },
49
50
  }),
@@ -75,10 +75,16 @@ export function routeRequest(req: Request, ctx: RouteContext): Routed {
75
75
  // A slide the script does not list has no place in the deck, so no page shows it.
76
76
  const sections = deck?.deck.sections ?? [];
77
77
  const index = sections.findIndex((section) => section.slug === route.slug);
78
- const html = deck && index >= 0 && deckSlides(deck).written(route.slug);
79
- return html
78
+ const slides = deck && index >= 0 ? deckSlides(deck) : undefined;
79
+ const html = slides?.written(route.slug);
80
+ const source = slides?.source(route.slug);
81
+ return html && source
80
82
  ? htmlResponse(
81
- stampSlide(html, { slug: route.slug, place: slidePlace(sections, index) }),
83
+ stampSlide(html, {
84
+ slug: route.slug,
85
+ place: slidePlace(sections, index),
86
+ source,
87
+ }),
82
88
  )
83
89
  : notFound();
84
90
  },