presently 0.16.0 → 0.17.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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/bake/presently/export.rb +187 -45
  4. data/bake/presently/recordings.rb +72 -0
  5. data/context/animating-slides.md +25 -1
  6. data/context/getting-started.md +92 -2
  7. data/lib/presently/application.rb +157 -30
  8. data/lib/presently/display_view.rb +7 -7
  9. data/lib/presently/environment/application.rb +17 -1
  10. data/lib/presently/export.rb +15 -13
  11. data/lib/presently/export.xrb +4 -0
  12. data/lib/presently/home_view.rb +65 -0
  13. data/lib/presently/page.rb +29 -22
  14. data/lib/presently/playback.rb +71 -0
  15. data/lib/presently/playback.xrb +59 -0
  16. data/lib/presently/presentation.rb +5 -0
  17. data/lib/presently/presenter_view.rb +6 -6
  18. data/lib/presently/recording_view.rb +158 -0
  19. data/lib/presently/recordings/normalizer.rb +183 -0
  20. data/lib/presently/recordings.rb +100 -0
  21. data/lib/presently/slide.rb +35 -3
  22. data/lib/presently/slide_assets.rb +101 -0
  23. data/lib/presently/slide_renderer.rb +2 -1
  24. data/lib/presently/slide_view.rb +23 -0
  25. data/lib/presently/stylesheet.rb +112 -0
  26. data/lib/presently/version.rb +1 -1
  27. data/lib/presently.rb +5 -0
  28. data/public/{code-focus.js → _components/@socketry/presently/Presently/CodeFocus.js} +1 -0
  29. data/public/{slide-scripts.js → _components/@socketry/presently/Presently/Scripts.js} +1 -1
  30. data/public/{slide.js → _components/@socketry/presently/Presently/Slide.js} +70 -13
  31. data/public/_components/@socketry/presently/Presently/SlideRendering.js +109 -0
  32. data/public/_components/@socketry/presently/Presently.js +4 -0
  33. data/public/_components/@socketry/syntax/Syntax/CodeElement.js +116 -37
  34. data/public/_components/@socketry/syntax/Syntax/Language/ruby.js +8 -4
  35. data/public/_components/@socketry/syntax/Syntax/Language.js +5 -2
  36. data/public/_components/@socketry/syntax/Syntax/Match.js +8 -2
  37. data/public/_components/@socketry/syntax/Syntax/Rule.js +21 -5
  38. data/public/_components/@socketry/syntax/Syntax.js +2 -2
  39. data/public/_components/@socketry/syntax/package.json +6 -5
  40. data/public/_components/@socketry/syntax/readme.md +7 -1
  41. data/public/_components/@socketry/syntax/themes/base/syntax.css +11 -0
  42. data/public/_components/@socketry/syntax/themes/theming.md +11 -0
  43. data/public/_static/index.css +381 -0
  44. data/public/application.js +29 -64
  45. data/public/export.js +1 -3
  46. data/public/playback.js +266 -0
  47. data/public/recorder.js +282 -0
  48. data/readme.md +41 -13
  49. data/releases.md +8 -0
  50. data.tar.gz.sig +0 -0
  51. metadata +34 -8
  52. metadata.gz.sig +0 -0
  53. data/bake/presently/node.rb +0 -47
  54. data/lib/presently/page.xrb +0 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c2eaa843e93a1ef3f3c97b0e89c80a3ee4484ddbee4c105ca39bc7c324671ea
4
- data.tar.gz: bc27aa664ca531b38da8b807e3fcb438a41c4338a180c1ddd39fc1daa0c549ed
3
+ metadata.gz: 76e4ab0cea03d4eefe8864d4c81f0193615ba5bb4548d65d19fd93992408a746
4
+ data.tar.gz: b2315554cb96689cf429c04d3a914525cc3294f5e01bb1cc39b0cf7a475d8b6d
5
5
  SHA512:
6
- metadata.gz: 98959ac207c29fa8a4bf444e0d1e476e584183615d04abed09c8f74cda3a338ed61f9517f67d5e7e5bb40aa624c352100bf1c2f36c61663a81f61ec509fe52d8
7
- data.tar.gz: 30ca2a30e72d1f0c0dbc71b31786349ecd8d8c70eae5d69f29e701e77cd2f39487909a71a4699b2be9b70169cc170065313da35e46394ab92d0b378f3849e38a
6
+ metadata.gz: 34fbbeee043bbdd4241049e639388661808245d0d3001256d979745199074c30a867ffc4782f30a728d494453fdadf723589ff3f44f44f08a2dd65b11bdb3b50
7
+ data.tar.gz: eb40ee8ba2bfa106b86e9641ece873ae27043e137c0fe3ae69ff714e24562b1b01d4a58de15681655e74348a4bcbec9f965c8bc6ac65166d63bf7c4378c58282
checksums.yaml.gz.sig CHANGED
Binary file
@@ -6,6 +6,7 @@
6
6
  def initialize(context)
7
7
  super
8
8
 
9
+ require "base64"
9
10
  require "fileutils"
10
11
  require "uri"
11
12
  end
@@ -23,12 +24,7 @@ end
23
24
  # @parameter timing [Boolean] Include slide duration and elapsed time. Default: `true`.
24
25
  # @parameter timeout [Integer] Seconds to wait for the page to signal readiness. Default: `60`.
25
26
  def pdf(output: "presentation.pdf", slides_root: "slides", notes: true, speaker: true, timing: true, slide_width_px: 1920, slide_height_px: 1080, notes_height_px: 300, timeout: 60)
26
- require "async"
27
- require "async/http/endpoint"
28
- require "async/service"
29
- require "async/webdriver"
30
27
  require "presently"
31
- require "presently/environment/application"
32
28
 
33
29
  page_size = Presently::Export::PageSize.new(
34
30
  slide_width_px: slide_width_px,
@@ -43,6 +39,121 @@ def pdf(output: "presentation.pdf", slides_root: "slides", notes: true, speaker:
43
39
  slide_width_px: slide_width_px, slide_height_px: slide_height_px, notes_height_px: notes_height_px
44
40
  )
45
41
 
42
+ with_browser_session(slides_root: slides_root, timeout: timeout) do |session, base_url|
43
+ session.resize_window(
44
+ page_size.slide_width_px,
45
+ page_size.slide_height_px
46
+ )
47
+
48
+ session.navigate_to("#{base_url}/export?#{query}")
49
+
50
+ # Block until export.js dispatches presently:ready.
51
+ session.execute_async(<<~JS)
52
+ const done = arguments[arguments.length - 1];
53
+ if (window.__PRESENTLY_READY) { done(); return; }
54
+ document.addEventListener('presently:ready', () => done(), {once: true});
55
+ JS
56
+
57
+ pdf_data = session.print(
58
+ background: true,
59
+ margin: {top: 0, bottom: 0, left: 0, right: 0},
60
+ page: {width: page_size.slide_width_cm, height: page_height_cm},
61
+ shrink_to_fit: false
62
+ )
63
+
64
+ FileUtils.mkdir_p(File.dirname(File.expand_path(output)))
65
+ File.write(output, pdf_data, mode: "wb")
66
+ end
67
+
68
+ return {path: output}
69
+ end
70
+
71
+ # Export the narrated presentation to an MP4 video.
72
+ #
73
+ # This uses Chromium's experimental `Page.startScreenRecording` DevTools
74
+ # command. Until that command reaches Chrome for Testing, pass matching
75
+ # Chromium and ChromeDriver paths explicitly (or through the
76
+ # `PRESENTLY_CHROME_PATH` and `PRESENTLY_CHROMEDRIVER_PATH` environment
77
+ # variables).
78
+ #
79
+ # @parameter output [String] Output MP4 path. Default: `presentation.mp4`.
80
+ # @parameter slides_root [String] The slides directory. Default: `slides`.
81
+ # @parameter width [Integer] Maximum video width. Default: `1920`.
82
+ # @parameter height [Integer] Maximum video height. Default: `1080`.
83
+ # @parameter frame_rate [Integer] Maximum video frame rate. Default: `30`.
84
+ # @parameter timeout [Integer] Seconds to wait for the playback page to load. Default: `60`.
85
+ # @parameter duration_limit [Integer] Maximum presentation duration in seconds. Default: `3600`.
86
+ # @parameter browser_version [String] Chrome for Testing version used when explicit paths are omitted. Default: `canary`.
87
+ # @parameter browser_path [String | Nil] Path to a Chromium executable supporting screen recording.
88
+ # @parameter driver_path [String | Nil] Path to a matching ChromeDriver executable.
89
+ def video(output: "presentation.mp4", slides_root: "slides", width: 1920, height: 1080, frame_rate: 30, timeout: 60, duration_limit: 3600, browser_version: "canary", browser_path: nil, driver_path: nil)
90
+ browser_path ||= ENV["PRESENTLY_CHROME_PATH"]
91
+ driver_path ||= ENV["PRESENTLY_CHROMEDRIVER_PATH"]
92
+
93
+ with_browser_session(
94
+ slides_root: slides_root,
95
+ timeout: timeout,
96
+ script_timeout: duration_limit,
97
+ browser_version: browser_version,
98
+ browser_path: browser_path,
99
+ driver_path: driver_path,
100
+ chrome_arguments: ["--autoplay-policy=no-user-gesture-required", "--hide-scrollbars"]
101
+ ) do |session, base_url|
102
+ resize_viewport(session, width, height)
103
+ session.navigate_to("#{base_url}/playback?autoplay=false&controls=false")
104
+
105
+ ready = session.execute_async(<<~JS)
106
+ const done = arguments[arguments.length - 1];
107
+ if (window.__PRESENTLY_PLAYBACK_ERROR) { done({error: window.__PRESENTLY_PLAYBACK_ERROR}); return; }
108
+ if (window.__PRESENTLY_PLAYBACK_READY) { done({ready: true}); return; }
109
+ document.addEventListener('presently:playback-error', event => done({error: event.detail.message}), {once: true});
110
+ document.addEventListener('presently:playback-ready', () => done({ready: true}), {once: true});
111
+ JS
112
+
113
+ raise "Playback preparation failed: #{ready["error"]}" if ready["error"]
114
+
115
+ recording_started = false
116
+ stream = nil
117
+ playback = nil
118
+
119
+ begin
120
+ devtools(session, "Page.startScreenRecording", audio: true, maxWidth: width, maxHeight: height, frameRate: frame_rate)
121
+ recording_started = true
122
+
123
+ session.execute("window.__PRESENTLY_PLAYBACK_START();")
124
+ playback = session.execute_async(<<~JS)
125
+ const done = arguments[arguments.length - 1];
126
+ if (window.__PRESENTLY_PLAYBACK_ERROR) { done({error: window.__PRESENTLY_PLAYBACK_ERROR}); return; }
127
+ if (window.__PRESENTLY_PLAYBACK_FINISHED) { done({finished: true}); return; }
128
+ document.addEventListener('presently:playback-error', event => done({error: event.detail.message}), {once: true});
129
+ document.addEventListener('presently:playback-finished', () => done({finished: true}), {once: true});
130
+ JS
131
+ ensure
132
+ if recording_started
133
+ stream = devtools(session, "Page.stopScreenRecording")["stream"]
134
+ end
135
+ end
136
+
137
+ raise "Playback failed: #{playback["error"]}" if playback&.dig("error")
138
+ raise "Chromium did not return the recorded video stream!" unless stream
139
+
140
+ write_devtools_stream(session, stream, output)
141
+ end
142
+
143
+ return {path: output}
144
+ end
145
+
146
+ private
147
+
148
+ def with_browser_session(slides_root:, timeout:, script_timeout: timeout, browser_version: "stable", browser_path: nil, driver_path: nil, chrome_arguments: [])
149
+ require "async"
150
+ require "async/http/endpoint"
151
+ require "async/service"
152
+ require "async/webdriver"
153
+ require "presently/environment/application"
154
+
155
+ result = nil
156
+
46
157
  Async do |task|
47
158
  # Bind port 0 first so we know the actual address before starting the server.
48
159
  bound_endpoint = Async::HTTP::Endpoint.parse("http://localhost:0").bound
@@ -55,7 +166,7 @@ def pdf(output: "presentation.pdf", slides_root: "slides", notes: true, speaker:
55
166
  endpoint: Async::HTTP::Endpoint.parse("http://localhost", bound_endpoint)
56
167
  )
57
168
 
58
- # PDF export always requires an HTTP server, regardless of the configured
169
+ # Export always requires an HTTP server, regardless of the configured
59
170
  # Lively transport:
60
171
  transport = environment.with(environment.evaluator.http_environment)
61
172
  evaluator = transport.evaluator
@@ -63,53 +174,22 @@ def pdf(output: "presentation.pdf", slides_root: "slides", notes: true, speaker:
63
174
  server_task = task.async{server.run}
64
175
 
65
176
  begin
66
- # Derive the actual base URL from the bound socket address.
67
- base_url = nil
68
- bound_endpoint.local_address_endpoint.each do |endpoint|
69
- address = endpoint.address
70
- host = address.ipv6? ? "[#{address.ip_address}]" : address.ip_address
71
- base_url = "http://#{host}:#{address.ip_port}"
72
- break
73
- end
74
-
75
- export_url = "#{base_url}/export?#{query}"
76
-
77
- bridge = Async::WebDriver::Bridge::Chrome.for(:stable)
177
+ base_url = export_base_url(bound_endpoint)
178
+ bridge = chrome_bridge(browser_version, browser_path, driver_path)
78
179
  driver = bridge.start
79
180
 
80
181
  begin
81
182
  client = Async::WebDriver::Client.open(driver.endpoint)
82
183
 
83
184
  begin
84
- session = client.session(bridge.default_capabilities)
185
+ capabilities = bridge.default_capabilities
186
+ capabilities[:alwaysMatch][:"goog:chromeOptions"][:args].concat(chrome_arguments)
187
+ session = client.session(capabilities)
85
188
 
86
189
  begin
87
- session.resize_window(
88
- page_size.slide_width_px,
89
- page_size.slide_height_px
90
- )
91
-
92
190
  session.page_load_timeout = timeout * 1000
93
- session.script_timeout = timeout * 1000
94
-
95
- session.navigate_to(export_url)
96
-
97
- # Block until export.js dispatches presently:ready.
98
- session.execute_async(<<~JS)
99
- const done = arguments[arguments.length - 1];
100
- if (window.__PRESENTLY_READY) { done(); return; }
101
- document.addEventListener('presently:ready', () => done(), {once: true});
102
- JS
103
-
104
- pdf_data = session.print(
105
- background: true,
106
- margin: {top: 0, bottom: 0, left: 0, right: 0},
107
- page: {width: page_size.slide_width_cm, height: page_height_cm},
108
- shrink_to_fit: false
109
- )
110
-
111
- FileUtils.mkdir_p(File.dirname(File.expand_path(output)))
112
- File.write(output, pdf_data, mode: "wb")
191
+ session.script_timeout = script_timeout * 1000
192
+ result = yield(session, base_url)
113
193
  ensure
114
194
  session.close
115
195
  end
@@ -128,5 +208,67 @@ def pdf(output: "presentation.pdf", slides_root: "slides", notes: true, speaker:
128
208
  end
129
209
  end
130
210
 
131
- return {path: output}
211
+ return result
212
+ end
213
+
214
+ def chrome_bridge(browser_version, browser_path, driver_path)
215
+ if browser_path || driver_path
216
+ options = {}
217
+ options[:browser_path] = File.expand_path(browser_path) if browser_path
218
+ options[:driver_path] = File.expand_path(driver_path) if driver_path
219
+
220
+ Async::WebDriver::Bridge::Chrome.new(**options)
221
+ else
222
+ Async::WebDriver::Bridge::Chrome.for(browser_version.to_sym)
223
+ end
224
+ end
225
+
226
+ def export_base_url(bound_endpoint)
227
+ bound_endpoint.local_address_endpoint.each do |endpoint|
228
+ address = endpoint.address
229
+ host = address.ipv6? ? "[#{address.ip_address}]" : address.ip_address
230
+ return "http://#{host}:#{address.ip_port}"
231
+ end
232
+
233
+ raise "Could not determine the export server address!"
234
+ end
235
+
236
+ def resize_viewport(session, width, height)
237
+ # WebDriver sizes the outer window, while screen recording captures the page
238
+ # viewport. Measure the browser decoration after an initial resize and
239
+ # compensate so the recorded video has the requested dimensions.
240
+ session.resize_window(width, height)
241
+ dimensions = session.execute(<<~JS)
242
+ return {outerWidth, outerHeight, innerWidth, innerHeight};
243
+ JS
244
+
245
+ session.resize_window(
246
+ width + dimensions["outerWidth"] - dimensions["innerWidth"],
247
+ height + dimensions["outerHeight"] - dimensions["innerHeight"]
248
+ )
249
+ end
250
+
251
+ def devtools(session, command, **parameters)
252
+ session.post("goog/cdp/execute", {cmd: command, params: parameters})
253
+ rescue Async::WebDriver::Error => error
254
+ raise "Chromium does not support #{command}: #{error.message}"
255
+ end
256
+
257
+ def write_devtools_stream(session, stream, output)
258
+ path = File.expand_path(output)
259
+ FileUtils.mkdir_p(File.dirname(path))
260
+
261
+ begin
262
+ File.open(path, "wb") do |file|
263
+ loop do
264
+ chunk = devtools(session, "IO.read", handle: stream, size: 1024 * 1024)
265
+ data = chunk["data"]
266
+ data = Base64.strict_decode64(data) if chunk["base64Encoded"]
267
+ file.write(data)
268
+ break if chunk["eof"]
269
+ end
270
+ end
271
+ ensure
272
+ devtools(session, "IO.close", handle: stream)
273
+ end
132
274
  end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2026, by Samuel Williams.
5
+
6
+ def initialize(context)
7
+ super
8
+
9
+ require "pathname"
10
+ require "presently/recordings/normalizer"
11
+ end
12
+
13
+ # Normalize all completed slide recordings to a consistent loudness.
14
+ #
15
+ # Original recordings are preserved under `input_root`. Normalized WebM/Opus
16
+ # files are written to the corresponding paths under `output_root`. Existing
17
+ # outputs newer than their source are skipped unless `force` is enabled.
18
+ #
19
+ # @parameter input_root [String] Source recordings directory. Default: `audio`.
20
+ # @parameter output_root [String] Normalized recordings directory. Default: `audio-normalized`.
21
+ # @parameter integrated_loudness [Float] Target integrated loudness in LUFS. Default: `-16.0`.
22
+ # @parameter true_peak [Float] Maximum true peak in dBTP. Default: `-1.5`.
23
+ # @parameter loudness_range [Float] Target loudness range in LU. Default: `11.0`.
24
+ # @parameter bitrate [String] Output Opus bitrate. Default: `128k`.
25
+ # @parameter force [Boolean] Normalize recordings even when output is current. Default: `false`.
26
+ # @parameter command [String] FFmpeg executable. Default: `ffmpeg`.
27
+ def normalize(input_root: "audio", output_root: "audio-normalized", integrated_loudness: -16.0, true_peak: -1.5, loudness_range: 11.0, bitrate: "128k", force: false, command: "ffmpeg")
28
+ input_root = File.expand_path(input_root)
29
+ output_root = File.expand_path(output_root)
30
+
31
+ if input_root == output_root
32
+ raise ArgumentError, "output_root must be different from input_root so originals are preserved!"
33
+ end
34
+
35
+ files = Dir.glob(File.join(input_root, "**", "*.webm")).sort
36
+ if files.empty?
37
+ puts "No WebM recordings found under #{input_root}."
38
+ return {processed: 0, skipped: 0, output_root: output_root}
39
+ end
40
+
41
+ normalizer = Presently::Recordings::Normalizer.new(command: command)
42
+ processed = 0
43
+ skipped = 0
44
+
45
+ files.each do |input_path|
46
+ relative_path = Pathname.new(input_path).relative_path_from(Pathname.new(input_root)).to_s
47
+ output_path = File.join(output_root, relative_path)
48
+
49
+ if !force && File.file?(output_path) && File.mtime(output_path) >= File.mtime(input_path)
50
+ puts "Skipping #{relative_path} (already normalized)."
51
+ skipped += 1
52
+ next
53
+ end
54
+
55
+ print "Normalizing #{relative_path}... "
56
+ measurements = normalizer.normalize(
57
+ input_path,
58
+ output_path,
59
+ integrated_loudness: integrated_loudness,
60
+ true_peak: true_peak,
61
+ loudness_range: loudness_range,
62
+ bitrate: bitrate,
63
+ )
64
+ input = measurements.fetch(:input)
65
+ output = measurements.fetch(:output)
66
+ puts "#{input.fetch("input_i")} LUFS → #{output.fetch("input_i")} LUFS, #{output.fetch("input_tp")} dBTP"
67
+ processed += 1
68
+ end
69
+
70
+ puts "Normalized #{processed} recording#{"s" unless processed == 1}; skipped #{skipped}."
71
+ return {processed: processed, skipped: skipped, output_root: output_root}
72
+ end
@@ -25,7 +25,7 @@ slide.find("li").show(1)
25
25
  ```
26
26
  ~~~
27
27
 
28
- The script receives a `slide` object — an instance of the `Slide` class from `slide.js` — scoped to the current slide's body.
28
+ The script receives a `slide` object — an instance of the `Slide` class exported by `@socketry/presently` — scoped to the current slide's body.
29
29
 
30
30
  If the script contains a syntax error or throws an exception, the error is logged to the browser console and the presentation continues unaffected.
31
31
 
@@ -194,6 +194,30 @@ All timeouts registered via `slide.after()` (and the underlying `slide.setTimeou
194
194
 
195
195
  The global `setTimeout` in slide scripts is also automatically tracked — you can use it directly and it will be cancelled on slide change.
196
196
 
197
+ ## Slide Lifetime and Cleanup
198
+
199
+ Slide scripts can start resources other than timers, including audio, video, observers, animations, and event listeners. Use `slide.defer(callback)` to release those resources when the slide is deactivated:
200
+
201
+ ``` javascript
202
+ const audio = new Audio("introduction.mp3")
203
+ audio.play()
204
+
205
+ slide.defer(() => {
206
+ audio.pause()
207
+ })
208
+ ```
209
+
210
+ Deferred callbacks run in reverse registration order when the slide changes. Registering a callback after the slide has already been deactivated runs it immediately, preventing asynchronously-created resources from escaping the slide's lifetime.
211
+
212
+ The `slide.signal` getter exposes an `AbortSignal` which is aborted at the same time. Browser APIs which support abort signals can therefore be bound directly to the slide:
213
+
214
+ ``` javascript
215
+ const button = slide.element.querySelector("button")
216
+ button.addEventListener("click", handleClick, {signal: slide.signal})
217
+ ```
218
+
219
+ Aborting the signal removes this event listener; it does not invoke `handleClick`. Use `slide.defer(...)` for resources which do not accept an `AbortSignal`.
220
+
197
221
  ## Looping Animations with `slide.loop()`
198
222
 
199
223
  To repeat an animation indefinitely, use `slide.loop()`. The callback receives a fresh `SlideContext` each iteration and can use `after()` to schedule steps in the same way as a regular chain. The loop waits for all steps to complete and then restarts, with an optional extra pause between iterations.
@@ -79,6 +79,43 @@ Each slide has three parts:
79
79
  2. **Content** with Markdown headings that become named sections for the template.
80
80
  3. **Presenter notes** after a `---` separator in the body (optional).
81
81
 
82
+ ### Styling Slides
83
+
84
+ CSS can be colocated with the slides it styles:
85
+
86
+ ``` text
87
+ slides/
88
+ ├── style.css
89
+ ├── 010-introduction.md
90
+ └── 020-scheduling/
91
+ ├── style.css
92
+ ├── 010-overview.md
93
+ ├── 020-queue.md
94
+ └── 020-queue.css
95
+ ```
96
+
97
+ `slides/style.css` applies globally. A nested `style.css` applies to every slide below that directory, while a CSS file matching a Markdown filename applies only to that slide. In the example above, `020-scheduling/style.css` applies to both scheduling slides and `020-queue.css` applies only to `020-queue.md`.
98
+
99
+ Presently automatically wraps nested and slide-specific stylesheets in an [`@scope`](https://developer.mozilla.org/en-US/docs/Web/CSS/@scope) rule rooted at the rendered slide. Write these files as scoped CSS fragments containing ordinary style rules and nestable grouping rules such as `@media`, `@supports`, `@container`, and `@layer`. Keep stylesheet-level rules such as `@charset`, `@import`, and `@namespace`, and globally named definitions such as `@font-face`, `@keyframes`, and `@property`, in the root `slides/style.css` or the existing `public/_static/custom.css`.
100
+
101
+ Relative images and fonts remain adjacent to the stylesheet that uses them:
102
+
103
+ ``` css
104
+ .architecture {
105
+ background-image: url("architecture.svg");
106
+ }
107
+ ```
108
+
109
+ Presently uses `protocol-media-registry` to determine asset content types. Files with unrecognized media types are not served.
110
+
111
+ Relative images embedded in Markdown resolve from the Markdown file's directory, including images in included Markdown files:
112
+
113
+ ``` markdown
114
+ ![Architecture](architecture.svg)
115
+ ```
116
+
117
+ Presently loads each discovered stylesheet once in deterministic presentation order. Directory styles are loaded from parent to child before the matching slide sidecar, so more specific styles naturally appear later in the cascade. The same stylesheets are used by the display, presenter, recorder, playback, and export interfaces.
118
+
82
119
  ### Running the Presentation
83
120
 
84
121
  Start the server from your presentation directory:
@@ -87,13 +124,66 @@ Start the server from your presentation directory:
87
124
  $ presently
88
125
  ```
89
126
 
90
- Then open two browser windows:
127
+ Open the launcher, or go directly to one of the presentation interfaces:
91
128
 
92
- - `http://localhost:9292/` — the audience display.
129
+ - `http://localhost:9292/` — the interface launcher.
130
+ - `http://localhost:9292/display` — the audience display.
93
131
  - `http://localhost:9292/presenter` — the presenter console.
132
+ - `http://localhost:9292/record` — the slide narration recorder.
133
+ - `http://localhost:9292/playback` — automatic playback with recorded narration.
94
134
 
95
135
  Advancing slides in either window updates both in real-time via WebSockets.
96
136
 
137
+ ### Recording Slide Narration
138
+
139
+ The recording interface is separate from the presenter console because narration is an authoring workflow: each slide can be recorded, reviewed, retaken, and explicitly saved without changing the live presentation controls.
140
+
141
+ Presently records WebM/Opus audio using the browser microphone, preserving its dynamics for offline normalization. A short delayed audio pipeline excludes approximately 100 milliseconds around the mouse clicks at the beginning and end. Saved recording paths mirror their slide paths under the presentation's `audio/` directory:
142
+
143
+ ``` text
144
+ slides/020-problem/010-overview.md
145
+ audio/020-problem/010-overview.webm
146
+ ```
147
+
148
+ To record narration:
149
+
150
+ 1. Open `http://localhost:9292/record` in a browser with WebM/Opus `MediaRecorder` support.
151
+ 2. Select the slide and press **Record**.
152
+ 3. Press **Stop**, then review the recording with the audio player.
153
+ 4. Press **Save** to replace that slide's existing narration.
154
+
155
+ Navigating away before saving discards the retake and preserves the previously saved recording.
156
+
157
+ To normalize completed takes to a consistent `-16 LUFS` target, install FFmpeg and run:
158
+
159
+ ``` shell
160
+ bundle exec bake presently:recordings:normalize
161
+ ```
162
+
163
+ Originals remain under `audio/`; normalized WebM/Opus copies are written under `audio-normalized/` using the same relative paths. The task skips outputs that are newer than their source, so it can be rerun after recording additional slides.
164
+
165
+ ### Playing Recorded Narration
166
+
167
+ Open `http://localhost:9292/playback` after every slide has a recording. Press **Start presentation** and Presently will play each narration track, run the slide's script, preserve its transition, and advance when the narration ends. Normalized recordings are preferred, with the corresponding original recording used as a fallback.
168
+
169
+ For browser automation or video capture, open:
170
+
171
+ ``` text
172
+ http://localhost:9292/playback?autoplay=true&controls=false
173
+ ```
174
+
175
+ The playback page sets `window.__PRESENTLY_PLAYBACK_READY` after its slides, fonts, syntax highlighting, and audio metadata are loaded. It sets `window.__PRESENTLY_PLAYBACK_FINISHED` when the final narration ends. It also dispatches `presently:playback-ready` and `presently:playback-finished` events for event-driven integrations.
176
+
177
+ To export the narrated presentation directly to MP4, use a Chromium and matching ChromeDriver build that supports the experimental `Page.startScreenRecording` DevTools command:
178
+
179
+ ``` shell
180
+ PRESENTLY_CHROME_PATH=/path/to/chromium \
181
+ PRESENTLY_CHROMEDRIVER_PATH=/path/to/chromedriver \
182
+ bundle exec bake presently:export:video output=presentation.mp4
183
+ ```
184
+
185
+ The defaults are 1920×1080 at up to 30 frames per second. The exporter starts an isolated Presently server, waits for playback to become ready, records until the final narration ends, and writes Chromium's MP4 stream to the selected output path.
186
+
97
187
  ### Keyboard Controls
98
188
 
99
189
  - **Arrow Right / Space / Page Down** — next slide.