Media Chrome Video Figure Design
Status: Superseded by Video Player Overhaul
Replace the browser’s native video controls with media-chrome web components, styled to match the Almanack aesthetic. Keep the Almanack-specific annotation, overlay, and margin-box systems intact.
Motivation
Three goals drive this change:
-
Better player chrome. The native
<video controls>varies by browser, lacks keyboard shortcuts, and renders chapter markers poorly. media-chrome gives us composable, accessible, keyboard- navigable controls with chapter segments in the scrub bar. -
Reduced maintenance. Offload play/pause, volume, scrub, and fullscreen to a maintained library. Focus our code on what is uniquely Almanack: margin annotations, SVG overlays, quality switching for static files.
-
Future capabilities. media-chrome supports HLS via
<hls-video>, adaptive bitrate, and rendition menus. When the 2.6 GBfinal_restored.mp4needs segmented delivery, the plumbing is ready.
What Changes, What Stays
media-chrome takes over
| Concern | Now | After |
|---|---|---|
| Play/pause, volume, scrub | Browser native | <media-play-button>, <media-time-range>, etc. |
| Fullscreen | Browser native | <media-fullscreen-button> |
| Keyboard shortcuts | Browser defaults only | media-chrome hotkeys (space, arrows) |
| Chapter markers | Browser renders natively (poorly) | Chapter segments in scrub bar, automatic from VTT |
| Quality picker | <select> in .video-figure-toolbar |
Custom item in settings popover |
| Annotation toggle | <button> in .video-figure-toolbar |
Custom item in settings popover |
Stays ours
- VTT fetching and JSON cue parsing (custom parser)
- Margin annotation injection via
Sidenotes.injectMarginBox() - SVG overlay shapes and connector lines
- Mobile annotation overlay fallback
- Annotation marker dots on the scrub bar (new)
- Time fragment handling (
#t=) - HTMX reinitialization
localStoragepersistence for annotation toggle
The .video-figure-toolbar div disappears entirely. Its contents
migrate into media-chrome’s <media-control-bar>.
Markup Contract
The article markdown does not change. Same data-video-figure,
data-label sources, <track> elements:
<figure class="figure" data-video-figure>
<video controls preload="none" poster="assets/poster.jpg">
<source src="assets/video-360p.mp4" type="video/mp4"
data-label="Original (360p)" default>
<source src="assets/video-enhanced-360p.mp4" type="video/mp4"
data-label="Enhanced (360p)">
<track kind="metadata" src="assets/annotations.vtt">
<track kind="chapters" src="assets/chapters.vtt">
</video>
<figcaption>...</figcaption>
</figure>
At enhancement time, JS wraps the <video> in a
<media-controller>, adds slot="media", removes controls, and
builds the control bar. If JS fails, controls stays and the reader
gets native browser playback.
Control Bar Layout
[Play] [0:32/10:53] [===*===|==*====*==|=======*=] [gear] [Fullscreen]
^ ^ ^
annotation chapter annotation
markers divider markers
Components, left to right:
<media-play-button>— play/pause toggle<media-time-display showduration>— current time / duration<media-time-range>— scrub bar with automatic chapter segments- Settings gear button — opens custom popover
<media-fullscreen-button>— fullscreen toggle
No volume controls (keyboard arrows handle volume; mobile uses hardware). No PiP, no playback rate. Add later if needed.
Settings Popover
A custom popover anchored to the gear icon. Opens upward, closes on outside click or Escape. Contains:
Quality picker — lists <source data-label> options as radio
items. On selection: capture currentTime, switch video.src,
restore position on loadedmetadata. Same logic as today.
Annotations toggle — on/off switch. When off: clears margin
boxes, SVG shapes, mobile overlay. State in localStorage, keyed
by container ID.
The popover is plain DOM inside <media-control-bar>. No
media-chrome dependency for this part.
Annotation Markers on the Scrub Bar
After the VTT parser loads metadata cues, calculate each cue’s start
time as a percentage of total duration. Inject small 4px square
elements (warm orange, rgba(255, 200, 50, 0.7)) in a container
overlaid on <media-time-range> with pointer-events: none.
Recalculate on loadedmetadata and on source switch. Markers are
visual only — clicks pass through to the scrub bar underneath.
Styling
media-chrome CSS custom properties inherit the Almanack palette:
media-controller {
--media-icon-color: var(--color-text);
--media-control-background: var(--color-bg);
--media-range-track-background: var(--color-light);
--media-range-bar-color: var(--color-text);
--media-range-thumb-background: var(--color-text);
--media-range-thumb-border-radius: 0;
--media-range-track-border-radius: 0;
--media-font: var(--font-body);
}
Sharp corners, body font, black-on-cream. The warm orange accent
stays reserved for annotation elements. The control bar gets a thin
border-top separating it from the video.
Vendoring and Loading
Vendored, not CDN. Download the media-chrome ESM bundle into
assets/js/vendor/media-chrome.esm.js. Self-hosted, IPFS-compatible,
no build step. Updates are manual and intentional.
Self-loading from the figure. The <script type="module"> tag
lives in the figure markup, not in base.html. Pages without video
figures load zero extra JS. video-figure.js becomes an ES module
that imports media-chrome:
import './vendor/media-chrome.esm.js';
// ... enhance [data-video-figure] elements
This self-loading pattern becomes the standard for all interactive figures going forward.
Progressive Degradation
| Feature | Without JS | media-chrome fails | Everything loads |
|---|---|---|---|
| Video playback | Native <video controls> |
Native <video controls> |
media-chrome player |
| Chapters | Browser renders natively | Browser renders natively | Segments in scrub bar |
| Subtitles | Native <track> |
Native <track> |
Native passthrough |
| Quality switching | No | No | Settings menu |
| Annotations | No | No | Margin boxes / overlay |
| Keyboard shortcuts | Browser defaults | Browser defaults | media-chrome hotkeys |
Guard: only remove controls after confirming
customElements.get('media-controller') exists.
Migration
Clean replacement of video-figure.js. Not incremental.
Delete:
- <select> quality picker and CSS
- <button> annotation toggle and CSS
- .video-figure-toolbar and CSS
- Script tag in base.html
Keep (with minor rewiring):
- fetchVTT() + parseVTT()
- renderAnnotations() (margin boxes via Sidenotes)
- renderMobileOverlay()
- createSVGShapeDeferred() + drawConnectors()
- handleTimeFragment()
- localStorage persistence
- HTMX afterSwap reinitialization
- marginsAvailable() check
Add:
- <media-controller> wrapping at runtime
- <media-control-bar> composition
- Settings popover (gear icon, quality list, annotation toggle)
- Annotation marker dots on scrub bar
- customElements.get() degradation guard
Tests: update src/tests/test-video-figure to look for
media-chrome elements instead of .video-figure-toolbar.
Open Questions
- Vendored bundle size. media-chrome’s full ESM bundle size needs measuring. If large, we may import only the components we use.
- Settings popover on mobile. The gear popover works on desktop. On small screens it may need to be a bottom sheet or fullscreen overlay. Test and adjust.
- HLS transition. When we segment
final_restored.mp4for streaming, we swap<video>for<hls-video>and gain access to<media-rendition-menu>for proper adaptive bitrate. The custom quality picker then becomes unnecessary for that source.