Media Chrome Video Figure Implementation Plan
For Claude: REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
Goal: Replace browser-native video controls with media-chrome web components. Keep the annotation, overlay, and margin-box systems.
Design document:
doc/process/plans/2026-02-15-media-chrome-video-figure-design.md
Architecture: Vendor media-chrome ESM bundle. Rewrite
video-figure.js as an ES module that wraps <video> in
<media-controller>, composes a <media-control-bar>, and wires
up a custom settings popover. Annotation rendering, SVG overlays,
VTT parsing, and margin-box injection stay as-is.
Task 1: Vendor media-chrome and set up module loading
Files:
- Create: assets/js/vendor/media-chrome.esm.js
- Modify: src/almnck/templates/base.html (remove old video-figure.js script tag)
Step 1: Download media-chrome ESM bundle
mkdir -p assets/js/vendor
curl -L -o assets/js/vendor/media-chrome.esm.js \
"https://cdn.jsdelivr.net/npm/media-chrome@4/+esm"
Inspect the downloaded file to confirm it is valid JS and note its
size. If it fetches further submodules via CDN imports, we may need
to bundle differently (use esbuild to produce a single-file
bundle from node_modules). Test by loading in a browser with
network tab open.
Step 2: Remove old script tag from base.html
In src/almnck/templates/base.html, remove:
<script src="{% cdnstatic 'js/video-figure.js' %}" defer></script>
The script will load from within the figure markup instead.
Step 3: Build and verify
make build
Confirm the vendor file appears in web/static/js/vendor/. Confirm
pages without video figures still load cleanly (no missing script
errors).
Step 4: Commit
git add assets/js/vendor/media-chrome.esm.js src/almnck/templates/base.html
git commit -m "Vendor media-chrome ESM bundle, remove global video-figure.js"
Task 2: Scaffold new video-figure.js as ES module
Files:
- Rewrite: assets/js/video-figure.js
Step 1: Create minimal module scaffold
Replace assets/js/video-figure.js with a new ES module that:
- Imports media-chrome
- Waits for custom elements to register
- Finds
[data-video-figure]elements - Wraps each
<video>in<media-controller>withslot="media" - Removes the
controlsattribute - Adds a minimal
<media-control-bar>with play button and time range - Falls back gracefully if
customElements.get('media-controller')is undefined
import './vendor/media-chrome.esm.js';
(function () {
'use strict';
function enhance(container) {
var video = container.querySelector('video');
if (!video) return;
// Guard: only enhance if media-chrome registered
if (!customElements.get('media-controller')) return;
// Remove native controls
video.removeAttribute('controls');
// Create media-controller wrapper
var mc = document.createElement('media-controller');
// Move video into controller with slot="media"
video.setAttribute('slot', 'media');
video.parentNode.insertBefore(mc, video);
mc.appendChild(video);
// Minimal control bar
var bar = document.createElement('media-control-bar');
bar.innerHTML = [
'<media-play-button></media-play-button>',
'<media-time-display showduration></media-time-display>',
'<media-time-range></media-time-range>',
'<media-fullscreen-button></media-fullscreen-button>',
].join('');
mc.appendChild(bar);
}
function init() {
document.querySelectorAll('[data-video-figure]').forEach(enhance);
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();
Step 2: Add inline script to Kropotkin article
In editorial/articles/kropotkins-funeral/article.md, add inside
(or just after) the <figure>:
<script type="module" src="/static/js/video-figure.js"></script>
Step 3: Build and verify in browser
make sync && make build && make serve
Open the Kropotkin article. Confirm:
- media-chrome controls appear (play button, scrub bar, fullscreen)
- Chapter segments visible in scrub bar
- Keyboard shortcuts work (space, arrows)
- If JS is disabled, native <video controls> still works
Step 4: Commit
git add assets/js/video-figure.js editorial/articles/kropotkins-funeral/article.md
git commit -m "Scaffold video-figure.js as ES module with media-chrome"
Task 3: Port quality picker into settings popover
Files:
- Modify: assets/js/video-figure.js
- Modify: assets/css/almanack.css (or web/static/css/almanack.css)
Step 1: Build the settings popover
In the enhance function, after creating the control bar:
- Create a gear button and popover div.
- Read
<source data-label>elements into a quality list. - Render quality options as radio-style items in the popover.
- On selection: capture
currentTimeandpaused, setvideo.src, callvideo.load(), restore onloadedmetadata. - Insert the gear button into the control bar, before fullscreen.
- Wire popover open/close (click gear, click outside, Escape).
Port the quality-switching logic verbatim from the current
video-figure.js picker change handler.
Step 2: Add CSS for settings popover
Style the popover: Almanack palette, black border, no rounded corners, body font. Position absolutely above the gear button.
Step 3: Remove old toolbar CSS
Delete the .video-figure-toolbar and .video-quality-picker CSS
rules from almanack.css.
Step 4: Build and verify
make sync && make build
Open the article. Confirm: - Gear icon visible in control bar - Popover opens with quality options - Switching quality preserves playback position - Old toolbar no longer renders
Step 5: Commit
git add assets/js/video-figure.js web/static/css/almanack.css
git commit -m "Port quality picker into media-chrome settings popover"
Task 4: Port annotation toggle into settings popover
Files:
- Modify: assets/js/video-figure.js
- Modify: web/static/css/almanack.css
Step 1: Add annotation toggle to popover
Add an on/off toggle row below the quality picker in the settings
popover. Wire it to the existing _annotationsEnabled flag and
localStorage persistence logic.
When toggled off: call clearAnnotationBoxes(), clear SVG overlay,
remove mobile overlay. When toggled on: re-render annotations for
current time.
Port the toggle logic from the current video-figure.js toggle
button click handler.
Step 2: Remove old toggle CSS
Delete .video-annotation-toggle CSS rules.
Step 3: Build and verify
Confirm toggle works, localStorage persists state across reloads.
Step 4: Commit
git add assets/js/video-figure.js web/static/css/almanack.css
git commit -m "Port annotation toggle into settings popover"
Task 5: Port metadata track dispatch and annotation rendering
Files:
- Modify: assets/js/video-figure.js
Step 1: Port VTT parser and metadata dispatch
Copy these functions from the current video-figure.js into the
new module:
fetchVTT(url, callback)parseVTT(text)setupMetadataTracks(video)wireTimeupdate(video)renderAnnotations(cues, currentTime, vid)clearAnnotationBoxes(vid)marginsAvailable(vid)escapeHtml(text)renderMobileOverlay(active, wrapper)
Rewire: the SVG overlay and video wrapper are now inside the
<media-controller>. Adjust DOM traversal accordingly:
- video.closest('.video-figure-wrapper') may need to change to
video.closest('media-controller') or similar
- The SVG overlay still wraps the video within the controller
Step 2: Wire setupMetadataTracks in enhance()
Call setupMetadataTracks(video) after building the control bar,
same as today.
Step 3: Build and verify
Play the Kropotkin video. Confirm: - Annotations appear in margins on desktop - Annotations appear as overlay on narrow viewport - Annotations toggle off/on correctly - Annotations survive quality switch
Step 4: Commit
git add assets/js/video-figure.js
git commit -m "Port metadata track dispatch and annotation rendering"
Task 6: Port SVG overlay shapes and connector lines
Files:
- Modify: assets/js/video-figure.js
Step 1: Port SVG overlay creation
Copy from the current video-figure.js:
- SVG overlay element creation (
document.createElementNS) createSVGShapeDeferred(shapeData, labelText, boxId)drawConnectors(svgOverlay, vid)
The SVG overlay sits between the <video> and the control bar,
inside <media-controller>. Create a wrapper div if needed, or
position the SVG absolutely over the video slot.
Step 2: Port shape rendering into renderAnnotations
Ensure shapes render during cue activation, connectors draw after double-rAF, and shapes clear when cues deactivate.
Step 3: Build and verify
Seek to a cue with shape data. Confirm: - SVG shape appears over the video - Connector lines reach the margin annotations - Shapes clear on cue deactivation - Shapes respect annotation toggle
Step 4: Commit
git add assets/js/video-figure.js
git commit -m "Port SVG overlay shapes and connector lines"
Task 7: Annotation marker dots on the scrub bar
Files:
- Modify: assets/js/video-figure.js
- Modify: web/static/css/almanack.css
Step 1: Create marker container
After VTT cues are parsed and video duration is known
(loadedmetadata), create a thin container div overlaid on the
<media-time-range> element. Position it absolutely, matching the
time range’s dimensions.
Step 2: Calculate and render marker dots
For each metadata cue, calculate (startTime / duration) * 100%
and create a 4px square element at that horizontal position. Use
the warm orange accent color (rgba(255, 200, 50, 0.7)). Set
pointer-events: none on the container so clicks pass through to
the scrub bar.
Step 3: Recalculate on source switch
After quality switch completes (on loadedmetadata), recalculate
markers with the new duration (which should be the same, but guard
against edge cases).
Step 4: Add CSS
.annotation-markers {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
pointer-events: none;
z-index: 1;
}
.annotation-marker {
position: absolute;
top: 50%;
width: 4px;
height: 4px;
background: rgba(255, 200, 50, 0.7);
transform: translate(-50%, -50%);
}
Positioning may need adjustment based on <media-time-range>’s
internal structure. Inspect the shadow DOM to find the correct
insertion point or overlay alignment.
Step 5: Build and verify
Confirm dots appear at correct positions on the scrub bar. Confirm they do not interfere with scrubbing.
Step 6: Commit
git add assets/js/video-figure.js web/static/css/almanack.css
git commit -m "Annotation marker dots on the scrub bar"
Task 8: Port time fragment handling and HTMX support
Files:
- Modify: assets/js/video-figure.js
Step 1: Port time fragment handling
Copy parseTimeFragment() and handleTimeFragment() from the
current video-figure.js. Wire hashchange listener.
Step 2: Port HTMX reinitialization
Add htmx:afterSwap listener that calls enhance() on any new
[data-video-figure] elements in the swapped content.
Step 3: Verify
- Navigate to article with
#t=1m30s— video scrolls into view and seeks to 1:30. - Trigger an htmx swap (if testable) — new video figures enhance correctly.
Step 4: Commit
git add assets/js/video-figure.js
git commit -m "Port time fragment handling and HTMX reinitialization"
Task 9: Almanack CSS theme for media-chrome
Files:
- Modify: web/static/css/almanack.css
Step 1: Add media-chrome theme CSS
Add a dedicated section in almanack.css for media-chrome styling:
media-controller— colors, fonts, sizing via CSS custom propsmedia-control-bar— border-top, padding- Individual components — button hover states, time display font
- Settings popover — position, border, font
- Annotation markers — position, color, size
Step 2: Remove old video-figure CSS
Delete these CSS rules from almanack.css:
- .video-figure-toolbar and children
- .video-quality-picker
- .video-annotation-toggle
Keep these (still used):
- .video-figure-wrapper
- .video-figure-overlay and .video-figure-shape
- .video-figure-connector
- .video-annotation (margin box content)
- .video-annotation-overlay (mobile)
Step 3: Build and verify across viewports
Test at desktop, tablet, and mobile widths. Confirm: - Controls match Almanack palette - Sharp corners, body font, black-on-cream - Settings popover positions correctly - Annotations render in margins (wide) or overlay (narrow)
Step 4: Commit
git add web/static/css/almanack.css
git commit -m "Almanack CSS theme for media-chrome controls"
Task 10: Update tests
Files:
- Modify: src/tests/test-video-figure
Step 1: Update element selectors
Replace references to old elements:
- .video-figure-toolbar -> media-control-bar
- .video-quality-picker -> #quality-picker (or settings popover selector)
- .video-annotation-toggle -> #annotation-toggle (in popover)
Step 2: Add new tests
- media-chrome controller wraps the video
- Chapter segments visible in
<media-time-range> - Keyboard shortcuts work (space toggles play)
- Settings popover opens and closes
- Annotation markers appear on scrub bar
Step 3: Run tests
make test
Confirm all tests pass.
Step 4: Commit
git add src/tests/test-video-figure
git commit -m "Update video figure tests for media-chrome"
Task 11: Clean up and final verification
Files:
- Remove old video-figure.js from base.html (if not already done)
- Verify no orphaned CSS or JS remains
Step 1: Full test run
make test-all
Step 2: Visual inspection
Open the Kropotkin article at desktop, tablet, and mobile widths.
Walk through:
- Play, pause, seek via controls and keyboard
- Chapter markers visible in scrub bar
- Annotation marker dots visible
- Settings gear: quality switch preserves position
- Settings gear: annotation toggle works
- Margin annotations appear on desktop
- Mobile overlay appears on narrow viewport
- SVG shapes appear during relevant cues
- #t=30s fragment link scrolls and seeks
- Without JS: native <video controls> fallback
Step 3: Commit and tag
git add -A
git commit -m "Media-chrome video figure: final cleanup and verification"
Reference
Design document:
doc/process/plans/2026-02-15-media-chrome-video-figure-design.md
Key files:
- assets/js/vendor/media-chrome.esm.js — vendored library
- assets/js/video-figure.js — rewritten enhancement module
- web/static/css/almanack.css — theme and annotation styles
- editorial/articles/kropotkins-funeral/article.md — test article
- editorial/articles/kropotkins-funeral/assets/funeral-annotations.vtt
- editorial/articles/kropotkins-funeral/assets/funeral-chapters.vtt
- src/tests/test-video-figure — browser tests (TAP)
Commands:
- make serve — dev server on :1969
- make sync && make build — rebuild static site
- make test — run default test suites
- make test-all — run all test suites