@hyperframes/studio 0.8.205 → 0.8.207
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/hyperframes-player-Cm5aBiKq.js +478 -0
- package/dist/assets/{index-dy6GQJn4.js → index-BF9YeBnC.js} +142 -142
- package/dist/assets/{index-C8hp9Y7c.js → index-BrqAmMRt.js} +1 -1
- package/dist/{chunk-Z5NKM57J.js → chunk-3EAFE522.js} +8 -4
- package/dist/{chunk-2YCKGJFD.js → chunk-HPIJDMWG.js} +5 -5
- package/dist/{chunk-T43DM7Q6.js → chunk-OGIOFEC7.js} +4 -2
- package/dist/{domEditingLayers-WMDSHU5P.js → domEditingLayers-7Z6J4UOK.js} +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.html +1 -1
- package/dist/index.js +235 -127
- package/dist/player.js +2 -2
- package/package.json +8 -8
- package/src/components/MediaPreview.test.tsx +69 -0
- package/src/components/MediaPreview.tsx +10 -5
- package/src/components/editor/domEditLayerWalkCache.test.ts +48 -0
- package/src/components/editor/domEditLayerWalkCache.ts +6 -0
- package/src/components/editor/domEditingLayers.ts +3 -2
- package/src/components/sidebar/PromptPreviewModal.test.tsx +22 -0
- package/src/components/sidebar/PromptPreviewModal.tsx +1 -0
- package/src/hooks/timelineEditingHelpers.test.ts +59 -0
- package/src/hooks/timelineEditingHelpers.ts +4 -5
- package/src/hooks/useGestureRecording.ts +5 -3
- package/src/player/components/PlayerControls.tsx +5 -2
- package/src/player/components/ShortcutsPanel.tsx +4 -2
- package/src/player/components/Timeline.test.ts +12 -0
- package/src/player/components/TimelineProvider.tsx +1 -0
- package/src/player/components/TimelineRuler.tsx +4 -7
- package/src/player/components/TimelineRulerPart.tsx +1 -0
- package/src/player/components/timelineClipDragPreview.test.ts +10 -0
- package/src/player/components/timelineClipDragPreview.ts +4 -5
- package/src/player/components/timelineRulerGeometry.ts +14 -3
- package/src/player/components/useTimelineClipDrag.ts +5 -2
- package/src/player/components/useTimelineProviderState.tsx +2 -1
- package/src/player/components/useTimelineTicks.ts +4 -1
- package/src/player/hooks/previewMessageRouter.test.ts +34 -0
- package/src/player/hooks/previewMessageRouter.ts +14 -3
- package/src/player/hooks/usePlaybackKeyboard.test.ts +19 -0
- package/src/player/hooks/usePlaybackKeyboard.ts +5 -2
- package/src/player/hooks/useShadowPreviewReload.ts +4 -1
- package/src/player/hooks/useTimelinePlayer.shadowReload.test.ts +21 -0
- package/src/player/lib/mediaFetch.test.ts +163 -0
- package/src/player/lib/mediaFetch.ts +98 -0
- package/src/player/lib/mediaProbe.test.ts +21 -1
- package/src/player/lib/mediaProbe.ts +4 -2
- package/src/player/lib/thumbnailVideoDecoder.test.ts +24 -1
- package/src/player/lib/thumbnailVideoDecoder.ts +3 -1
- package/src/player/lib/time.test.ts +13 -13
- package/src/player/lib/time.ts +4 -4
- package/src/utils/linkedClipPreferences.ts +2 -0
- package/src/utils/sourceScopedSelectorIndex.ts +5 -2
- package/dist/assets/hyperframes-player-DzdSmJdB.js +0 -478
package/dist/player.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/studio",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.207",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -60,12 +60,12 @@
|
|
|
60
60
|
"dockview-react": "8.3.1",
|
|
61
61
|
"gsap": "^3.13.0",
|
|
62
62
|
"mediabunny": "^1.45.3",
|
|
63
|
-
"@hyperframes/core": "0.8.
|
|
64
|
-
"@hyperframes/parsers": "0.8.
|
|
65
|
-
"@hyperframes/
|
|
66
|
-
"@hyperframes/
|
|
67
|
-
"@hyperframes/
|
|
68
|
-
"@hyperframes/studio-server": "0.8.
|
|
63
|
+
"@hyperframes/core": "0.8.207",
|
|
64
|
+
"@hyperframes/parsers": "0.8.207",
|
|
65
|
+
"@hyperframes/player": "0.8.207",
|
|
66
|
+
"@hyperframes/shader-transitions": "0.8.207",
|
|
67
|
+
"@hyperframes/sdk": "0.8.207",
|
|
68
|
+
"@hyperframes/studio-server": "0.8.207"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"vite": "^6.4.2",
|
|
83
83
|
"vitest": "^4.1.11",
|
|
84
84
|
"zustand": "^5.0.0",
|
|
85
|
-
"@hyperframes/producer": "0.8.
|
|
85
|
+
"@hyperframes/producer": "0.8.207"
|
|
86
86
|
},
|
|
87
87
|
"peerDependencies": {
|
|
88
88
|
"react": "19",
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { act } from "react";
|
|
3
|
+
import { createRoot, type Root } from "react-dom/client";
|
|
4
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
5
|
+
import { MediaPreview } from "./MediaPreview";
|
|
6
|
+
|
|
7
|
+
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
8
|
+
|
|
9
|
+
let root: Root | null = null;
|
|
10
|
+
let host: HTMLDivElement | null = null;
|
|
11
|
+
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
if (root) act(() => root?.unmount());
|
|
14
|
+
root = null;
|
|
15
|
+
host = null;
|
|
16
|
+
document.body.replaceChildren();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
async function renderPreview(projectId: string, filePath: string): Promise<HTMLDivElement> {
|
|
20
|
+
if (!root) {
|
|
21
|
+
host = document.createElement("div");
|
|
22
|
+
document.body.append(host);
|
|
23
|
+
root = createRoot(host);
|
|
24
|
+
}
|
|
25
|
+
await act(async () => {
|
|
26
|
+
root?.render(<MediaPreview projectId={projectId} filePath={filePath} />);
|
|
27
|
+
});
|
|
28
|
+
return host as HTMLDivElement;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe("MediaPreview", () => {
|
|
32
|
+
it("retries a repaired file after visiting another media source", async () => {
|
|
33
|
+
const host = await renderPreview("test", "broken.png");
|
|
34
|
+
const failedImage = host.querySelector("img");
|
|
35
|
+
expect(failedImage).not.toBeNull();
|
|
36
|
+
|
|
37
|
+
await act(async () => {
|
|
38
|
+
failedImage?.dispatchEvent(new Event("error"));
|
|
39
|
+
});
|
|
40
|
+
expect(host.textContent).toContain("Couldn't load this file");
|
|
41
|
+
|
|
42
|
+
await renderPreview("test", "healthy.png");
|
|
43
|
+
expect(host.querySelector("img")?.getAttribute("src")).toContain("healthy.png");
|
|
44
|
+
|
|
45
|
+
await renderPreview("test", "broken.png");
|
|
46
|
+
expect(host.querySelector("img")?.getAttribute("src")).toContain("broken.png");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("resets failure state when the project changes, but preserves a current failure", async () => {
|
|
50
|
+
const host = await renderPreview("first", "broken.png");
|
|
51
|
+
const image = host.querySelector("img");
|
|
52
|
+
await act(async () => {
|
|
53
|
+
image?.dispatchEvent(new Event("error"));
|
|
54
|
+
});
|
|
55
|
+
expect(host.textContent).toContain("Couldn't load this file");
|
|
56
|
+
|
|
57
|
+
await renderPreview("second", "broken.png");
|
|
58
|
+
expect(host.querySelector("img")?.getAttribute("src")).toContain("/second/preview/broken.png");
|
|
59
|
+
|
|
60
|
+
const secondImage = host.querySelector("img");
|
|
61
|
+
await act(async () => {
|
|
62
|
+
secondImage?.dispatchEvent(new Event("error"));
|
|
63
|
+
});
|
|
64
|
+
expect(host.textContent).toContain("Couldn't load this file");
|
|
65
|
+
|
|
66
|
+
await renderPreview("second", "broken.png");
|
|
67
|
+
expect(host.querySelector("img")).toBeNull();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { buildProjectApiPath } from "../utils/projectRouting";
|
|
2
|
-
import { useState } from "react";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
3
|
import { IMAGE_EXT, VIDEO_EXT, AUDIO_EXT } from "../utils/mediaTypes";
|
|
4
4
|
import { encodeUrlPath } from "@hyperframes/parsers";
|
|
5
5
|
|
|
@@ -32,10 +32,15 @@ function MediaErrorPanel({ name, filePath }: { name: string; filePath: string })
|
|
|
32
32
|
export function MediaPreview({ projectId, filePath }: { projectId: string; filePath: string }) {
|
|
33
33
|
const serveUrl = buildProjectApiPath(projectId, `/preview/${encodeUrlPath(filePath)}`);
|
|
34
34
|
const name = filePath.split("/").pop() ?? filePath;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
const [failure, setFailure] = useState<{ source: string; failed: boolean }>({
|
|
36
|
+
source: serveUrl,
|
|
37
|
+
failed: false,
|
|
38
|
+
});
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
setFailure({ source: serveUrl, failed: false });
|
|
41
|
+
}, [serveUrl]);
|
|
42
|
+
const failed = failure.source === serveUrl && failure.failed;
|
|
43
|
+
const setFailed = () => setFailure({ source: serveUrl, failed: true });
|
|
39
44
|
|
|
40
45
|
if (failed) return <MediaErrorPanel name={name} filePath={filePath} />;
|
|
41
46
|
|
|
@@ -148,6 +148,54 @@ describe("collectDomEditLayerItems incremental rebuild", () => {
|
|
|
148
148
|
});
|
|
149
149
|
});
|
|
150
150
|
|
|
151
|
+
it("queries the document for no selector when a walk meets elements it has not seen", () => {
|
|
152
|
+
const root = mountPreview(12);
|
|
153
|
+
const boxes = Array.from(root.querySelectorAll<HTMLElement>(".box"));
|
|
154
|
+
// The scenes a scrub has not reached yet: hidden, so no identity is read for them.
|
|
155
|
+
for (const box of boxes.slice(6)) box.style.display = "none";
|
|
156
|
+
const cache = createDomEditLayerWalkCache();
|
|
157
|
+
const observer = new MutationObserver(() => {});
|
|
158
|
+
observer.observe(document.documentElement, DOM_EDIT_LAYER_OBSERVER_INIT);
|
|
159
|
+
try {
|
|
160
|
+
collectDomEditLayerItems(root, opts, undefined, cache);
|
|
161
|
+
for (const box of boxes.slice(6)) box.style.display = "";
|
|
162
|
+
cache.ingest(observer.takeRecords());
|
|
163
|
+
|
|
164
|
+
const real = document.querySelectorAll.bind(document);
|
|
165
|
+
let queries = 0;
|
|
166
|
+
Object.defineProperty(document, "querySelectorAll", {
|
|
167
|
+
configurable: true,
|
|
168
|
+
value: (selector: string) => {
|
|
169
|
+
queries += 1;
|
|
170
|
+
return real(selector);
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
let kept: DomEditLayerItem[];
|
|
174
|
+
try {
|
|
175
|
+
kept = collectDomEditLayerItems(root, opts, undefined, cache);
|
|
176
|
+
} finally {
|
|
177
|
+
delete (document as Partial<Document>).querySelectorAll;
|
|
178
|
+
}
|
|
179
|
+
// The revealed cards are in the kept index for their selector.
|
|
180
|
+
expect(queries).toBe(0);
|
|
181
|
+
expect(shape(kept)).toEqual(shape(collectDomEditLayerItems(root, opts)));
|
|
182
|
+
} finally {
|
|
183
|
+
observer.disconnect();
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("builds the selector index again once a node is added", () => {
|
|
188
|
+
withWarmWalk(6, ({ root, cache, observer }) => {
|
|
189
|
+
const added = document.createElement("div");
|
|
190
|
+
added.className = "box";
|
|
191
|
+
root.insertBefore(added, root.firstElementChild);
|
|
192
|
+
cache.ingest(observer.takeRecords());
|
|
193
|
+
|
|
194
|
+
const kept = collectDomEditLayerItems(root, opts, undefined, cache);
|
|
195
|
+
expect(shape(kept)).toEqual(shape(collectDomEditLayerItems(root, opts)));
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
151
199
|
/**
|
|
152
200
|
* The equivalence half, and the one that would catch a wrong optimisation
|
|
153
201
|
* rather than a missing one. Every mutation KIND the invalidation reasons
|
|
@@ -47,6 +47,7 @@ import {
|
|
|
47
47
|
resolveDomLayerIdentity,
|
|
48
48
|
} from "./domEditingElement";
|
|
49
49
|
import type { DomEditSelection } from "./domEditingTypes";
|
|
50
|
+
import type { KeptIndexes } from "../../utils/sourceScopedSelectorIndex";
|
|
50
51
|
|
|
51
52
|
/** How an element is addressed. Survives style writes; see `readIdentity`. */
|
|
52
53
|
export type DomEditLayerIdentity = Pick<
|
|
@@ -160,16 +161,20 @@ export interface DomEditLayerWalkCache {
|
|
|
160
161
|
ingest(records: MutationRecord[]): void;
|
|
161
162
|
/** Forget every entry — the fallback for anything not attributable. */
|
|
162
163
|
invalidateAll(): void;
|
|
164
|
+
/** Selector occurrence indexes, kept across walks and dropped with `identities`, which derive from them. */
|
|
165
|
+
readonly selectorIndex: KeptIndexes;
|
|
163
166
|
}
|
|
164
167
|
|
|
165
168
|
export function createDomEditLayerWalkCache(): DomEditLayerWalkCache {
|
|
166
169
|
let presence = new WeakMap<HTMLElement, PresenceMemo>();
|
|
167
170
|
let identities = new WeakMap<HTMLElement, IdentityMemo>();
|
|
168
171
|
let scope: string | null = null;
|
|
172
|
+
const selectorIndex: KeptIndexes = new Map();
|
|
169
173
|
|
|
170
174
|
const invalidateAll = () => {
|
|
171
175
|
presence = new WeakMap();
|
|
172
176
|
identities = new WeakMap();
|
|
177
|
+
selectorIndex.clear();
|
|
173
178
|
};
|
|
174
179
|
|
|
175
180
|
const drop = (el: HTMLElement | null) => {
|
|
@@ -262,6 +267,7 @@ export function createDomEditLayerWalkCache(): DomEditLayerWalkCache {
|
|
|
262
267
|
}
|
|
263
268
|
},
|
|
264
269
|
invalidateAll,
|
|
270
|
+
selectorIndex,
|
|
265
271
|
};
|
|
266
272
|
}
|
|
267
273
|
|
|
@@ -487,10 +487,11 @@ export function collectDomEditLayerItems(
|
|
|
487
487
|
// card or tile class. The walk is one synchronous read of a document it does
|
|
488
488
|
// not mutate, so one index per selector serves the whole of it. The pass lives
|
|
489
489
|
// here rather than in each caller because this function owns the loop.
|
|
490
|
-
|
|
490
|
+
const walkRoots = () => {
|
|
491
491
|
// Drilled into a group → show only its members; otherwise the whole tree.
|
|
492
492
|
for (const el of groupScopedLayerRoots(root, options.activeGroupElement ?? null)) visit(el, 0);
|
|
493
|
-
}
|
|
493
|
+
};
|
|
494
|
+
withSelectorIndexPass(root.ownerDocument, walkRoots, cache?.selectorIndex);
|
|
494
495
|
return items;
|
|
495
496
|
}
|
|
496
497
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
4
|
+
import { PromptPreviewModal } from "./PromptPreviewModal";
|
|
5
|
+
import { cleanupMounted, mountHost } from "../ui/mountHost.testHelpers";
|
|
6
|
+
|
|
7
|
+
afterEach(cleanupMounted);
|
|
8
|
+
|
|
9
|
+
describe("PromptPreviewModal", () => {
|
|
10
|
+
it("gives the prompt editor a stable accessible name", () => {
|
|
11
|
+
const prompt = "Change the title";
|
|
12
|
+
const title = "Example";
|
|
13
|
+
const host = mountHost(<PromptPreviewModal title={title} prompt={prompt} onClose={() => {}} />);
|
|
14
|
+
const dialog = host.querySelector('[role="dialog"]');
|
|
15
|
+
const textarea = host.querySelector("textarea");
|
|
16
|
+
|
|
17
|
+
expect(dialog?.getAttribute("aria-label")).toBe("Ask agent: Example");
|
|
18
|
+
expect(textarea?.getAttribute("aria-label")).toBe("Prompt");
|
|
19
|
+
expect(textarea?.getAttribute("aria-label")).not.toBe(prompt);
|
|
20
|
+
expect(textarea?.getAttribute("aria-label")).not.toBe(dialog?.getAttribute("aria-label"));
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
patchIframeDomTiming,
|
|
11
11
|
persistElementAttribute,
|
|
12
12
|
persistTimelineBatchEdit,
|
|
13
|
+
persistTimelineEdit,
|
|
13
14
|
type PersistTimelineBatchChange,
|
|
14
15
|
} from "./timelineEditingHelpers";
|
|
15
16
|
import type { TimelineElement } from "../player/store/playerStore";
|
|
@@ -415,6 +416,64 @@ describe("persistTimelineBatchEdit", () => {
|
|
|
415
416
|
});
|
|
416
417
|
});
|
|
417
418
|
|
|
419
|
+
describe("persistTimelineEdit", () => {
|
|
420
|
+
const SOURCE = `<div id="root"><video id="a" class="clip" data-start="1" data-duration="3"></video></div>`;
|
|
421
|
+
|
|
422
|
+
async function runEdit(id: string, start: number) {
|
|
423
|
+
vi.stubGlobal(
|
|
424
|
+
"fetch",
|
|
425
|
+
vi.fn(async () => ({ ok: true, json: async () => ({ content: SOURCE }) })),
|
|
426
|
+
);
|
|
427
|
+
const writes: Array<[string, string]> = [];
|
|
428
|
+
const pending = new Set<string>();
|
|
429
|
+
const element = el({ id, tag: "video", domId: id, start: 1, duration: 3 });
|
|
430
|
+
const done = persistTimelineEdit({
|
|
431
|
+
projectId: "p1",
|
|
432
|
+
element,
|
|
433
|
+
activeCompPath: "index.html",
|
|
434
|
+
label: "Resize timeline clip",
|
|
435
|
+
buildPatches: (original, target) =>
|
|
436
|
+
buildTimelineResizeTimingPatch(original, target, element, {
|
|
437
|
+
start,
|
|
438
|
+
duration: 3,
|
|
439
|
+
playbackStart: undefined,
|
|
440
|
+
}),
|
|
441
|
+
writeProjectFile: async (path, content) => {
|
|
442
|
+
writes.push([path, content]);
|
|
443
|
+
},
|
|
444
|
+
recordEdit: async () => {},
|
|
445
|
+
pendingTimelineEditPathRef: { current: pending },
|
|
446
|
+
});
|
|
447
|
+
return { done, writes, pending };
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
afterEach(() => {
|
|
451
|
+
vi.unstubAllGlobals();
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
it("saves nothing and says nothing when the clip already holds the values (a resize that lands where it began)", async () => {
|
|
455
|
+
// 1.0000001 is a different number from the clip's 1, so the gesture sees a change; the file writes "1" either way.
|
|
456
|
+
const { done, writes, pending } = await runEdit("a", 1.0000001);
|
|
457
|
+
await expect(done).resolves.toBeUndefined();
|
|
458
|
+
expect(writes).toHaveLength(0);
|
|
459
|
+
expect(pending.size).toBe(0);
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
it("writes a real change and marks its file", async () => {
|
|
463
|
+
const { done, writes, pending } = await runEdit("a", 2);
|
|
464
|
+
await done;
|
|
465
|
+
expect(writes).toHaveLength(1);
|
|
466
|
+
expect(writes[0]![1]).toContain('data-start="2"');
|
|
467
|
+
expect([...pending]).toEqual(["index.html"]);
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
it("still throws for a clip the file does not hold", async () => {
|
|
471
|
+
const { done, writes } = await runEdit("ghost", 2);
|
|
472
|
+
await expect(done).rejects.toThrow("Unable to patch timeline element ghost in index.html");
|
|
473
|
+
expect(writes).toHaveLength(0);
|
|
474
|
+
});
|
|
475
|
+
});
|
|
476
|
+
|
|
418
477
|
describe("deleteSelectedKeyframes", () => {
|
|
419
478
|
it("coalesces all removals and reloads only after the last one", () => {
|
|
420
479
|
usePlayerStore.setState({
|
|
@@ -351,7 +351,6 @@ export async function persistTimelineEdit(input: PersistTimelineEditInput): Prom
|
|
|
351
351
|
throw new Error(`Timeline element ${input.element.id} is missing a patchable target`);
|
|
352
352
|
}
|
|
353
353
|
|
|
354
|
-
input.pendingTimelineEditPathRef.current.add(targetPath);
|
|
355
354
|
await saveProjectFilesWithHistory({
|
|
356
355
|
projectId: input.projectId,
|
|
357
356
|
label: input.label,
|
|
@@ -359,10 +358,10 @@ export async function persistTimelineEdit(input: PersistTimelineEditInput): Prom
|
|
|
359
358
|
coalesceMs: input.coalesceMs,
|
|
360
359
|
files: {
|
|
361
360
|
[targetPath]: (current) => {
|
|
362
|
-
const patched =
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
361
|
+
const patched = patchTimelineChangesInSource(current, targetPath, [
|
|
362
|
+
{ element: input.element, buildPatches: input.buildPatches },
|
|
363
|
+
]);
|
|
364
|
+
if (patched !== current) input.pendingTimelineEditPathRef.current.add(targetPath);
|
|
366
365
|
return patched;
|
|
367
366
|
},
|
|
368
367
|
},
|
|
@@ -2,6 +2,7 @@ import { revealClip } from "@hyperframes/core/runtime/clip-reveal";
|
|
|
2
2
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
3
|
import { usePlayerStore, liveTime } from "../player/store/playerStore";
|
|
4
4
|
import { frameToSeconds, secondsToFrame } from "../player/lib/time";
|
|
5
|
+
import { useLinkedClipPreferences } from "../utils/linkedClipPreferences";
|
|
5
6
|
|
|
6
7
|
export interface GestureSample {
|
|
7
8
|
time: number;
|
|
@@ -141,12 +142,13 @@ function recordSample(r: RecordingRefs, time: number, properties: Record<string,
|
|
|
141
142
|
// stripStudioEditsFromTarget in studio-api), so the keyframes must already
|
|
142
143
|
// include it. Subtracting it made the committed gesture play shoved off by the
|
|
143
144
|
// offset (the offset was removed twice).
|
|
144
|
-
const
|
|
145
|
-
const
|
|
145
|
+
const fps = useLinkedClipPreferences.getState().compositionFps;
|
|
146
|
+
const frame = secondsToFrame(time, fps);
|
|
147
|
+
const sample = { time: frameToSeconds(frame, fps), properties: { ...properties } };
|
|
146
148
|
const lastIndex = r.samples.length - 1;
|
|
147
149
|
const lastSample = r.samples[lastIndex];
|
|
148
150
|
// Gesture events follow the display refresh rate (often 60/120Hz), but the
|
|
149
|
-
//
|
|
151
|
+
// composition has its own frame rate. Keep the latest pointer state for each
|
|
150
152
|
// output frame so recording cannot create visually indistinguishable piles.
|
|
151
153
|
if (lastSample?.time === sample.time) {
|
|
152
154
|
r.samples[lastIndex] = sample;
|
|
@@ -6,6 +6,7 @@ import { liveTime, usePlayerStore } from "../store/playerStore";
|
|
|
6
6
|
import { trackStudioEvent } from "../../utils/studioTelemetry";
|
|
7
7
|
import { Tooltip } from "../../components/ui";
|
|
8
8
|
import { useMountEffect } from "../../hooks/useMountEffect";
|
|
9
|
+
import { useLinkedClipPreferences } from "../../utils/linkedClipPreferences";
|
|
9
10
|
import { ShortcutsButton } from "./ShortcutsPanel";
|
|
10
11
|
import type { ShortcutSection } from "./studioShortcuts";
|
|
11
12
|
import { SpeedMenu } from "./SpeedMenu";
|
|
@@ -167,6 +168,8 @@ interface PlayerControlsProps {
|
|
|
167
168
|
shortcutSections?: readonly ShortcutSection[];
|
|
168
169
|
}
|
|
169
170
|
|
|
171
|
+
const compositionFps = () => useLinkedClipPreferences.getState().compositionFps;
|
|
172
|
+
|
|
170
173
|
export const PlayerControls = memo(function PlayerControls({
|
|
171
174
|
onTogglePlay,
|
|
172
175
|
onSeek,
|
|
@@ -202,7 +205,7 @@ export const PlayerControls = memo(function PlayerControls({
|
|
|
202
205
|
if (!timeDisplayRef.current) return;
|
|
203
206
|
const t = currentTimeRef.current;
|
|
204
207
|
timeDisplayRef.current.textContent =
|
|
205
|
-
timeDisplayMode === "frame" ? formatFrameTime(t, duration) : formatTime(t);
|
|
208
|
+
timeDisplayMode === "frame" ? formatFrameTime(t, duration, compositionFps()) : formatTime(t);
|
|
206
209
|
}, [duration, timeDisplayMode]);
|
|
207
210
|
|
|
208
211
|
useMountEffect(() => {
|
|
@@ -212,7 +215,7 @@ export const PlayerControls = memo(function PlayerControls({
|
|
|
212
215
|
const currentDuration = durationRef.current;
|
|
213
216
|
const text =
|
|
214
217
|
timeDisplayModeRef.current === "frame"
|
|
215
|
-
? formatFrameTime(time, currentDuration)
|
|
218
|
+
? formatFrameTime(time, currentDuration, compositionFps())
|
|
216
219
|
: formatTime(time);
|
|
217
220
|
if (timeDisplayRef.current.textContent !== text) timeDisplayRef.current.textContent = text;
|
|
218
221
|
};
|
|
@@ -3,6 +3,7 @@ import { formatTime, frameToSeconds } from "../lib/time";
|
|
|
3
3
|
import { Popover, Tooltip } from "../../components/ui";
|
|
4
4
|
import { flatActive, flatIdle } from "../../components/timelineToolbarStyles";
|
|
5
5
|
import { usePlayerStore } from "../store/playerStore";
|
|
6
|
+
import { useCompositionFps } from "../../utils/linkedClipPreferences";
|
|
6
7
|
import { DEFAULT_SHORTCUT_SECTIONS, type ShortcutSection } from "./studioShortcuts";
|
|
7
8
|
|
|
8
9
|
interface ShortcutsPanelProps {
|
|
@@ -31,6 +32,7 @@ export const ShortcutsPanel = memo(function ShortcutsPanel({
|
|
|
31
32
|
}: ShortcutsPanelProps) {
|
|
32
33
|
const [showShortcuts, setShowShortcuts] = useState(false);
|
|
33
34
|
const [jumpFrame, setJumpFrame] = useState("");
|
|
35
|
+
const compositionFps = useCompositionFps();
|
|
34
36
|
// Focus lands on the scrolling body, not the frame input, so keyboard users can scroll and read it.
|
|
35
37
|
const panelBodyRef = useRef<HTMLDivElement>(null);
|
|
36
38
|
|
|
@@ -38,8 +40,8 @@ export const ShortcutsPanel = memo(function ShortcutsPanel({
|
|
|
38
40
|
if (disabled) return;
|
|
39
41
|
const frame = Number.parseInt(jumpFrame, 10);
|
|
40
42
|
if (!Number.isFinite(frame) || duration <= 0) return;
|
|
41
|
-
onSeek(Math.min(duration, frameToSeconds(Math.max(0, frame))));
|
|
42
|
-
}, [disabled, duration, jumpFrame, onSeek]);
|
|
43
|
+
onSeek(Math.min(duration, frameToSeconds(Math.max(0, frame), compositionFps)));
|
|
44
|
+
}, [compositionFps, disabled, duration, jumpFrame, onSeek]);
|
|
43
45
|
|
|
44
46
|
const handleJumpSubmit = useCallback(
|
|
45
47
|
(e: React.FormEvent) => {
|
|
@@ -4,6 +4,7 @@ import React, { act } from "react";
|
|
|
4
4
|
import { createRoot } from "react-dom/client";
|
|
5
5
|
import { afterEach } from "vitest";
|
|
6
6
|
import { describe, it, expect, vi } from "vitest";
|
|
7
|
+
import { rulerTickText } from "./timelineRulerGeometry";
|
|
7
8
|
import {
|
|
8
9
|
Timeline,
|
|
9
10
|
formatTimelineTickLabel,
|
|
@@ -1367,3 +1368,14 @@ describe("resolveTimelineAssetDrop", () => {
|
|
|
1367
1368
|
).toEqual({ start: 1.18, track: 8 });
|
|
1368
1369
|
});
|
|
1369
1370
|
});
|
|
1371
|
+
|
|
1372
|
+
describe("rulerTickText", () => {
|
|
1373
|
+
it("counts frames at the rate the ticks were laid out at", () => {
|
|
1374
|
+
expect(rulerTickText(2, 25, 10, 1)).toBe(50);
|
|
1375
|
+
expect(rulerTickText(2, 30_000 / 1_001, 10, 1)).toBe(60);
|
|
1376
|
+
});
|
|
1377
|
+
|
|
1378
|
+
it("shows time when the ruler is not counting frames", () => {
|
|
1379
|
+
expect(rulerTickText(2, undefined, 10, 1)).toBe("00:02");
|
|
1380
|
+
});
|
|
1381
|
+
});
|
|
@@ -48,6 +48,7 @@ export type TimelineCanvasState = Omit<
|
|
|
48
48
|
totalH: number;
|
|
49
49
|
effectiveDuration: number;
|
|
50
50
|
majorTickInterval: number;
|
|
51
|
+
tickFrameRate: number | undefined;
|
|
51
52
|
rangeSelection: TimelineRangeSelection | null;
|
|
52
53
|
marqueeRect: Rect | null;
|
|
53
54
|
resizingClip: ResizingClipState | null;
|
|
@@ -2,9 +2,7 @@ import { memo, type RefObject } from "react";
|
|
|
2
2
|
import { useSettledScrollLeft } from "./useSettledScrollLeft";
|
|
3
3
|
import type { TimelineTheme } from "./timelineTheme";
|
|
4
4
|
import { RULER_H, getTimelineBeatEntries } from "./timelineLayout";
|
|
5
|
-
import {
|
|
6
|
-
import { usePlayerStore } from "../store/playerStore";
|
|
7
|
-
import { secondsToFrame } from "../lib/time";
|
|
5
|
+
import { rulerTickText } from "./timelineRulerGeometry";
|
|
8
6
|
import type { MusicBeatAnalysis } from "@hyperframes/core/beats";
|
|
9
7
|
import type { TimelineTimeRange } from "../lib/timelineClipIndex";
|
|
10
8
|
|
|
@@ -16,6 +14,7 @@ interface TimelineRulerProps {
|
|
|
16
14
|
totalH: number;
|
|
17
15
|
effectiveDuration: number;
|
|
18
16
|
majorTickInterval: number;
|
|
17
|
+
tickFrameRate?: number;
|
|
19
18
|
theme: TimelineTheme;
|
|
20
19
|
beatAnalysis?: MusicBeatAnalysis | null;
|
|
21
20
|
contentOrigin: number;
|
|
@@ -84,13 +83,13 @@ export const TimelineRuler = memo(function TimelineRuler({
|
|
|
84
83
|
totalH,
|
|
85
84
|
effectiveDuration,
|
|
86
85
|
majorTickInterval,
|
|
86
|
+
tickFrameRate,
|
|
87
87
|
theme,
|
|
88
88
|
beatAnalysis,
|
|
89
89
|
contentOrigin,
|
|
90
90
|
renderTimeRange,
|
|
91
91
|
scrollRef,
|
|
92
92
|
}: TimelineRulerProps) {
|
|
93
|
-
const timeDisplayMode = usePlayerStore((s) => s.timeDisplayMode);
|
|
94
93
|
const beatTimes = beatAnalysis?.beatTimes ?? [];
|
|
95
94
|
const beatStrengths = beatAnalysis?.beatStrengths ?? [];
|
|
96
95
|
const beatEntries = getTimelineBeatEntries(beatTimes, beatStrengths, renderTimeRange);
|
|
@@ -194,9 +193,7 @@ export const TimelineRuler = memo(function TimelineRuler({
|
|
|
194
193
|
fontSize: 10,
|
|
195
194
|
}}
|
|
196
195
|
>
|
|
197
|
-
{
|
|
198
|
-
? secondsToFrame(t)
|
|
199
|
-
: formatTimelineTickLabel(t, effectiveDuration, majorTickInterval)}
|
|
196
|
+
{rulerTickText(t, tickFrameRate, effectiveDuration, majorTickInterval)}
|
|
200
197
|
</span>
|
|
201
198
|
<div className="w-px" style={{ height: RULER_H, background: theme.tickMajor }} />
|
|
202
199
|
</div>
|
|
@@ -13,6 +13,7 @@ export function TimelineRulerPart() {
|
|
|
13
13
|
totalH={props.totalH}
|
|
14
14
|
effectiveDuration={props.effectiveDuration}
|
|
15
15
|
majorTickInterval={props.majorTickInterval}
|
|
16
|
+
tickFrameRate={props.tickFrameRate}
|
|
16
17
|
theme={props.theme}
|
|
17
18
|
beatAnalysis={props.beatAnalysis}
|
|
18
19
|
contentOrigin={props.contentOrigin}
|
|
@@ -5,8 +5,10 @@ import {
|
|
|
5
5
|
computeResizePreview,
|
|
6
6
|
guideIfSaved,
|
|
7
7
|
getTimelineDragOverlayPosition,
|
|
8
|
+
trimPreviewTime,
|
|
8
9
|
type DragPreviewContext,
|
|
9
10
|
} from "./timelineClipDragPreview";
|
|
11
|
+
import { useLinkedClipPreferences } from "../../utils/linkedClipPreferences";
|
|
10
12
|
import type { DraggedClipState } from "./timelineClipDragTypes";
|
|
11
13
|
import {
|
|
12
14
|
commitDraggedClipMove,
|
|
@@ -937,3 +939,11 @@ describe("an audio clip stays inside its partner video", () => {
|
|
|
937
939
|
expect(trim("end", 50, ["v"]).previewDuration).toBe(58);
|
|
938
940
|
});
|
|
939
941
|
});
|
|
942
|
+
|
|
943
|
+
describe("trimPreviewTime", () => {
|
|
944
|
+
it.each([25, 60])("shows the last frame of the clip at %s fps", (fps) => {
|
|
945
|
+
useLinkedClipPreferences.getState().setCompositionFps(fps);
|
|
946
|
+
expect(trimPreviewTime("end", 1, 2)).toBeCloseTo(3 - 1 / fps, 9);
|
|
947
|
+
useLinkedClipPreferences.getState().setCompositionFps(30);
|
|
948
|
+
});
|
|
949
|
+
});
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
} from "./timelineGroupEditing";
|
|
28
28
|
import { groupMoveFloor, resolveGroupMovers } from "./timelineMultiDragPreview";
|
|
29
29
|
import type { DraggedClipState, ResizingClipState } from "./timelineClipDragTypes";
|
|
30
|
-
import {
|
|
30
|
+
import { useLinkedClipPreferences } from "../../utils/linkedClipPreferences";
|
|
31
31
|
import { heldAudioShiftRange, heldPartnerVideoBounds } from "./audioClipLink";
|
|
32
32
|
|
|
33
33
|
/** Snap-target builder closure supplied by the hook (closes over refs + store). */
|
|
@@ -306,12 +306,11 @@ export function guideIfSaved(
|
|
|
306
306
|
return off * pps < 1 ? target : null;
|
|
307
307
|
}
|
|
308
308
|
|
|
309
|
-
/** One frame: the last visible frame of a clip sits just before its end time. */
|
|
310
|
-
const TRIM_END_FRAME_LEAD_S = 1 / STUDIO_PREVIEW_FPS;
|
|
311
|
-
|
|
312
309
|
/** The composition time whose frame a trim shows: the edge being dragged. */
|
|
313
310
|
export function trimPreviewTime(edge: "start" | "end", start: number, duration: number): number {
|
|
314
|
-
|
|
311
|
+
// One frame back: the last visible frame of a clip sits just before its end time.
|
|
312
|
+
const frame = 1 / useLinkedClipPreferences.getState().compositionFps;
|
|
313
|
+
return edge === "start" ? start : Math.max(start, start + duration - frame);
|
|
315
314
|
}
|
|
316
315
|
|
|
317
316
|
export interface ResizePreviewContext {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { formatTime,
|
|
1
|
+
import { formatTime, secondsToFrame } from "../lib/time";
|
|
2
2
|
import type { TimelineTimeDisplayMode } from "../../utils/studioUiPreferences";
|
|
3
3
|
import type { TimelineTimeRange } from "../lib/timelineClipIndex";
|
|
4
4
|
|
|
@@ -94,8 +94,8 @@ function tickSpacing(duration: number, pixelsPerSecond?: number, frameRate?: num
|
|
|
94
94
|
return { majorInterval, subdivisions };
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
export function rulerFrameRate(mode: TimelineTimeDisplayMode): number | undefined {
|
|
98
|
-
return mode === "frame" ?
|
|
97
|
+
export function rulerFrameRate(mode: TimelineTimeDisplayMode, fps: number): number | undefined {
|
|
98
|
+
return mode === "frame" ? fps : undefined;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
/** Seconds between neighbouring ruler lines (minor ticks when drawn, else major): the snap grid. */
|
|
@@ -161,3 +161,14 @@ export function formatTimelineTickLabel(
|
|
|
161
161
|
}
|
|
162
162
|
return formatTime(safeTime);
|
|
163
163
|
}
|
|
164
|
+
|
|
165
|
+
export function rulerTickText(
|
|
166
|
+
time: number,
|
|
167
|
+
frameRate: number | undefined,
|
|
168
|
+
duration: number,
|
|
169
|
+
majorInterval: number,
|
|
170
|
+
): string | number {
|
|
171
|
+
return frameRate
|
|
172
|
+
? secondsToFrame(time, frameRate)
|
|
173
|
+
: formatTimelineTickLabel(time, duration, majorInterval);
|
|
174
|
+
}
|