Skip to content
Merged
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
- Card DOM (`src/card.js`): adds, updates and removes an artwork image at the start of a media card's info container. The image stays hidden until it loads, and only `https:` or image `data:` sources are set.
- Runtime (`src/runtime.js`, `src/install.js`): watches Zen's media cards and each playing tab's metadata, and keeps every card's artwork in step with the track it shows, picking an image sized for the screen's pixel density. Disabling the mod or re-running it removes all artwork and listeners.
- Sine manifest (`theme.json`) and a minimal `chrome.css` that sizes the thumbnail, so the mod can be installed from this repository.
- Artwork styles, chosen under the mod's settings in Sine (`preferences.json`, pref `zen-media-viz.artwork-style`): a small thumbnail beside the title (default), a large centered cover above the title, or the artwork behind the whole card, which grows to a square on hover so the whole cover shows. Changing the style applies at once.
- The media card's buttons show a pointer cursor.
- The small thumbnail hides in very narrow sidebars, and artwork is fetched again at a higher resolution when the window moves to a denser screen.
- Claude Code project skills: `unslop` (code style, summarized in the contributing guide), `mine` (attribution policy) and `ship-it` (commit, review and fix loop).

[Unreleased]: https://github.com/rodzy/Zen-Media-Viz/commits/main
4 changes: 2 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ A Zen Browser mod, loaded by the Sine mod manager, that shows album artwork in Z
## Architecture

- `src/*.js` are ES modules. `build.mjs` (esbuild) bundles `src/index.js` into one IIFE, `zen-media-viz.uc.js`, at the repo root. **The bundle is generated but committed**: Sine installs straight from the GitHub repo and only executes `.uc.js` (not `.uc.mjs`). After changing `src/`, run `npm run build` and commit the bundle too. Never hand-edit it.
- Sine integration: `theme.json` and `chrome.css` at the repo root (from Sine's source, `CosmoCreeper/Sine` `src/core/manager.sys.mjs` and `utils.sys.mjs`). `scripts` maps a path relative to the repo root to `{ include: [...] }`; `*` in a pattern is a wildcard and the pattern must match the whole window URL. Only `.uc.js` scripts are loaded as classic subscripts, once per matching window after its `load` event; `style.chrome` is applied as a user stylesheet. Mods outside Sine's store run JS only when the user allows unsafe JS in Sine's settings. Sine gives the window `addUnloadListener(callback)`: it calls the callback when the mod is disabled and before re-running the script into an open window; with `supportsUnload: true` Sine doesn't ask for a restart on disable. `src/install.js` registers `window.ZenMediaViz.destroy()` there and also calls any previous instance's `destroy()` before starting.
- Sine integration: `theme.json` and `chrome.css` at the repo root (from Sine's source, `CosmoCreeper/Sine` `src/core/manager.sys.mjs` and `utils.sys.mjs`). `scripts` maps a path relative to the repo root to `{ include: [...] }`; `*` in a pattern is a wildcard and the pattern must match the whole window URL. Only `.uc.js` scripts are loaded as classic subscripts, once per matching window after its `load` event; `style.chrome` is applied as a user stylesheet. Mods outside Sine's store run JS only when the user allows unsafe JS in Sine's settings. Sine gives the window `addUnloadListener(callback)`: it calls the callback when the mod is disabled and before re-running the script into an open window; with `supportsUnload: true` Sine doesn't ask for a restart on disable. `src/install.js` registers `window.ZenMediaViz.destroy()` there and also calls any previous instance's `destroy()` before starting. Mod settings live in `preferences.json` (Sine renders `dropdown`, `checkbox`, `string` and `separator` entries, stored as `about:config` prefs). `src/settings.js` reads them through the injected `Services.prefs` and observes changes. `chrome.css` is loaded as a **user** sheet, so overriding one of Zen's own rules needs `!important`; Zen's card styles are in `zen-browser/desktop` `src/zen/media/zen-media-controls.css`.
- **Injected globals:** logic modules never read `gBrowser`, `gZenMediaController`, `window` or `document` directly; they take them as parameters. Only `src/index.js` touches the real window. Tests pass fakes. DOM tests opt in with `// @vitest-environment happy-dom` (default environment is `node`).
- Zen/Firefox APIs relied on (from `zen-browser/desktop` `src/zen/media/` and Firefox's `MediaController.webidl`), verified on Zen 1.24.3b (Gecko 160.0.1) by the spike (`docs/spike.md`, `npm run spike`). Its report is the fixture `test/fixtures/zen-1.24.3b.json`, and `test/zen-fixture.test.js` pins the facts below:
- Media cards: `#zen-media-controls-toolbar` > `.zen-media-card` (cloned from `#zen-media-card-template`, which sits inside the toolbar) > `.zen-media-main-vbox` > `vbox` > `.zen-media-info-container` > `.zen-media-info-vbox` > `.zen-media-title` / `.zen-media-artist`. Use descendant selectors, not child chains. Zen sets only title and artist; it ignores artwork. The recorded card had a `playing` class; per Zen's source, cards are created `hidden` and shown when their tab isn't selected.
- Cards carry no attribute naming their controller or browser (only `class`, `style`, `hidden`). Match cards to controllers by title and artist. From Zen's source, not verified by the spike: the card-to-controller map is a private field, and `gZenMediaController.frontCard` returns a card object with `element`, `browser` and `controller`, but only for the front visible card.
- `tab.linkedBrowser.browsingContext.mediaController.getMetadata()` returns `{title, artist, album, artwork: [{src, sizes, type}]}` with absolute `src`. It **throws** `NS_ERROR_NOT_AVAILABLE` when the controller is inactive. The controller fires `metadatachange`.
- `browser.xhtml`'s CSP is `script-src chrome: moz-src: resource:; frame-src chrome:; object-src 'none';`, with no `img-src`, so it shouldn't restrict images (confirm a real artwork image renders once the mod runs in Zen, Milestone 5). Limiting artwork to `https:`/`data:` sources is the mod's own choice: no plain `http:`, and no `blob:` or privileged schemes from the page.
- `browser.xhtml`'s CSP is `script-src chrome: moz-src: resource:; frame-src chrome:; object-src 'none';`, with no `img-src`, so it doesn't restrict images (confirmed: real artwork renders in the card on Zen 1.24.3b, macOS). Limiting artwork to `https:`/`data:` sources is the mod's own choice: no plain `http:`, and no `blob:` or privileged schemes from the page.
- Anything that can't be tested under Node goes in `docs/manual-testing.md`.

## Workflow
Expand Down
123 changes: 116 additions & 7 deletions chrome.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,121 @@
#zen-media-controls-toolbar {
--zen-media-viz-thumbnail-size: 48px;
--zen-media-viz-cover-size: min(100cqw - 32px, 220px);
--zen-media-viz-text-room: 76px;
--zen-media-viz-background-opacity: 0.35;
--zen-media-viz-easing: var(--zen-media-stack-easing, ease-out);
}

.zen-media-viz-artwork {
flex: none;
width: 36px;
height: 36px;
margin-inline-end: 8px;
border-radius: 4px;
pointer-events: none;
object-fit: cover;

&[hidden] {
display: none !important;
}
}

.zen-media-info-container:has(> .zen-media-viz-artwork:not([hidden])) > .zen-media-info-vbox {
overflow-x: clip !important;
width: auto !important;
min-width: 0 !important;

&::before {
display: none !important;
}
}

#zen-media-controls-toolbar[zen-media-viz-style="small"] {
.zen-media-info-container > .zen-media-info-vbox {
flex: 1 1 0 !important;
align-self: center;
}

.zen-media-viz-artwork {
flex: none;
align-self: center;
width: var(--zen-media-viz-thumbnail-size);
height: var(--zen-media-viz-thumbnail-size);
margin-inline-end: 10px;
border-radius: 6px;
}
}

@container (min-width: 181px) {
#zen-media-controls-toolbar[zen-media-viz-style="small"]:hover
.zen-media-info-container.show-on-hover:has(> .zen-media-viz-artwork:not([hidden])) {
max-height: calc(var(--zen-media-viz-thumbnail-size) + 2 * var(--zen-space-5, 6px)) !important;
}
}

@container (max-width: 180px) {
#zen-media-controls-toolbar[zen-media-viz-style="small"] .zen-media-viz-artwork {
display: none;
}
}

#zen-media-controls-toolbar[zen-media-viz-style="large"] {
.zen-media-info-container {
flex-wrap: wrap;
}

&:hover .zen-media-info-container.show-on-hover:has(> .zen-media-viz-artwork:not([hidden])) {
max-height: calc(var(--zen-media-viz-cover-size) + var(--zen-media-viz-text-room)) !important;
}

.zen-media-info-container > .zen-media-info-vbox {
flex: 1 1 50% !important;
}

.zen-media-viz-artwork {
flex: none;
width: var(--zen-media-viz-cover-size);
height: var(--zen-media-viz-cover-size);
margin-inline: calc((100% - var(--zen-media-viz-cover-size)) / 2);
margin-block-end: 8px;
border-radius: 8px;
box-shadow: 0 2px 8px rgb(0 0 0 / 0.25);
}
}

#zen-media-controls-toolbar[zen-media-viz-style="background"] {
.zen-media-card:has(> .zen-media-viz-artwork:not([hidden])) {
min-height: 0;

&:not([zen-removing], [zen-hiding], [zen-reindexing]) {
transition:
transform 0.35s var(--zen-media-viz-easing),
opacity 0.3s var(--zen-media-viz-easing),
filter 0.3s var(--zen-media-viz-easing),
padding 0.3s ease-out,
min-height 0.35s var(--zen-media-viz-easing) !important;
}
}

&:hover .zen-media-card:has(> .zen-media-viz-artwork:not([hidden])) {
min-height: 100cqw;

.zen-media-main-vbox > vbox:first-child {
flex: 1;
}

.zen-media-progress-hbox {
flex-grow: 0 !important;
margin-top: auto;
}
}

.zen-media-card > .zen-media-viz-artwork {
position: absolute;
inset: 0;
z-index: -1;
width: 100%;
height: 100%;
border-radius: inherit;
opacity: var(--zen-media-viz-background-opacity);
}
}

.zen-media-viz-artwork[hidden] {
display: none;
#zen-media-controls-toolbar .zen-media-card toolbarbutton:not([disabled]) {
cursor: pointer !important;
}
12 changes: 12 additions & 0 deletions docs/manual-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,15 @@ Allow JavaScript from unofficial sources in Sine's settings, install the mod fro
- [ ] A track without artwork shows no thumbnail and no broken image.
- [ ] Disabling the mod in Sine removes the artwork without a restart; enabling it again brings it back, with only one thumbnail per card.
- [ ] Opening a new window shows artwork there too.

## Artwork styles

Change **Artwork style** in the mod's settings in Sine while a track is playing. Each change should apply without reloading.

- [ ] **Small thumbnail beside the title:** on hover, a 48px square sits left of the title. The start of the title isn't covered or faded, and the artist and close button still fit.
- [ ] **Large cover above the title:** on hover, the card grows smoothly to show a centered square cover with the title, artist and close button below it. Closing is just as smooth.
- [ ] **Artwork behind the whole card:** the artwork sits dimmed behind the resting card. On hover the card grows to a square and the whole cover shows, with the title at the top and the progress bar and controls together at the bottom, all readable.
- [ ] Switching back to the small thumbnail leaves one thumbnail per card and nothing behind the card.
- [ ] Narrowing the sidebar until the card is very thin hides the small thumbnail instead of squeezing the title.
- [ ] Try each style with a light and a dark Zen theme.
- [ ] The pointer turns into a hand over every button on the card (play/pause, previous, next, mute, close, picture-in-picture and the tab button on the left).
20 changes: 10 additions & 10 deletions docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

The first release is built in milestones. Each milestone is one pull request, written test-first.

| # | Milestone | What it delivers | Status |
| --- | --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | ------ |
| 0 | Open-source & tooling shell | Test, lint, format and bundle tooling, CI, contributor docs and templates | Done |
| 1 | Spike & fixtures | A read-only console snippet that checks Zen's media card DOM and real metadata on the maintainer's Zen version, saved as test fixtures | Done |
| 2 | Artwork selection | `src/artwork.js`: parse `sizes`, filter to usable `https:`/`data:` sources, pick the best image | Done |
| 3 | Controller matching | `src/controllers.js`: safely read metadata from each tab's media controller and match it to a media card | Done |
| 4 | Card DOM | `src/card.js`: add, update and remove the thumbnail element in a media card | Done |
| 5 | Runtime wiring & Sine | Watch cards and metadata changes, clean teardown, `theme.json`, first run inside Zen | Done |
| 6 | Styling & polish | `chrome.css` for the thumbnail, narrow-sidebar and collapsed states, manual checklist | Next |
| 7 | Release v0.1.0 | Install guide, screenshot, version bump and tag | |
| # | Milestone | What it delivers | Status |
| --- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ------ |
| 0 | Open-source & tooling shell | Test, lint, format and bundle tooling, CI, contributor docs and templates | Done |
| 1 | Spike & fixtures | A read-only console snippet that checks Zen's media card DOM and real metadata on the maintainer's Zen version, saved as test fixtures | Done |
| 2 | Artwork selection | `src/artwork.js`: parse `sizes`, filter to usable `https:`/`data:` sources, pick the best image | Done |
| 3 | Controller matching | `src/controllers.js`: safely read metadata from each tab's media controller and match it to a media card | Done |
| 4 | Card DOM | `src/card.js`: add, update and remove the thumbnail element in a media card | Done |
| 5 | Runtime wiring & Sine | Watch cards and metadata changes, clean teardown, `theme.json`, first run inside Zen | Done |
| 6 | Styling & settings | Artwork styles chosen in Sine's settings (small thumbnail, large cover, background), narrow-sidebar handling, pixel-density updates, manual checklist | Done |
| 7 | Release v0.1.0 | Install guide, screenshot, version bump and tag | Next |

Ideas for after v0.1.0 are tracked as [issues](https://github.com/rodzy/Zen-Media-Viz/issues).
14 changes: 14 additions & 0 deletions preferences.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"type": "dropdown",
"property": "zen-media-viz.artwork-style",
"label": "Artwork style",
"defaultValue": "small",
"placeholder": false,
"options": [
{ "value": "small", "label": "Small thumbnail beside the title" },
{ "value": "large", "label": "Large cover above the title" },
{ "value": "background", "label": "Artwork behind the whole card" }
]
}
]
17 changes: 10 additions & 7 deletions src/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,33 @@ const INFO_CONTAINER_SELECTOR = ".zen-media-info-container";

const findArtwork = (card) => card.querySelector(`.${ARTWORK_CLASS}`);

function createArtwork(container) {
const image = container.ownerDocument.createElementNS(HTML_NS, "img");
function createArtwork(document) {
const image = document.createElementNS(HTML_NS, "img");
image.className = ARTWORK_CLASS;
image.alt = "";
image.setAttribute("referrerpolicy", "no-referrer");
image.addEventListener("load", () => {
image.hidden = false;
});
container.prepend(image);
return image;
}

const artworkHost = (card, asBackground) =>
asBackground ? card : card.querySelector(INFO_CONTAINER_SELECTOR);

export function removeArtwork(card) {
findArtwork(card)?.remove();
}

export function showArtwork(card, src) {
export function showArtwork(card, src, { asBackground = false } = {}) {
if (!isUsableSrc(src)) {
removeArtwork(card);
return;
}
const container = card.querySelector(INFO_CONTAINER_SELECTOR);
if (!container) return;
const image = findArtwork(card) ?? createArtwork(container);
const host = artworkHost(card, asBackground);
if (!host) return;
const image = findArtwork(card) ?? createArtwork(card.ownerDocument);
if (host.firstElementChild !== image) host.prepend(image);
if (image.getAttribute("src") === src) return;
image.hidden = true;
image.setAttribute("src", src);
Expand Down
6 changes: 5 additions & 1 deletion src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ function destroyPrevious(window) {
export function install(window) {
destroyPrevious(window);
try {
const mediaViz = startMediaViz({ window, gBrowser: window.gBrowser });
const mediaViz = startMediaViz({
window,
gBrowser: window.gBrowser,
prefs: window.Services.prefs,
});
const handle = {
destroy() {
mediaViz.destroy();
Expand Down
Loading