Manual
Almnck.
Price: 50ⓐ

Video Player Overhaul Implementation Plan

For Claude: REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.

Goal: Replace custom popover, chapter markers, and quality UI with media-chrome’s native <media-settings-menu> and built-in chapter segments. Add <media-mute-button>. Redesign annotation markers as mini-manicules. Delete ~170 lines of custom CSS.

Design document: doc/process/plans/2026-02-16-video-player-overhaul-design.md

Architecture: Vendor the media-chrome menu ESM bundle (~81KB). Rewrite video-player.js to compose a <media-control-bar> with native media-chrome components plus a <media-settings-menu> for quality and annotations. Strip chapter menu from video-scenes.js. Clean up CSS. Annotation markers become tiny SVG manicules tracked by a ResizeObserver.

Tech Stack: media-chrome web components, Playwright (Python), pytest, TAP output

Test article: /5921/2/13/kropotkins-funeral/ — has video with chapters VTT (18 chapters), annotations VTT, subtitles, multiple quality sources.


Task 1: Vendor media-chrome menu bundle

Files: - Create: assets/js/vendor/media-chrome-menu.esm.js

Step 1: Download the menu bundle

curl -L -o assets/js/vendor/media-chrome-menu.esm.js \
  "https://cdn.jsdelivr.net/npm/media-chrome@4/menu/+esm"

Step 2: Verify it’s valid JS and check size

wc -c assets/js/vendor/media-chrome-menu.esm.js
head -5 assets/js/vendor/media-chrome-menu.esm.js

Expected: ~81KB, starts with /** JSDoc comment from jsdelivr bundler.

Step 3: Build and verify no breakage

make build

Expected: Build succeeds. The new file appears in web/static/js/vendor/. No pages reference it yet, so nothing changes.

Step 4: Commit

git add assets/js/vendor/media-chrome-menu.esm.js
git commit -m "Vendor media-chrome menu ESM bundle (81KB)

Separate entry point for <media-settings-menu>, <media-settings-menu-button>,
<media-chrome-menu-item>, and related components. Loaded only by video-player.js."

Task 2: Write failing tests for the new control bar

Files: - Create: src/tests/test_video_player.py

These tests verify the control bar composition after the overhaul. They will fail against the current code (no <media-mute-button>, no <media-settings-menu-button>, still has custom .vf-settings-btn).

Step 1: Write the test file

"""Tests for the media-chrome video player controls.

Verifies control bar composition, settings menu, and annotation markers
on the Kropotkin funeral article which has video with chapters,
annotations, subtitles, and multiple quality sources.
"""

import pytest

ARTICLE_URL = "/5921/2/13/kropotkins-funeral/"


# ---------------------------------------------------------------------------
# Fixtures
# ---------------------------------------------------------------------------

@pytest.fixture(scope="session")
def desktop_browser(playwright_instance):
    """Session-scoped desktop browser."""
    browser = playwright_instance.chromium.launch()
    yield browser
    browser.close()


@pytest.fixture
def desktop_context(desktop_browser, dev_server_url):
    """Desktop context with wide viewport."""
    context = desktop_browser.new_context(
        viewport={"width": 1280, "height": 900},
        base_url=dev_server_url,
    )
    yield context
    context.close()


@pytest.fixture
def page(desktop_context):
    """Desktop page with the Kropotkin article loaded."""
    page = desktop_context.new_page()
    page.goto(ARTICLE_URL)
    # Wait for media-chrome to enhance the video
    page.wait_for_selector("media-controller", timeout=15000)
    yield page
    page.close()


# ---------------------------------------------------------------------------
# Control bar composition
# ---------------------------------------------------------------------------

class TestControlBarComposition:
    """Verify the control bar has the expected media-chrome components."""

    def test_has_play_button(self, page):
        """Control bar should contain a play button."""
        btn = page.locator("media-control-bar media-play-button")
        assert btn.count() == 1

    def test_has_mute_button(self, page):
        """Control bar should contain a mute button."""
        btn = page.locator("media-control-bar media-mute-button")
        assert btn.count() == 1

    def test_has_time_display(self, page):
        """Control bar should contain a time display."""
        display = page.locator("media-control-bar media-time-display")
        assert display.count() == 1

    def test_has_time_range(self, page):
        """Control bar should contain a time range (scrub bar)."""
        tr = page.locator("media-control-bar media-time-range")
        assert tr.count() == 1

    def test_has_settings_menu_button(self, page):
        """Control bar should contain a settings menu button."""
        btn = page.locator("media-control-bar media-settings-menu-button")
        assert btn.count() == 1

    def test_has_fullscreen_button(self, page):
        """Control bar should contain a fullscreen button."""
        btn = page.locator("media-control-bar media-fullscreen-button")
        assert btn.count() == 1

    def test_no_custom_settings_popover(self, page):
        """Old custom settings popover should not exist."""
        old = page.locator(".vf-settings-popover")
        assert old.count() == 0

    def test_no_custom_gear_button(self, page):
        """Old custom gear button should not exist."""
        old = page.locator(".vf-settings-btn")
        assert old.count() == 0


# ---------------------------------------------------------------------------
# Settings menu
# ---------------------------------------------------------------------------

class TestSettingsMenu:
    """Verify the settings menu has quality and annotation submenus."""

    def test_settings_menu_exists(self, page):
        """A media-settings-menu element should exist."""
        menu = page.locator("media-settings-menu")
        assert menu.count() == 1

    def test_settings_menu_has_quality_item(self, page):
        """Settings menu should have a Quality submenu item."""
        # Settings menu items contain text labels
        items = page.locator("media-settings-menu media-settings-menu-item")
        texts = [items.nth(i).inner_text() for i in range(items.count())]
        assert any("Quality" in t for t in texts)

    def test_settings_menu_has_annotations_item(self, page):
        """Settings menu should have an Annotations submenu item."""
        items = page.locator("media-settings-menu media-settings-menu-item")
        texts = [items.nth(i).inner_text() for i in range(items.count())]
        assert any("Annotation" in t for t in texts)

    def test_no_chapter_menu_in_settings(self, page):
        """Chapters should NOT appear in the settings menu."""
        items = page.locator("media-settings-menu media-settings-menu-item")
        texts = [items.nth(i).inner_text() for i in range(items.count())]
        assert not any("Scene" in t or "Chapter" in t for t in texts)


# ---------------------------------------------------------------------------
# Annotation markers
# ---------------------------------------------------------------------------

class TestAnnotationMarkers:
    """Verify annotation manicule markers on the scrub bar."""

    def test_annotation_markers_exist(self, page):
        """Annotation marker container should exist on the time range."""
        page.wait_for_selector(".annotation-markers", timeout=10000)
        markers = page.locator(".annotation-markers .annotation-marker")
        # The Kropotkin VTT has many annotation cues
        assert markers.count() > 5

    def test_markers_are_svg_manicules(self, page):
        """Annotation markers should be SVG elements, not plain divs."""
        page.wait_for_selector(".annotation-markers", timeout=10000)
        marker = page.locator(".annotation-markers .annotation-marker").first
        # Marker should contain an SVG or be an SVG element
        tag = marker.evaluate("el => el.tagName.toLowerCase()")
        has_svg = marker.evaluate(
            "el => el.tagName === 'svg' || el.querySelector('svg') !== null"
        )
        assert has_svg or tag == "svg"


# ---------------------------------------------------------------------------
# Chapter segments (built-in)
# ---------------------------------------------------------------------------

class TestChapterSegments:
    """Verify media-chrome's built-in chapter segments render."""

    def test_chapter_track_present(self, page):
        """The video should have a chapters track element."""
        track = page.locator('video track[kind="chapters"]')
        assert track.count() == 1


# ---------------------------------------------------------------------------
# Margin TOC (preserved from video-scenes.js)
# ---------------------------------------------------------------------------

class TestMarginChapterTOC:
    """Verify the margin chapter TOC still works."""

    def test_chapter_toc_in_margin(self, page):
        """Chapter TOC should appear in a margin box."""
        page.wait_for_selector(".sidenotes-ready", timeout=15000)
        page.wait_for_selector(".video-chapter-toc", timeout=10000)
        toc = page.locator(".video-chapter-toc")
        assert toc.count() == 1

    def test_chapter_toc_has_entries(self, page):
        """Chapter TOC should have entries matching the VTT."""
        page.wait_for_selector(".sidenotes-ready", timeout=15000)
        page.wait_for_selector(".video-chapter-toc", timeout=10000)
        entries = page.locator(".video-chapter-toc-entry")
        # Kropotkin VTT has 18 chapters
        assert entries.count() >= 15

Step 2: Run tests to verify they fail

source bin/a-activate
pytest src/tests/test_video_player.py --tap-stream -q 2>&1 | head -30

Expected: Tests for mute button, settings-menu-button, and no-custom-popover should fail (current code has custom popover, no mute button, no <media-settings-menu-button>). Tests for play button, time display, fullscreen, chapter track, and margin TOC should pass (already present).

Step 3: Commit the failing tests

git add src/tests/test_video_player.py
git commit -m "test: add failing tests for media-chrome video player overhaul

Tests verify: mute button, settings menu with quality/annotations submenus,
no custom popover, SVG manicule annotation markers. Currently failing —
implementation follows."

Task 3: Rewrite video-player.js control bar and settings menu

Files: - Modify: assets/js/figures/video-player.js

This is the main implementation task. Replace the custom control bar construction with native media-chrome components.

Step 1: Rewrite the control bar and settings menu construction

In video-player.js, replace the control bar and settings popover code. The key changes:

  1. Import the menu bundle: import '../vendor/media-chrome-menu.esm.js';
  2. Build <media-control-bar> with: play, mute, time-display, time-range, settings-menu-button, fullscreen
  3. Build <media-settings-menu anchor="auto" hidden> with:
  4. Quality submenu (dynamic from <source data-label>)
  5. Annotations toggle submenu
  6. Remove all custom popover code (gear button, click-outside, Escape handler, popover div)
  7. Remove renderChapterMarkers() and related helpers
  8. Keep: annotation marker rendering (but replace divs with SVG manicules)
  9. Keep: all publish[...] capability calls
  10. Add ResizeObserver on time-range wrapper to realign annotation markers

The quality submenu uses <media-chrome-menu> with <media-chrome-menu-item type="radio"> items. On click, same src-swap logic as today.

The annotations submenu uses <media-chrome-menu> with <media-chrome-menu-item type="radio"> for On/Off.

Annotation markers become SVG <svg> elements with a tiny manicule path, positioned by percentage left along the track container. A ResizeObserver on the marker container’s parent re-calls alignMarkersToTrack() on any size change (including fullscreen).

Step 2: Build and verify in browser

make sync && make build

Open http://localhost:1969/5921/2/13/kropotkins-funeral/ and verify: - Control bar shows: play, mute, time, scrub, ⋯, fullscreen - Click ⋯ — settings menu opens with Quality and Annotations - Quality switching works (preserves position) - Annotations toggle works - Chapter segments visible in scrub bar - Annotation manicule markers visible on scrub bar

Step 3: Run the tests

pytest src/tests/test_video_player.py --tap-stream -q

Expected: All tests in TestControlBarComposition and TestSettingsMenu should now pass.

Step 4: Commit

git add assets/js/figures/video-player.js
git commit -m "Rewrite video-player.js with native media-chrome controls

Replace custom popover with <media-settings-menu>. Add <media-mute-button>.
Quality and annotations as submenus. Chapter markers now built-in via
media-chrome's <media-time-range> segment support. Annotation markers
redesigned as SVG manicules with ResizeObserver for fullscreen scaling."

Task 4: Strip chapter settings menu from video-scenes.js

Files: - Modify: assets/js/figures/video-scenes.js

Step 1: Remove buildChapterMenu()

Delete the buildChapterMenu() function and its call site. The margin TOC and all subscribe['video.playback'] highlighting logic stays.

Specifically remove: - The buildChapterMenu() function definition - The subscribe['video.settings'] block inside buildChapterMenu - The call to buildChapterMenu() in the chapters subscriber

Keep: - buildTocMarginBox() — the margin chapter TOC - The playback subscriber that highlights the current chapter - All cleanup logic

Step 2: Build and run tests

make sync && make build
pytest src/tests/test_video_player.py --tap-stream -q

Expected: test_no_chapter_menu_in_settings passes (no Scenes item in settings menu). Margin TOC tests still pass.

Step 3: Commit

git add assets/js/figures/video-scenes.js
git commit -m "Remove chapter settings menu from video-scenes.js

Chapters are served by media-chrome's built-in scrub bar segments and
the margin TOC. No need for a third representation in a settings popover."

Task 5: Delete old CSS, add light media-chrome theme

Files: - Modify: assets/css/almanack.css

Step 1: Delete old custom popover CSS

Remove these rule blocks entirely: - .vf-settings-wrap (line ~1443) - .vf-settings-btn - .vf-settings-popover - .vf-settings-heading - .vf-quality-list, .vf-quality-item, .vf-quality-active, .vf-quality-active::before - .vf-settings-row - .vf-annotation-toggle, .vf-annotation-toggle:hover, .vf-annotation-toggle[aria-checked="true"]::before - .vf-chapter-list, .vf-chapter-item, .vf-chapter-item:hover, .vf-chapter-active, .vf-chapter-time, .vf-chapter-name - .vf-chapter-label - .chapter-markers, .chapter-marker

Keep: - .vf-time-range-wrap — still used for annotation marker overlay - .annotation-markers, .annotation-marker — updated for SVG manicules - .video-chapter-toc* — margin TOC styles - All media-controller, media-control-bar, media-time-display rules - All .video-figure-*, .video-annotation* rules

Step 2: Update media-chrome theme CSS

Replace the existing media-controller block with a refined version:

media-controller {
    --media-primary-color: #fff;
    --media-secondary-color: rgb(20 20 30 / .7);
    --media-font: var(--font-body);
    --media-font-size: 0.8rem;
    --media-icon-color: #fff;
    --media-button-icon-width: 20px;
    --media-button-icon-height: 20px;
    --media-range-track-border-radius: 0;
    --media-range-thumb-border-radius: 0;
    --media-range-segments-gap: 2px;
    display: block;
    position: relative;
    width: 100%;
}

Add settings menu theming:

media-settings-menu {
    --media-menu-background: rgb(20 20 30 / .9);
    --media-font: var(--font-body);
    --media-font-size: 0.85rem;
    border-radius: 2px;
}

Step 3: Update annotation marker CSS for SVG manicules

.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: 8px;
    height: 8px;
    transform: translate(-50%, -50%);
    pointer-events: none;
    color: rgba(255, 200, 50, 0.8);
}

.annotation-marker svg {
    width: 100%;
    height: 100%;
    fill: currentColor;
}

Step 4: Build and verify visually

make sync && make build

Open the article. Confirm controls match the Almanack palette with sharp corners, body font in menus, mono for timecodes.

Step 5: Run all tests

pytest src/tests/test_video_player.py --tap-stream -q
make test

Expected: All video player tests pass. No regressions in unit suite.

Step 6: Commit

git add assets/css/almanack.css
git commit -m "Delete custom popover CSS, add light media-chrome theme

Remove ~170 lines of .vf-settings-*, .vf-quality-*, .vf-chapter-*,
.chapter-marker CSS. Add media-settings-menu theming. Update annotation
marker styles for SVG manicules."

Task 6: Run full test suite and visual verification

Files: None (verification only)

Step 1: Run the default test suite

make test

Expected: All tests pass (API container test may fail for unrelated Docker reasons — ignore that one).

Step 2: Run mobile tests

make test-mobile

Expected: All 24 mobile tests pass. The video player isn’t directly tested in mobile suite but margin layout tests exercise the same page.

Step 3: Run video player tests

pytest src/tests/test_video_player.py -v --tap-stream

Expected: All tests pass.

Step 4: Visual inspection checklist

Open http://localhost:1969/5921/2/13/kropotkins-funeral/ at: - Desktop (1280px+): control bar, settings menu, margin TOC, margin annotations, chapter segments in scrub bar, manicule markers - Narrow desktop (800px): controls adapt, no margin layout - iOS Simulator: swipe mode, controls, fullscreen

Walk through: - [ ] Play/pause via button and spacebar - [ ] Mute/unmute via button and ‘m’ key - [ ] Scrub bar shows chapter segments with gaps - [ ] Hover over scrub bar shows chapter name preview - [ ] Settings ⋯ opens menu with Quality and Annotations - [ ] Quality switch preserves playback position - [ ] Annotations toggle persists across reload - [ ] Manicule markers visible on scrub bar - [ ] Fullscreen: markers and segments rescale correctly - [ ] #t=1m30s fragment link scrolls and seeks - [ ] Margin annotations appear during annotated cues - [ ] Chapter TOC in margin highlights current chapter - [ ] Without JS: native <video controls> fallback works

Step 5: Commit if any fixups were needed

git add -A
git commit -m "Video player overhaul: final fixups from visual review"

Task 7: Deploy

Step 1: Push and deploy

git push
make prod-deploy

Step 2: Verify on production

Open the Kropotkin article on the live site and run through the visual checklist from Task 6 Step 4.


Reference

Design document: doc/process/plans/2026-02-16-video-player-overhaul-design.md

Key files: - assets/js/vendor/media-chrome-menu.esm.js — new vendored bundle - assets/js/figures/video-player.js — major rewrite - assets/js/figures/video-scenes.js — chapter menu removal - assets/css/almanack.css — CSS cleanup + theme - src/tests/test_video_player.py — new test file - editorial/articles/kropotkins-funeral/ — test article

Commands: - make serve — dev server on :1969 - make sync && make build — rebuild static site - pytest src/tests/test_video_player.py --tap-stream -q — video tests - make test — default test suites - make test-mobile — mobile tests - make test-all — everything