8000 feat(editor): stage-based output + per-element viewport transform by johannboehme · Pull Request #21 · johannboehme/tk-1 · GitHub
[go: up one dir, main page]

Skip to content

feat(editor): stage-based output + per-element viewport transform - #21

Merged
johannboehme merged 3 commits into
mainfrom
claude/peaceful-gagarin-db0fac
May 2, 2026
Merged

johannboehme merged 3 commits into
mainfrom
claude/peaceful-gagarin-db0fac

Conversation

@johannboehme
Copy link
Copy Markdown
Owner

Summary

  • Drop the bbox(maxW, maxH) Output-Frame logic. Stage shape is now driven explicitly by the Export panel's Aspect + long-side Resolution pickers, with auto-init from the first clip.
  • Per-clip viewportTransform { scale, x, y } on top of a cover-fit default. The new StageInteractionOverlay lets the user drag/wheel/dbl-click in the live preview to pan/zoom the active element. Alt = 5× precision.
  • Preview and export render paths now share applyViewportTransform from editor/render/element-transform.ts — the duplicate computeFitRect in local/render/compositor.ts is gone, plus a convergence test pins the two paths together so they can never drift again.
  • Export panel re-laid out: opinionated presets at the top (WEB = 16:9 1080p, MOBILE = 9:16 1080p, ARCHIVE = current aspect at H.265/Pristine), Aspect picker, long-side Resolution picker. Default preset is "custom" — Stage shape derives from the first clip on the timeline.
  • Persistence: per-clip viewportTransform and the full exportSpec round-trip through useAutoPersist so reload restores everything.

Why

The old bbox heuristic produced unusable squares when a project mixed widescreen + portrait clips. There was no way to pick the output shape, no way to frame each element inside the Stage, and the IOReadout's "Source vs Output" no longer matched the multi-clip reality.

Notes for review

  • Render-pass convergence is the architecture point. element-transform.ts is the single source of truth for "where does an element land on the Stage." Both editor/render/build-descriptor.ts (preview) and local/render/compositor.ts (export) call buildElementFitRect. editor/render/preview-export-convergence.test.ts rebuilds a frame through both paths and asserts identical fitRects.
  • All three backends (WebGPU / WebGL2 / Canvas2D) consume FrameLayer.fitRect unchanged — no backend code changes were needed; the rect can now extend past the canvas bounds and the implicit canvas clip handles the rest.
  • applyPreset was rewritten to set aspect + dims + codec + bitrate together (presets are opinionated recipes). Custom is the default and means "derived from the first clip."
  • DEFAULT_EXPORT.preset flipped from "web" to "custom" so first-time users see derived dims, not a forced 16:9.
  • Behind main by 3 commits (fix(editor): unmount inactive layout — kill duplicate <MasterAudio>/<TransportBar> #18-fix(transport): L shortcut clamps loop region into trim #20), but git merge-tree confirms a clean merge — no conflicts.

Test plan

  • Drop a widescreen video → Stage = 1920×1080, 16:9 chip active
  • Drop a portrait video next → Stage stays as user's first choice; cover-fit places portrait centered, sides cropped
  • Drag the active element in the preview → it moves; Alt-drag is 5× slower
  • Mousewheel on the preview → zoom; Alt-wheel is finer
  • Double-click element → resets to cover-fit; reset hint disappears
  • Switch Aspect 16:9 → 9:16 → Stage flips, dims re-derive at same long-side
  • Click WEB preset → 16:9 1920×1080 H.264 Good
  • Click MOBILE preset → 9:16 1080×1920 H.264 Low
  • Reload page → Stage shape, picker selections, and per-clip framings all restored
  • Render a project → output mp4 has the exact dims shown in the panel (verify via ffprobe)

🤖 Generated with Claude Code

johannboehme and others added 3 commits May 2, 2026 22:58
The render pipeline used to compute Output dims as bbox(maxW, maxH)
across all clips. With multi-aspect mixes (Widescreen + Portrait) that
produced a square output with letterboxing on both axes — and the user
had no control over which slice ended up in the frame.

Replace it with an explicit Stage:

* Output dims now come from `exportSpec.resolution`. The Export panel's
  ASPECT + RESOLUTION pickers (long-side mode) drive the Stage shape,
  with the first-clip auto-init seeding the spec the first time a clip
  reports its dims.
* Each clip carries an optional `viewportTransform { scale, x, y }`
  applied on top of a cover-fit default. Drag / wheel / dbl-click in
  the live preview mutate it via the new `StageInteractionOverlay`,
  Alt-modifier giving 5x precision. Per-element so two portraits in a
  widescreen Stage can each frame their own subject.
* Preview and export now share `applyViewportTransform` from
  `editor/render/element-transform.ts` — the duplicated `computeFitRect`
  copies in `build-descriptor.ts` and `local/render/compositor.ts` are
  gone, with a convergence test pinning the two paths together.
* Export panel re-laid out: presets (Web/Archive/Mobile/Custom) at the
  top as opinionated recipes, then Aspect, Resolution, Quality. WEB =
  16:9 1080p, MOBILE = 9:16 1080p, ARCHIVE keeps the user's aspect at
  H.265/Pristine. Custom is the default — derived from the first clip.
* Persistence: `viewportTransform` per clip + the full `exportSpec`
  round-trip through `useAutoPersist` so reload restores the Stage
  shape and per-clip framing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…nated recipes

Type-check failures from CI:
- `capLongSide` was unused after applyPreset's rewrite (presets now use
  deriveResolution directly).
- The applyPreset test suite still asserted the old "preserve user's
  aspect" behaviour. Rewrite it to match the new contract — WEB always
  16:9 1080p, MOBILE always 9:16 1080p, ARCHIVE keeps user's aspect at
  H.265/Pristine.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The component test still asserted preset='web' default and Mobile
preserving source aspect — both no longer hold:
- DEFAULT_EXPORT.preset is now 'custom' (Stage shape derives from the
  first clip's dims via the store's auto-init).
- MOBILE is opinionated: 9:16 1080×1920 regardless of source.
- WEB is opinionated: 16:9 1920×1080 regardless of source.
- ARCHIVE keeps current aspect/dims (with 16:9 4K fallback).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@johannboehme
johannboehme merged commit 73c5cd3 into main May 2, 2026
1 check passed
@johannboehme
johannboehme deleted the claude/peaceful-gagarin-db0fac branch May 2, 2026 21:14
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.

1 participant

0