Files
cutdex/packages/cutdex_preview
T
lingjhf 38ca180cf7
Gitea CI / Check code and tests (pull_request) Failing after 8s
Gitea CI / Build Android APK (pull_request) Skipped
Gitea CI / Build Windows x64 app (pull_request) Skipped
Gitea CI / Audit and package Windows x64 (pull_request) Skipped
Gitea CI / Assemble and validate CI artifacts (pull_request) Skipped
Gitea CI / Gitea CI passed (pull_request) Failing after 1s
refactor(core): own editor UI and pin verified native releases
38ca180cf7 · 2026-10-12 03:20:29 +08:00
History
..

cutdex_preview

Application-owned Flutter preview controllers, canvas and transform/mask interactions. Core provides editing and execution semantics; this package binds the native session to Flutter and owns preview lifecycle. The package has no App, Riverpod, workspace, platform-grant or localization dependency.

  • PreviewController accepts an EditorSession, the active-sequence getter and the host's existing TimelineViewController resolver. When selection changes, the host notifies the editor session.
  • It owns one runtime session and attaches that same target to editor-owned execution coordination. Playback and seek go directly to runtime. Authored transforms and masks commit through editor; timelines remain local.
  • SourcePreviewController uses runtime directly. PreviewMediaLoader binds the source outside the package and retains its access until the callback finishes, including native session cleanup. No editor is needed for source playback.
  • PreviewCanvas, PreviewInteractionOverlay and MaskInteractionOverlay provide reusable presentation. The App supplies padding, background, error feedback and toolbars. PreviewPolicy supplies viewing assumptions; project settings override timeline defaults.
  • PreviewPolicy.skimmingMode uses runtime's SkimmingMode directly: audible by default, or silent. Both preview controllers pass this policy to the runtime without Boolean adapters.
  • Errors remain original objects. Unavailable assets carry runtime error codes; unavailableAtPlayhead returns clip names for the host to format.
final preview = PreviewController(
  timeline: editor,
  runtime: runtime,
  activeSequence: () => selectedSequence,
  viewForSequence: timelineViewFor,
);
await preview.initialize();
// Mount RuntimePreview(session: preview.session!) inside PreviewCanvas.
// Detach widgets before closing and keep host timeline views alive until close.
await preview.close(); // releases preview; does not close editor

Concurrent initialize calls share one startup; initialization after close is rejected. Public runtime and playback state is read-only. The host reports preparation failures through reportFailure, without assigning controller fields. PreviewController.close releases its notifier too; after SourcePreviewController.close, dispose its notifier. Closing waits for pending startup, playback and native cleanup, even when a host callback or cleanup action fails; it reports the first failure after releasing other resources. Clearing the active sequence detaches the old view, cancels seek and pauses output. The host must close preview before releasing the project's media grants.

Run flutter test packages/cutdex_preview/test from the application workspace. App tests retain inspector/MCP/preview integration coverage.

PreviewController implements EditorPreviewService and registers a non-owning port on EditorSession during initialization, unregistering before close. Tools query or control this existing timeline preview by explicit sequence ID. Controls reject inactive sequences, preserve authored history and reuse native synchronization. Explicit pause is sent even before the native playing event arrives. Source preview remains independent.

EditorAlignmentService resolves canvas alignment at explicit sequence time using the synchronized execution geometry. It rejects stale, missing or ambiguous geometry and active timelines; the editor owns the final version check and authored commit. CanvasAlignment is defined by editor and re-exported by preview.

SourcePreviewController.control provides explicit play, pause and exact seek, serialized with UI playback and drained on close. The App PreviewTarget owns the selected controller and source navigation; both tools and the panel reuse it. Explicit pause reaches native playback even before a playing event arrives.

Editor selection decorations are painted by Flutter over native video output. Material and mask selections share blue bounds, white corner squares and an output-pixel dimension label. Drag a corner square to resize; drag just outside any corner to rotate, with Shift snapping to 15 degrees. Transform bounds follow acknowledged native renders. Selection and style changes do not acquire a paused native frame or submit native decorations.

Selection strokes use an integer physical-pixel width based on display density. Axis-aligned bounds and corner squares align their stroke boundaries to physical pixels. Rotated outlines use vertex opacity ramps across a physical-pixel fringe, preserving subpixel geometry while smoothing shallow diagonals. These adjustments affect painting only.

Move and resize snapping uses 1% of the displayed canvas's shorter side, capped at six logical pixels. Release distance is 5/3 of the entry distance. Both distances are converted to output pixels before evaluating geometry.

Canvas and property rotation drags share normalizeRotationDegrees, wrapping to [-180, 180) from the fixed gesture baseline so crossing the boundary or reversing direction remains continuous.