mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-03 04:38:33 +00:00
feat: Persist Studio manual edits via manifest (#593)
## Summary Studio manual geometry edits now persist as a project-local manifest instead of being baked into composition source on each gesture. The manifest lives at: ```text .hyperframes/studio-manual-edits.json ``` It is the source of truth for manual drag, resize, rotation, inspector geometry edits, group moves, and selected-layer reset. ## Architecture - **Manifest-backed edits**: each edit stores a kind (`path-offset`, `box-size`, `rotation`), a source-scoped target, and the edit values. - **Source-scoped resolution**: targets include `sourceFile`, `id`, `selector`, and `selectorIndex`, so duplicate selectors in nested compositions resolve against the owning source file. - **Additive CSS layer**: move uses CSS `translate`, resize writes stable dimensions/flex sizing, and rotation uses CSS `rotate` over the authored base. - **Shared replay runtime**: Studio preview, thumbnails, frame capture, producer renders, and CLI Studio renders/thumbnails all use the same core manual-edit render script. - **Animation-safe replay**: Studio reapplies the manual layer after load, refresh, timeline seeks, player operations, playback frames, thumbnail seeks, and render seeks instead of rewriting GSAP timelines. - **History and handoff**: the manifest is a normal project file, so undo/redo and agent edits can preserve, modify, or remove manual visual edits explicitly. ## User Impact Users can move, resize, rotate, group-move, and reset supported layers from the canvas or inspector, then refresh, capture thumbnails/screenshots, play animated compositions, and render videos without manual edits drifting away from the edited state. ## Main Files - `packages/studio/src/components/editor/manualEdits.ts` - `packages/studio/src/components/editor/DomEditOverlay.tsx` - `packages/studio/src/components/editor/PropertyPanel.tsx` - `packages/studio/src/App.tsx` - `packages/core/src/studio-api/helpers/manualEditsRenderScript.ts` - `packages/studio/vite.config.ts` - `packages/cli/src/server/studioServer.ts` - `packages/core/src/compiler/htmlBundler.ts` - `packages/producer/src/services/htmlCompiler.ts` - `packages/core/src/studio-api/routes/thumbnail.ts` - `packages/producer/src/services/fileServer.ts` - `packages/producer/src/services/renderOrchestrator.ts` ## Test Plan ```bash volta run --node 22.20.0 bun run build volta run --node 22.20.0 bun run --filter @hyperframes/core test -- src/studio-api/helpers/manualEditsRenderScript.test.ts volta run --node 22.20.0 bun run --filter @hyperframes/core typecheck volta run --node 22.20.0 bun run --filter @hyperframes/studio typecheck volta run --node 22.20.0 bun run --filter @hyperframes/cli typecheck volta run --node 22.20.0 bunx oxlint <changed files> volta run --node 22.20.0 bunx oxfmt --check <changed files> git diff --check ```
This commit is contained in:
@@ -13,6 +13,7 @@ import { createProjectWatcher, type ProjectWatcher } from "./fileWatcher.js";
|
||||
import { loadRuntimeSource } from "./runtimeSource.js";
|
||||
import { VERSION as version } from "../version.js";
|
||||
import {
|
||||
createStudioManualEditsRenderBodyScript,
|
||||
createStudioApi,
|
||||
getMimeType,
|
||||
type StudioApiAdapter,
|
||||
@@ -22,6 +23,8 @@ import {
|
||||
import { getElementScreenshotClip } from "@hyperframes/core/studio-api/screenshot-clip";
|
||||
import type { ScreenshotClip } from "@hyperframes/core/studio-api/screenshot-clip";
|
||||
|
||||
const STUDIO_MANUAL_EDITS_PATH = ".hyperframes/studio-manual-edits.json";
|
||||
|
||||
// ── Path resolution ─────────────────────────────────────────────────────────
|
||||
|
||||
function resolveDistDir(): string {
|
||||
@@ -77,6 +80,38 @@ function resolveRuntimePath(): string {
|
||||
return builtPath;
|
||||
}
|
||||
|
||||
function readStudioManualEditManifestContent(projectDir: string): string {
|
||||
const manifestPath = join(projectDir, STUDIO_MANUAL_EDITS_PATH);
|
||||
if (!existsSync(manifestPath)) return "";
|
||||
try {
|
||||
return readFileSync(manifestPath, "utf-8");
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
async function applyStudioManualEditsToThumbnailPage(
|
||||
page: import("puppeteer-core").Page,
|
||||
manifestContent: string,
|
||||
activeCompositionPath: string,
|
||||
): Promise<void> {
|
||||
const script = createStudioManualEditsRenderBodyScript(manifestContent, {
|
||||
activeCompositionPath,
|
||||
});
|
||||
if (!script) return;
|
||||
await page.addScriptTag({ content: script });
|
||||
}
|
||||
|
||||
async function reapplyStudioManualEditsToThumbnailPage(
|
||||
page: import("puppeteer-core").Page,
|
||||
): Promise<void> {
|
||||
await page.evaluate(() => {
|
||||
const apply = (window as Window & { __hfStudioManualEditsApply?: () => number })
|
||||
.__hfStudioManualEditsApply;
|
||||
if (typeof apply === "function") apply();
|
||||
});
|
||||
}
|
||||
|
||||
// ── Shared thumbnail browser (singleton per process) ────────────────────────
|
||||
// One browser instance is reused across all composition thumbnail requests.
|
||||
// Spawning a new Puppeteer process per request adds 2-5s overhead and causes
|
||||
@@ -198,10 +233,13 @@ export function createStudioServer(options: StudioServerOptions): StudioServer {
|
||||
// Continue without — acquireBrowser will try its own resolution
|
||||
}
|
||||
|
||||
const manifestContent = readStudioManualEditManifestContent(opts.project.dir);
|
||||
const manualEditsRenderScript = createStudioManualEditsRenderBodyScript(manifestContent);
|
||||
const job = createRenderJob({
|
||||
fps: opts.fps as 24 | 30 | 60,
|
||||
quality: opts.quality as "draft" | "standard" | "high",
|
||||
format: opts.format,
|
||||
...(manualEditsRenderScript ? { renderBodyScripts: [manualEditsRenderScript] } : {}),
|
||||
});
|
||||
const startTime = Date.now();
|
||||
const onProgress = (j: { progress: number; currentStage?: string }) => {
|
||||
@@ -258,11 +296,14 @@ export function createStudioServer(options: StudioServerOptions): StudioServer {
|
||||
win.__timeline.seek(t);
|
||||
}
|
||||
}, opts.seekTime);
|
||||
const manifestContent = readStudioManualEditManifestContent(opts.project.dir);
|
||||
await applyStudioManualEditsToThumbnailPage(page, manifestContent, opts.compPath);
|
||||
// Let the seek render settle.
|
||||
await new Promise((r) => setTimeout(r, 200));
|
||||
await reapplyStudioManualEditsToThumbnailPage(page);
|
||||
let clip: ScreenshotClip | undefined;
|
||||
if (opts.selector) {
|
||||
clip = await page.evaluate(getElementScreenshotClip, opts.selector);
|
||||
clip = await page.evaluate(getElementScreenshotClip, opts.selector, opts.selectorIndex);
|
||||
}
|
||||
const screenshot = (await page.screenshot(
|
||||
opts.format === "png"
|
||||
@@ -318,8 +359,8 @@ export function createStudioServer(options: StudioServerOptions): StudioServer {
|
||||
|
||||
app.get("/api/events", (c) => {
|
||||
return streamSSE(c, async (stream) => {
|
||||
const listener = () => {
|
||||
stream.writeSSE({ event: "file-change", data: "{}" }).catch(() => {});
|
||||
const listener = (path: string) => {
|
||||
stream.writeSSE({ event: "file-change", data: JSON.stringify({ path }) }).catch(() => {});
|
||||
};
|
||||
watcher.addListener(listener);
|
||||
while (true) {
|
||||
|
||||
Reference in New Issue
Block a user