Skip to content

added stretch mode - #1

Open
Deepakktripathy wants to merge 7 commits into
mainfrom
feature/stretch
Open

Deepakktripathy wants to merge 7 commits into
mainfrom
feature/stretch

Conversation

@Deepakktripathy

@Deepakktripathy Deepakktripathy commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This PR adds stretch mode and splits the controls: the toolbar popup chooses the mode (Crop or Stretch) and the player button turns that mode on or off.

The player button used to be a single crop toggle. It is now a simple on/off switch for whichever mode is picked in the popup, so the two trade-offs — trimming edges vs. distorting the picture — are an explicit choice instead of a hidden third click.

  • Choose Crop or Stretch from two large cards in the popup.
  • Clicking a card selects that mode and turns it on.
  • The player button only toggles the selected mode.
  • The popup reports Crop is off, Crop is on, Stretch is off, or Stretch is on.
  • Each card has a looping, reduced-motion-aware preview of a square video in a 21:9 player.
  • Existing cropEnabled values migrate automatically. cropMode was never released, so there is no cropMode migration.

Behavior

Action Selected mode Fill Player icon Popup
Fresh install Crop Off brackets only Crop selected, “Crop is off”
Player button Crop On square mark Crop selected, “Crop is on”
Player button Crop Off brackets only Crop selected, “Crop is off”
Click Stretch Stretch On wide-bar mark Stretch selected, “Stretch is on”
Player button Stretch Off brackets only Stretch selected, “Stretch is off”
Player button Stretch On wide-bar mark Stretch selected, “Stretch is on”
Click Crop Crop On square mark Crop selected, “Crop is on”

Clicking the already-selected card turns it on, so the card does not double as an off switch. The player button is the only off switch.

Screenshots

Popup

popup-states

The previews loop, so each capture is taken at the held “applied” point of the animation. The player button icon remains the same.

Implementation

Two values instead of one

State is now:

  • fillMode: "crop" | "stretch"
  • fillEnabled: boolean

The player can be off while still remembering which mode its button should turn back on.

Player button

src/player/button.ts now calls toggleEnabled() instead of advancing a cycle. It writes:

  • data-flrm-mode — the selected mode, always
  • aria-pressed — whether fill is on
  • title / aria-label — Fullorama: crop on, Fullorama: stretch off, etc.

The icon still contains both overlay shapes. content.css reveals the square or wide bar only when aria-pressed="true" and the mode matches, so the inner mark disappears when off.

Popup

src/popup/popup.ts is now interactive:

  • loadState() once on open
  • render() sets the status text, the green status dot, and the selected card
  • clicking a card calls selectMode(mode), which sets the mode and enables fill

Card states:

  • Selected — white outline and a filled radio; the preview keeps its normal border colour
  • Unselected — neutral border and an empty radio

The green dot and the Crop is on/off status line carry on/off. The footer is reduced to Share feedback and the version.

Animated previews

src/popup/preview.jpg is a 768×768 still of a hot-air balloon over a mountain valley at sunset. It appears in the Original frame above the cards and inside both card previews. Every frame is a 21:9 box, so the square still starts with side bars.

  • Crop — scales both axes uniformly by 21 ÷ 9 = 2.3333, filling the width and clipping top/bottom. No distortion. On the selected card, the clipped parts reappear as a faded overflow above and below the frame.
  • Stretch — scales only X by 2.3333, filling the width and visibly widening the picture. Nothing is clipped.

Both cards run the same 5-second loop: hold normal, transition, hold applied, transition back. prefers-reduced-motion: reduce removes the animation and holds each card in its applied state, so the preview still explains the mode. The previews are aria-hidden; the label and status line carry the meaning.

The card grid uses minmax(0, 1fr) plus min-width: 0; without that, the image's intrinsic width forces the cards wide. At the 360 px popup width the cards are 153 px wide with 66 px previews, and the Original frame is 46% of the content width. The faded crop overflow is a single pseudo-element behind the preview with a vertical opacity mask, not a second image or a mirrored reflection.

Renderer

src/player/fill.ts exports applyFill(player) and reads the stored state itself:

  • disabled — removes flrm-fill-on and both scale variables
  • crop — sets both variables to max(player / video, video / player)
  • stretch — sets the shorter axis to 1 and the longer axis to the fill ratio
  • unknown player or video size — clears the fill, so changing modes before the size is known cannot leave stale geometry

One class, flrm-fill-on, and one transform block in content.css handle both modes; crop sets (s, s), stretch sets (s, 1) or (1, s). Transforms are still used rather than width/height plus object-fit: YouTube sizes .html5-main-video to the video's own aspect ratio and centres it inside the player, and the video container can have zero height.

Migration

Only the pre-1.3.0 cropEnabled key is migrated. cropMode was never in a release, so it is not read.

Stored state Result
fillEnabled plus a valid fillMode used unchanged
cropEnabled: true only crop, enabled
cropEnabled: false only crop, disabled
nothing or malformed crop, disabled

The old key is removed after it is moved. The migration is marked in src/storage/state.ts for removal in the release after 1.3.0. A fresh install starts in crop, off.

onStorageChange watches both fillEnabled and fillMode, so changing a mode in the popup updates open YouTube tabs immediately.

Update: popup redesign

The toolbar popup now mirrors the player: an Original frame branches into two result cards, Crop and Stretch. The header shows the current state (Crop is off/on, Stretch is off/on) with a green dot when on. The selected card gets a white outline and a filled radio, without the accent tint from the first draft. The selected Crop card shows the cut-off parts as a faded overflow above and below the frame instead of a mirrored reflection. The footer is only Share feedback and the version, and the popup is 360 px wide.

Both previews keep looping; the Original frame supplies the before state, and reduced motion holds each card in its applied state.

Validation

  • bun run typecheck — clean
  • bun test — 32 pass, 0 fail
  • web-ext lint — 0 errors, 1 pre-existing Firefox Android min-version warning

@Deepakktripathy Deepakktripathy changed the title Feature/stretch feat: add stretch mode Nov 9, 2026

@sudhz sudhz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://optimize-musicians-jennifer-contracts.trycloudflare.com/

i like this format better

also we gotta remove built by @sudhz

@sudhz

sudhz commented Nov 9, 2026

Copy link
Copy Markdown
Owner

lmk if you need that balloon image

@sudhz

sudhz commented Nov 9, 2026

Copy link
Copy Markdown
Owner

i kinda like the stretch is on / crop is on indicator from your design tho, let's keep that

but borrow everything else from that design i shared

@sudhz

sudhz commented Nov 9, 2026

Copy link
Copy Markdown
Owner

keep the PR title and commit message like historical commit format? we don't use stuff like feat or ops yet

@Deepakktripathy Deepakktripathy changed the title feat: add stretch mode added stretch mode Nov 10, 2026
@sudhz

sudhz commented Nov 10, 2026

Copy link
Copy Markdown
Owner

can we update the screenshots in the PR description?

@sudhz

sudhz commented Nov 10, 2026

Copy link
Copy Markdown
Owner

@copilot is this using more code than necessary? a 1,000+ line addition for a simple change like this seems a bit off to me. can you review?

Co-authored-by: sudhz <61375120+sudhz@users.noreply.github.com>

Copilot AI commented Nov 10, 2026

Copy link
Copy Markdown

@copilot is this using more code than necessary? a 1,000+ line addition for a simple change like this seems a bit off to me. can you review?

Reviewed and trimmed it in 02432f0. I removed the non-essential changelog/readme/version churn and simplified the popup previews to static applied states (no loop). That drops the branch-vs-main delta to a much tighter set centered on the stretch-mode implementation.

Copilot AI requested a review from sudhz November 10, 2026 11:47
@sudhz

sudhz commented Nov 10, 2026

Copy link
Copy Markdown
Owner

@Deepakktripathy here's the balloon image from the design. Please use it in place of preview.jpg:

balloon preview

It's square on purpose. Inside the 21:9 frame it gets wide side bars, so crop and stretch look clearly different. With the 16:9 bunny frame, both cards only scale by 1.31×, so they look almost the same. If you switch to it, change --preview-fill from 1.3125 to 2.3333 (21/9 ÷ 1).

One more thing from the design: the faded bits above and below the selected Crop card are the parts that get cut off by the crop. They aren't a mirrored reflection, so the .mirror markup can go. Instead, show the overflow of the crop preview at low opacity outside the frame.

@sudhz sudhz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Deepakktripathy thanks for working through this. Here's everything left before we merge. Heads up: I bumped the version to 1.3.0 and force-pushed (c1fb128). If you have the older 607d008 locally, run git pull --rebase before pushing.

Design

  1. Use the balloon image in place of the bunny preview.jpg (links in this comment), and change --preview-fill from 1.3125 to 2.3333. With a square picture, Crop and Stretch look clearly different. With the 16:9 bunny they look almost the same.
  2. Fix the faded edges on the Crop card. In the design they're the parts the crop cuts off, shown faded above and below the card. They aren't a mirrored reflection, so please remove the .mirror markup (4 extra images) and its CSS.

Less code

  1. Remove the cropMode migration: src/storage/mode.ts, parseLegacyMode, tests/mode.test.ts, and the cropMode state tests. That key only existed on this branch and was never released.
  2. Keep the fillEnabled rename, but make the cropEnabled migration short and temporary. Mark it for removal in the release after 1.3.0, and cover it with a single test that gets deleted along with it. Something like:
    // Temporary: moves the pre-1.3.0 `cropEnabled` key. Remove in the release after 1.3.0.
    if (typeof result[ENABLED_KEY] !== 'boolean' && typeof result.cropEnabled === 'boolean') {
        enabled = result.cropEnabled;
        await extensionApi.storage.local.set({ [ENABLED_KEY]: enabled });
        await extensionApi.storage.local.remove('cropEnabled');
    }
  3. Have the apply function read the state itself, the way applyCrop did, so callers just call applyFill(getPlayer()) instead of passing isEnabled(), getMode() at 5 call sites.
  4. Use one transform for both modes: one player class plus --flrm-scale-x / --flrm-scale-y. Crop sets (s, s). Stretch sets (s, 1) or (1, s). That removes the second class, --flrm-scale, and the duplicate CSS block.

Naming

  1. Use "fill" everywhere. Right now it's a mix of "fill" (fillMode, FillMode, "Fill mode") and "fit":

    • fit.ts → fill.ts
    • applyFit / applyFitNow / applyFitAndSync → applyFill / applyFillNow / applyFillAndSync
    • player class → flrm-fill-on

    FillMode, getMode, selectMode, toggleEnabled, isEnabled, and the icon classes .flrm-crop / .flrm-stretch can stay as they are.

Bug

  1. If the mode changes before the video's size is known, applyFit returns early and leaves the previous mode's class on the player. Item 6 fixes this.

PR housekeeping

  1. Update the PR description. It still describes the looping animation, reduced-motion handling, and "accent outline" cards, which no longer exist. Please also add screenshots of the new popup.
  2. Commit format: 2c3c32e still starts with feat:. I'll squash-merge with a plain title, so there's no need to rewrite history.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants