@hyperframes/studio 0.9.61 → 0.9.64
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-Cm0hYGm2.js → hyperframes-player-mSF_GvRs.js} +1 -1
- package/dist/assets/{index-BGrNWeLK.js → index-CVmmHGol.js} +168 -168
- package/dist/assets/{index-REqr_dLu.js → index-DN167Uqf.js} +1 -1
- package/dist/assets/{pausedVideoDecoder-DqLDSq8J.js → pausedVideoDecoder-C8rhpGPx.js} +1 -1
- package/dist/{chunk-UM4CLD4M.js → chunk-OJLNM6V5.js} +1 -1
- package/dist/{chunk-3KCEIESB.js → chunk-VDDEXNVX.js} +11 -1
- package/dist/{chunk-OOGQ5KCC.js → chunk-YQ3ZAXXY.js} +8 -27
- package/dist/{domEditingLayers-IHYA42AJ.js → domEditingLayers-YYHWRNF4.js} +2 -2
- package/dist/index.html +1 -1
- package/dist/index.js +1163 -1000
- package/dist/player.js +2 -2
- package/package.json +8 -8
- package/src/components/nle/AudioMeterStrip.tsx +63 -2
- package/src/components/nle/audioSealedPreview.test.ts +254 -0
- package/src/components/nle/zLaneGesture.test.ts +67 -0
- package/src/components/nle/zLaneGesture.ts +4 -0
- package/src/hooks/timelineAudioGroupCreate.ts +57 -7
- package/src/hooks/timelineAudioGroupVolume.ts +110 -34
- package/src/main.tsx +14 -11
- package/src/player/components/Timeline.newTrack.test.tsx +106 -0
- package/src/player/components/TimelineLanes.tsx +4 -2
- package/src/player/components/TimelineTrackHeader.tsx +12 -4
- package/src/player/components/clipMenuAudioItems.tsx +46 -3
- package/src/player/components/timelineRowKeys.test.ts +28 -0
- package/src/player/components/timelineRowKeys.ts +27 -0
- package/src/player/hooks/useTimelineSyncCallbacks.sealed.test.ts +98 -0
- package/src/player/hooks/useTimelineSyncCallbacks.ts +23 -8
- package/src/player/lib/playbackTypes.ts +0 -2
- package/src/player/lib/previewChannel.ts +10 -0
- package/src/player/lib/timelineElementHelpers.ts +7 -42
- package/src/player/lib/timelineIframeHelpers.test.ts +18 -137
- package/src/player/lib/timelineIframeHelpers.ts +15 -94
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback } from "react";
|
|
1
|
+
import { useCallback, useState } from "react";
|
|
2
2
|
import {
|
|
3
3
|
failedTimelineSave,
|
|
4
4
|
projectForTimelineSave,
|
|
@@ -9,6 +9,11 @@ import { HF_AUDIO_AUTOMATION_ATTR } from "@hyperframes/core/audio-automation";
|
|
|
9
9
|
import { usePlayerStore } from "../player";
|
|
10
10
|
import type { TimelineElementPatch } from "../player/store/timelineElement";
|
|
11
11
|
import { invalidateGroupInfoCache } from "../player/lib/timelineGroupInfo";
|
|
12
|
+
import {
|
|
13
|
+
previewDocumentCopy,
|
|
14
|
+
previewFrameOpaque,
|
|
15
|
+
previewRequest,
|
|
16
|
+
} from "../player/lib/previewChannel";
|
|
12
17
|
import {
|
|
13
18
|
buildPatchTarget,
|
|
14
19
|
persistElementAttribute,
|
|
@@ -21,6 +26,35 @@ import type {
|
|
|
21
26
|
UseTimelineElementVisibilityEditingInput,
|
|
22
27
|
} from "./timelineTrackVisibility";
|
|
23
28
|
|
|
29
|
+
type SealedLane = { busy: boolean; next: { value: string | null } | null };
|
|
30
|
+
const sealedLanes = new WeakMap<HTMLIFrameElement, Map<string, SealedLane>>();
|
|
31
|
+
|
|
32
|
+
/** A drag writes per frame: one write in flight per group attribute, and only the newest waits. */
|
|
33
|
+
function writeSealedGroupAttribute(
|
|
34
|
+
iframe: HTMLIFrameElement,
|
|
35
|
+
groupId: string,
|
|
36
|
+
attr: string,
|
|
37
|
+
value: string | null,
|
|
38
|
+
): void {
|
|
39
|
+
const lanes = sealedLanes.get(iframe) ?? new Map<string, SealedLane>();
|
|
40
|
+
sealedLanes.set(iframe, lanes);
|
|
41
|
+
const key = audioGroupAttributeLiveKey(groupId, attr);
|
|
42
|
+
const lane = lanes.get(key) ?? { busy: false, next: null };
|
|
43
|
+
lanes.set(key, lane);
|
|
44
|
+
lane.next = { value };
|
|
45
|
+
const pump = () => {
|
|
46
|
+
if (lane.busy || !lane.next) return;
|
|
47
|
+
const params = { id: groupId, attr, value: lane.next.value };
|
|
48
|
+
lane.next = null;
|
|
49
|
+
lane.busy = true;
|
|
50
|
+
void previewRequest(iframe, "set-audio-group-attribute", params).finally(() => {
|
|
51
|
+
lane.busy = false;
|
|
52
|
+
pump();
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
pump();
|
|
56
|
+
}
|
|
57
|
+
|
|
24
58
|
/** Direct DOM write on the group element for the gesture in progress — no
|
|
25
59
|
* file write, no history entry (mirrors FxParamRow's live/commit split). */
|
|
26
60
|
function patchLiveGroupAttribute(
|
|
@@ -29,6 +63,10 @@ function patchLiveGroupAttribute(
|
|
|
29
63
|
attr: string,
|
|
30
64
|
value: string | null,
|
|
31
65
|
): void {
|
|
66
|
+
if (iframe && previewFrameOpaque(iframe)) {
|
|
67
|
+
writeSealedGroupAttribute(iframe, groupId, attr, value);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
32
70
|
const target = iframe?.contentDocument?.getElementById(groupId);
|
|
33
71
|
if (!target) return;
|
|
34
72
|
if (value === null) target.removeAttribute(attr);
|
|
@@ -146,12 +184,9 @@ export function resolveGroupSourceFile(groupEl: Element | null): string | undefi
|
|
|
146
184
|
|
|
147
185
|
interface SetAudioGroupAttributeInput {
|
|
148
186
|
projectId: string;
|
|
149
|
-
|
|
150
|
-
groupId: string;
|
|
151
|
-
attr: string;
|
|
187
|
+
source: LiveLaneSource;
|
|
152
188
|
value: string | null;
|
|
153
189
|
label: string;
|
|
154
|
-
previewIframe: HTMLIFrameElement | null;
|
|
155
190
|
patchLive: (value: string | null) => void;
|
|
156
191
|
onFileRead: (value: string | null) => void;
|
|
157
192
|
writeProjectFile: (path: string, content: string) => Promise<void>;
|
|
@@ -165,36 +200,31 @@ interface SetAudioGroupAttributeInput {
|
|
|
165
200
|
* `createAudioGroupAndAssignMembers`'s save shape but for a single element
|
|
166
201
|
* and attribute rather than a member-assignment sweep.
|
|
167
202
|
*/
|
|
168
|
-
function groupSaveTarget(
|
|
169
|
-
previewIframe: HTMLIFrameElement | null,
|
|
170
|
-
groupId: string,
|
|
171
|
-
activeCompPath: string | null,
|
|
172
|
-
) {
|
|
173
|
-
const groupEl = previewIframe?.contentDocument?.getElementById(groupId) ?? null;
|
|
203
|
+
function groupSaveTarget(groupEl: Element | null, groupId: string, activeCompPath: string | null) {
|
|
174
204
|
return {
|
|
175
205
|
targetPath: resolveGroupSourceFile(groupEl) || activeCompPath || "index.html",
|
|
176
206
|
patchTarget: buildPatchTarget({ domId: groupId }),
|
|
177
207
|
};
|
|
178
208
|
}
|
|
179
209
|
|
|
210
|
+
const liveGroupElement = (previewIframe: HTMLIFrameElement | null, groupId: string) =>
|
|
211
|
+
previewIframe?.contentDocument?.getElementById(groupId) ?? null;
|
|
212
|
+
|
|
180
213
|
function groupLiveSource(
|
|
181
|
-
|
|
214
|
+
groupEl: Element | null,
|
|
182
215
|
groupId: string,
|
|
183
216
|
activeCompPath: string | null,
|
|
184
217
|
attr: string,
|
|
185
218
|
): LiveLaneSource {
|
|
186
|
-
const { targetPath, patchTarget } = groupSaveTarget(
|
|
219
|
+
const { targetPath, patchTarget } = groupSaveTarget(groupEl, groupId, activeCompPath);
|
|
187
220
|
return { path: targetPath, target: patchTarget, attr };
|
|
188
221
|
}
|
|
189
222
|
|
|
190
223
|
async function setAudioGroupAttribute({
|
|
191
224
|
projectId,
|
|
192
|
-
|
|
193
|
-
groupId,
|
|
194
|
-
attr,
|
|
225
|
+
source,
|
|
195
226
|
value,
|
|
196
227
|
label,
|
|
197
|
-
previewIframe,
|
|
198
228
|
patchLive,
|
|
199
229
|
onFileRead,
|
|
200
230
|
writeProjectFile,
|
|
@@ -209,7 +239,7 @@ async function setAudioGroupAttribute({
|
|
|
209
239
|
// means `readTagSnippetByTarget` finds nothing and every mute, fader move and
|
|
210
240
|
// FX preset throws "Unable to patch element in index.html". Every sibling
|
|
211
241
|
// timeline writer already routes `element.sourceFile || activeCompPath`.
|
|
212
|
-
const { targetPath, patchTarget } =
|
|
242
|
+
const { path: targetPath, target: patchTarget, attr } = source;
|
|
213
243
|
if (!patchTarget) return null;
|
|
214
244
|
|
|
215
245
|
return persistElementAttribute({
|
|
@@ -255,22 +285,62 @@ export function useSetAudioGroupAttribute({
|
|
|
255
285
|
restoreLive: (restore: LiveLaneRestore) => void;
|
|
256
286
|
} {
|
|
257
287
|
const liveLanes = useLiveLanes(projectIdRef, activeCompPath);
|
|
288
|
+
// A sealed preview's gesture reads the group once, off a copy of the frame, before its first write.
|
|
289
|
+
const [sealedReads] = useState(() => new Map<string, Promise<Document | null>>());
|
|
290
|
+
const openSealedLane = useCallback(
|
|
291
|
+
(iframe: HTMLIFrameElement, groupId: string, attr: string) => {
|
|
292
|
+
const key = audioGroupAttributeLiveKey(groupId, attr);
|
|
293
|
+
const open = sealedReads.get(key);
|
|
294
|
+
if (open) return open;
|
|
295
|
+
const read = previewDocumentCopy(iframe);
|
|
296
|
+
sealedReads.set(key, read);
|
|
297
|
+
void read.then((doc) => {
|
|
298
|
+
if (sealedReads.get(key) !== read) return;
|
|
299
|
+
const groupEl = doc?.getElementById(groupId) ?? null;
|
|
300
|
+
liveLanes.preview(
|
|
301
|
+
key,
|
|
302
|
+
() => groupEl?.getAttribute(attr) ?? null,
|
|
303
|
+
groupLiveSource(groupEl, groupId, activeCompPath, attr),
|
|
304
|
+
);
|
|
305
|
+
});
|
|
306
|
+
return read;
|
|
307
|
+
},
|
|
308
|
+
[sealedReads, liveLanes, activeCompPath],
|
|
309
|
+
);
|
|
310
|
+
const sealedGroupElement = useCallback(
|
|
311
|
+
async (iframe: HTMLIFrameElement, groupId: string, attr: string) => {
|
|
312
|
+
const key = audioGroupAttributeLiveKey(groupId, attr);
|
|
313
|
+
const read = sealedReads.get(key) ?? previewDocumentCopy(iframe);
|
|
314
|
+
const doc = await read;
|
|
315
|
+
if (sealedReads.get(key) === read) sealedReads.delete(key);
|
|
316
|
+
return doc?.getElementById(groupId) ?? null;
|
|
317
|
+
},
|
|
318
|
+
[sealedReads],
|
|
319
|
+
);
|
|
258
320
|
const setLive = useCallback(
|
|
259
321
|
(groupId: string, attr: string, value: string | null) => {
|
|
260
322
|
const key = audioGroupAttributeLiveKey(groupId, attr);
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
() =>
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
323
|
+
const iframe = previewIframeRef.current;
|
|
324
|
+
if (iframe && previewFrameOpaque(iframe)) {
|
|
325
|
+
const read = openSealedLane(iframe, groupId, attr);
|
|
326
|
+
void read.then(() => {
|
|
327
|
+
if (sealedReads.get(key) === read) patchLiveGroupAttribute(iframe, groupId, attr, value);
|
|
328
|
+
});
|
|
329
|
+
} else {
|
|
330
|
+
const target = liveGroupElement(iframe, groupId);
|
|
331
|
+
liveLanes.preview(
|
|
332
|
+
key,
|
|
333
|
+
() => target?.getAttribute(attr) ?? null,
|
|
334
|
+
groupLiveSource(target, groupId, activeCompPath, attr),
|
|
335
|
+
);
|
|
336
|
+
patchLiveGroupAttribute(iframe, groupId, attr, value);
|
|
337
|
+
}
|
|
268
338
|
// Live too, not just on commit: a fader drag is `setLive` per frame and
|
|
269
339
|
// `setQuiet` once on release, so without this the strip's own readout
|
|
270
340
|
// fights the drag.
|
|
271
341
|
syncStoredGroupAttribute(groupId, attr, value);
|
|
272
342
|
},
|
|
273
|
-
[liveLanes, previewIframeRef, activeCompPath],
|
|
343
|
+
[liveLanes, previewIframeRef, activeCompPath, openSealedLane, sealedReads],
|
|
274
344
|
);
|
|
275
345
|
const laneApply = useCallback(
|
|
276
346
|
(groupId: string, attr: string) => ({
|
|
@@ -286,9 +356,12 @@ export function useSetAudioGroupAttribute({
|
|
|
286
356
|
[liveLanes, laneApply],
|
|
287
357
|
);
|
|
288
358
|
const revertLive = useCallback(
|
|
289
|
-
(groupId: string, attr: string) =>
|
|
290
|
-
|
|
291
|
-
|
|
359
|
+
(groupId: string, attr: string) => {
|
|
360
|
+
const key = audioGroupAttributeLiveKey(groupId, attr);
|
|
361
|
+
sealedReads.delete(key);
|
|
362
|
+
liveLanes.revert(key, laneApply(groupId, attr));
|
|
363
|
+
},
|
|
364
|
+
[liveLanes, laneApply, sealedReads],
|
|
292
365
|
);
|
|
293
366
|
const setQuiet = useCallback(
|
|
294
367
|
async (
|
|
@@ -301,7 +374,12 @@ export function useSetAudioGroupAttribute({
|
|
|
301
374
|
const pid = projectForTimelineSave(isRecordingRef?.current, project, showToast);
|
|
302
375
|
// Settles on what the file holds, so overlapping saves that fail cannot leave
|
|
303
376
|
// the preview or the store on a value that never landed.
|
|
304
|
-
const
|
|
377
|
+
const iframe = previewIframeRef.current;
|
|
378
|
+
const groupEl =
|
|
379
|
+
iframe && previewFrameOpaque(iframe)
|
|
380
|
+
? await sealedGroupElement(iframe, groupId, attr)
|
|
381
|
+
: liveGroupElement(iframe, groupId);
|
|
382
|
+
const source = groupLiveSource(groupEl, groupId, activeCompPath, attr);
|
|
305
383
|
const live = claimLive(groupId, attr, source);
|
|
306
384
|
const unsaved = async (outcome: TimelineEditOutcome): Promise<TimelineEditOutcome> => {
|
|
307
385
|
live.settle(
|
|
@@ -313,12 +391,9 @@ export function useSetAudioGroupAttribute({
|
|
|
313
391
|
try {
|
|
314
392
|
const written = await setAudioGroupAttribute({
|
|
315
393
|
projectId: pid,
|
|
316
|
-
|
|
317
|
-
groupId,
|
|
318
|
-
attr,
|
|
394
|
+
source,
|
|
319
395
|
value,
|
|
320
396
|
label,
|
|
321
|
-
previewIframe: previewIframeRef.current,
|
|
322
397
|
patchLive: live.preview,
|
|
323
398
|
onFileRead: live.read,
|
|
324
399
|
writeProjectFile,
|
|
@@ -337,6 +412,7 @@ export function useSetAudioGroupAttribute({
|
|
|
337
412
|
},
|
|
338
413
|
[
|
|
339
414
|
claimLive,
|
|
415
|
+
sealedGroupElement,
|
|
340
416
|
activeCompPath,
|
|
341
417
|
previewIframeRef,
|
|
342
418
|
writeProjectFile,
|
package/src/main.tsx
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
} from "./utils/rejectionTelemetry";
|
|
14
14
|
import { prefetchPreviewForHash } from "./utils/previewPrefetch";
|
|
15
15
|
import { bindThumbnailPageLifecycle } from "./player/lib/thumbnailPageLifecycle";
|
|
16
|
+
import { dropServiceWorkers } from "@hyperframes/core/studio-preview-mark";
|
|
16
17
|
import "./styles/studio.css";
|
|
17
18
|
|
|
18
19
|
const unbindThumbnailPageLifecycle = bindThumbnailPageLifecycle(window, document);
|
|
@@ -110,16 +111,18 @@ window.addEventListener("unhandledrejection", (event) => {
|
|
|
110
111
|
trackStudioEvent("unhandled_promise_rejection", props);
|
|
111
112
|
});
|
|
112
113
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
void dropServiceWorkers().then(() =>
|
|
115
|
+
createRoot(document.getElementById("root")!).render(
|
|
116
|
+
<StrictMode>
|
|
117
|
+
{/* One icon size and weight for the whole app, taken from the theme file.
|
|
116
118
|
Icons that pass their own size or weight still win. */}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
119
|
+
<IconContext.Provider value={readIconTokens()}>
|
|
120
|
+
<StudioErrorBoundary>
|
|
121
|
+
<ShowThemeToggle.Provider value>
|
|
122
|
+
<StudioApp />
|
|
123
|
+
</ShowThemeToggle.Provider>
|
|
124
|
+
</StudioErrorBoundary>
|
|
125
|
+
</IconContext.Provider>
|
|
126
|
+
</StrictMode>,
|
|
127
|
+
),
|
|
125
128
|
);
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import React, { act } from "react";
|
|
4
|
+
import { createRoot } from "react-dom/client";
|
|
5
|
+
import { afterAll, beforeAll, expect, it } from "vitest";
|
|
6
|
+
import type { TimelineElement } from "../store/playerStore";
|
|
7
|
+
import { normalizeToZones } from "./timelineZones";
|
|
8
|
+
|
|
9
|
+
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
10
|
+
|
|
11
|
+
class MockResizeObserver {
|
|
12
|
+
constructor(private readonly callback: ResizeObserverCallback) {}
|
|
13
|
+
observe(target: Element) {
|
|
14
|
+
this.callback(
|
|
15
|
+
[{ target, borderBoxSize: [{ inlineSize: 900, blockSize: 400 }] } as never],
|
|
16
|
+
this as unknown as ResizeObserver,
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
unobserve() {}
|
|
20
|
+
disconnect() {}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const originalResizeObserver = globalThis.ResizeObserver;
|
|
24
|
+
const sizes = ["clientWidth", "clientHeight"] as const;
|
|
25
|
+
const originals = sizes.map((name) => Object.getOwnPropertyDescriptor(HTMLElement.prototype, name));
|
|
26
|
+
|
|
27
|
+
beforeAll(() => {
|
|
28
|
+
globalThis.ResizeObserver = MockResizeObserver as unknown as typeof ResizeObserver;
|
|
29
|
+
Object.defineProperty(HTMLElement.prototype, "clientWidth", {
|
|
30
|
+
configurable: true,
|
|
31
|
+
get: () => 900,
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(HTMLElement.prototype, "clientHeight", {
|
|
34
|
+
configurable: true,
|
|
35
|
+
get: () => 400,
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
afterAll(() => {
|
|
40
|
+
globalThis.ResizeObserver = originalResizeObserver;
|
|
41
|
+
sizes.forEach((name, i) => {
|
|
42
|
+
const original = originals[i];
|
|
43
|
+
if (original) Object.defineProperty(HTMLElement.prototype, name, original);
|
|
44
|
+
});
|
|
45
|
+
document.body.innerHTML = "";
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const clip = (id: string, track: number, start = 0): TimelineElement => ({
|
|
49
|
+
id,
|
|
50
|
+
label: id,
|
|
51
|
+
tag: "div",
|
|
52
|
+
start,
|
|
53
|
+
duration: 5,
|
|
54
|
+
track,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
async function settleUntil(ready: () => boolean) {
|
|
58
|
+
for (let i = 0; i < 60 && !ready(); i++)
|
|
59
|
+
await act(async () => new Promise<void>((done) => requestAnimationFrame(() => done())));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Mounts the timeline on `first`, then shows `next`; returns which of `kept` got a new DOM node. */
|
|
63
|
+
async function remountedAfter(first: TimelineElement[], next: TimelineElement[], kept: string[]) {
|
|
64
|
+
const [{ Timeline }, { usePlayerStore }] = await Promise.all([
|
|
65
|
+
import("./Timeline"),
|
|
66
|
+
import("../store/playerStore"),
|
|
67
|
+
]);
|
|
68
|
+
usePlayerStore.setState({ duration: 60, timelineReady: true, elements: normalizeToZones(first) });
|
|
69
|
+
const host = document.body.appendChild(document.createElement("div"));
|
|
70
|
+
const root = createRoot(host);
|
|
71
|
+
const node = (id: string) => host.querySelector<HTMLElement>(`[data-el-id="${id}"]`);
|
|
72
|
+
try {
|
|
73
|
+
await act(async () => root.render(React.createElement(Timeline)));
|
|
74
|
+
await settleUntil(() => kept.every((id) => node(id)));
|
|
75
|
+
const before = new Map(kept.map((id) => [id, node(id)]));
|
|
76
|
+
expect([...before.values()].every(Boolean)).toBe(true);
|
|
77
|
+
await act(async () => usePlayerStore.setState({ elements: normalizeToZones(next) }));
|
|
78
|
+
await settleUntil(() => next.every(({ id }) => node(id)));
|
|
79
|
+
return kept.filter((id) => node(id) !== before.get(id));
|
|
80
|
+
} finally {
|
|
81
|
+
act(() => root.unmount());
|
|
82
|
+
usePlayerStore.getState().reset();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// An agent edit that adds a track re-zones every lane below it (normalizeToZones), shifting each clip's display
|
|
87
|
+
// track by one. On a long film that remounted the whole timeline in one frame. The 30 s budget matches
|
|
88
|
+
// Timeline.virtualization.test.
|
|
89
|
+
it(
|
|
90
|
+
"adding a track above the others keeps every existing clip mounted",
|
|
91
|
+
{ timeout: 30_000 },
|
|
92
|
+
async () => {
|
|
93
|
+
const ids = ["a", "b", "c", "d", "e"];
|
|
94
|
+
const authored = ids.map((id, i) => clip(id, i + 1));
|
|
95
|
+
expect(await remountedAfter(authored, [clip("new", 0), ...authored], ids)).toEqual([]);
|
|
96
|
+
},
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
it(
|
|
100
|
+
"deleting a track's first clip keeps the rest of the timeline mounted",
|
|
101
|
+
{ timeout: 30_000 },
|
|
102
|
+
async () => {
|
|
103
|
+
const first = [clip("x1", 0, 0), clip("x2", 0, 10), clip("y", 1), clip("z", 2)];
|
|
104
|
+
expect(await remountedAfter(first, first.slice(1), ["x2", "y", "z"])).toEqual([]);
|
|
105
|
+
},
|
|
106
|
+
);
|
|
@@ -31,6 +31,7 @@ import { TimelineTrackRow } from "./TimelineTrackRow";
|
|
|
31
31
|
import { isTimelineClipActive } from "./useTimelineActiveClips";
|
|
32
32
|
import { queryTimelineClipIndex } from "../lib/timelineClipIndex";
|
|
33
33
|
import { getTimelineElementIdentity } from "../lib/timelineElementHelpers";
|
|
34
|
+
import { timelineRows } from "./timelineRowKeys";
|
|
34
35
|
import { timelineClipFocusId } from "./timelineNavigationIdentity";
|
|
35
36
|
import { useTimelineKeyboardActor } from "./useTimelineKeyboardActor";
|
|
36
37
|
import { TimelineTransitionOverlays } from "./TimelineTransitionOverlays";
|
|
@@ -145,6 +146,7 @@ export function TimelineLanes({
|
|
|
145
146
|
onDrillDown,
|
|
146
147
|
});
|
|
147
148
|
const clipActions = useRef<TimelineLaneClipActions>(null!);
|
|
149
|
+
const rows = timelineRows(tracks);
|
|
148
150
|
clipActions.current = {
|
|
149
151
|
gestures: {
|
|
150
152
|
pps,
|
|
@@ -218,7 +220,7 @@ export function TimelineLanes({
|
|
|
218
220
|
const logicalRow = trackLogicalRows[0];
|
|
219
221
|
if (!logicalRow) return null;
|
|
220
222
|
const rowHeight = rowGeometry.getRowHeight(row);
|
|
221
|
-
const els =
|
|
223
|
+
const els = rows.clips(trackNum);
|
|
222
224
|
const renderElements = rowsVirtualized
|
|
223
225
|
? queryTimelineClipIndex(
|
|
224
226
|
clipIndex,
|
|
@@ -302,7 +304,7 @@ export function TimelineLanes({
|
|
|
302
304
|
: undefined;
|
|
303
305
|
return (
|
|
304
306
|
<TimelineTrackRow
|
|
305
|
-
key={
|
|
307
|
+
key={rows.reactKey(trackNum)}
|
|
306
308
|
index={row}
|
|
307
309
|
rowKey={rowKey}
|
|
308
310
|
logicalRow={logicalRow}
|
|
@@ -12,6 +12,7 @@ import { useTimelineEditContextOptional } from "../../contexts/TimelineEditConte
|
|
|
12
12
|
import { useDomEditActionsContextOptional } from "../../contexts/DomEditContext";
|
|
13
13
|
import { mintGroupId } from "../../components/editor/useFxCarveGrouping";
|
|
14
14
|
import { runtimeAudioId } from "../lib/timelineElementHelpers";
|
|
15
|
+
import { previewDocumentCopy, previewFrameOpaque } from "../lib/previewChannel";
|
|
15
16
|
import { isAudioOnlyTrack } from "../../utils/timelineInspector";
|
|
16
17
|
import { TimelineFxButton } from "./TimelineFxButton";
|
|
17
18
|
import { getTimelinePropertyLanes } from "./TimelinePropertyLanes";
|
|
@@ -262,10 +263,17 @@ export function TimelineTrackHeader({
|
|
|
262
263
|
: null;
|
|
263
264
|
const canGroupWholeTrack = (allGroupableClipIds?.length ?? 0) >= 2;
|
|
264
265
|
const groupUngroupedClips = (label: string) => {
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
if (!
|
|
268
|
-
|
|
266
|
+
const iframe = domEditActions?.previewIframeRef.current;
|
|
267
|
+
const ids = allGroupableClipIds;
|
|
268
|
+
if (!onGroupClips || !ids || ids.length < 2) return;
|
|
269
|
+
if (iframe && previewFrameOpaque(iframe)) {
|
|
270
|
+
void previewDocumentCopy(iframe).then(
|
|
271
|
+
(doc) => doc && onGroupClips(ids, mintGroupId(doc), label),
|
|
272
|
+
);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
const doc = iframe?.contentDocument;
|
|
276
|
+
if (doc) void onGroupClips(ids, mintGroupId(doc), label);
|
|
269
277
|
};
|
|
270
278
|
|
|
271
279
|
return (
|
|
@@ -1,11 +1,21 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { HF_AUDIO_GROUP_ATTR } from "@hyperframes/core/audio-groups";
|
|
1
3
|
import type { TimelineElement } from "../store/timelineElement";
|
|
4
|
+
import type { TimelineEditCallbacks } from "./timelineCallbacks";
|
|
2
5
|
import { useTimelineEditContextOptional } from "../../contexts/TimelineEditContext";
|
|
3
6
|
import { useStudioShellContextOptional } from "../../contexts/StudioContext";
|
|
4
7
|
import { usePlayerStore } from "../store/playerStore";
|
|
5
8
|
import { useLivePreviewIframe } from "../store/previewIframeStore";
|
|
6
9
|
import { clipHasSound, throwUnlessSaved, TimelineSaveError } from "./clipMenuNormalize";
|
|
7
10
|
import { openAudioGainDialog } from "./audioGainDialogStore";
|
|
8
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
offersDuck,
|
|
13
|
+
readBedCarve,
|
|
14
|
+
setDuckUnderVoice,
|
|
15
|
+
type DuckOutcome,
|
|
16
|
+
type GroupClips,
|
|
17
|
+
} from "./clipMenuDuck";
|
|
18
|
+
import { previewDocumentCopy, previewFrameOpaque } from "../lib/previewChannel";
|
|
9
19
|
|
|
10
20
|
const ITEM_CLASS =
|
|
11
21
|
"w-full flex items-center justify-between px-3 py-1.5 text-xs text-left outline-hidden text-neutral-300 hover:bg-neutral-800 focus-visible:bg-neutral-800 cursor-pointer";
|
|
@@ -17,6 +27,38 @@ const DUCK_TOAST: Record<DuckOutcome, string> = {
|
|
|
17
27
|
aborted: "Could not group the voices to duck under.",
|
|
18
28
|
};
|
|
19
29
|
|
|
30
|
+
type Copy = { iframe: HTMLIFrameElement; doc: Document | null };
|
|
31
|
+
|
|
32
|
+
function usePreviewDocument(iframe: HTMLIFrameElement | null): {
|
|
33
|
+
doc: Document | null;
|
|
34
|
+
copy: Document | null;
|
|
35
|
+
} {
|
|
36
|
+
const sealed = iframe !== null && previewFrameOpaque(iframe);
|
|
37
|
+
const [read, setRead] = useState<Copy | null>(null);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (!iframe || !sealed) return;
|
|
40
|
+
let current = true;
|
|
41
|
+
void previewDocumentCopy(iframe).then((doc) => current && setRead({ iframe, doc }));
|
|
42
|
+
return () => {
|
|
43
|
+
current = false;
|
|
44
|
+
};
|
|
45
|
+
}, [iframe, sealed]);
|
|
46
|
+
if (!sealed) return { doc: iframe?.contentDocument ?? null, copy: null };
|
|
47
|
+
const copy = read?.iframe === iframe ? read.doc : null;
|
|
48
|
+
return { doc: copy, copy };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function voiceGrouper(
|
|
52
|
+
onGroupClips: NonNullable<TimelineEditCallbacks["onGroupClips"]>,
|
|
53
|
+
copy: Document | null,
|
|
54
|
+
): GroupClips {
|
|
55
|
+
if (!copy) return (ids, groupId) => onGroupClips(ids, groupId, "Voice");
|
|
56
|
+
return async (ids, groupId) => {
|
|
57
|
+
await onGroupClips(ids, groupId, "Voice");
|
|
58
|
+
for (const id of ids) copy.getElementById(id)?.setAttribute(HF_AUDIO_GROUP_ATTR, groupId);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
20
62
|
/** Audio Gain… (opens the G dialog) or Duck under voice (toggle), placed separately in the sound group. */
|
|
21
63
|
export function ClipMenuAudioItems({
|
|
22
64
|
part,
|
|
@@ -33,7 +75,8 @@ export function ClipMenuAudioItems({
|
|
|
33
75
|
const sessionProjectId = usePlayerStore((s) => s.timelineProjectId);
|
|
34
76
|
const projectId = shell?.projectId ?? sessionProjectId;
|
|
35
77
|
const showToast = shell?.showToast ?? onNotice;
|
|
36
|
-
const
|
|
78
|
+
const iframe = shell?.previewIframeRef.current ?? liveIframe;
|
|
79
|
+
const { doc, copy } = usePreviewDocument(iframe);
|
|
37
80
|
const bed = doc?.getElementById(element.domId ?? element.id) ?? null;
|
|
38
81
|
const ducked = bed ? readBedCarve(bed)?.enabled === true : false;
|
|
39
82
|
if (!clipHasSound(element) || !projectId || !showToast || !onSetElementAttributeQuiet) {
|
|
@@ -52,7 +95,7 @@ export function ClipMenuAudioItems({
|
|
|
52
95
|
await onSetElementAttributeQuiet(element, attr, value, "Duck under voice"),
|
|
53
96
|
);
|
|
54
97
|
},
|
|
55
|
-
onGroupClips
|
|
98
|
+
onGroupClips && voiceGrouper(onGroupClips, copy),
|
|
56
99
|
).catch((error: unknown): DuckOutcome | TimelineSaveError =>
|
|
57
100
|
error instanceof TimelineSaveError ? error : "aborted",
|
|
58
101
|
);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { expect, it } from "vitest";
|
|
2
|
+
import type { TimelineElement } from "../store/playerStore";
|
|
3
|
+
import { timelineRows } from "./timelineRowKeys";
|
|
4
|
+
|
|
5
|
+
const el = (id: string, track: number, authoredTrack?: number, tag = "div"): TimelineElement => ({
|
|
6
|
+
id,
|
|
7
|
+
tag,
|
|
8
|
+
start: 0,
|
|
9
|
+
duration: 1,
|
|
10
|
+
track,
|
|
11
|
+
...(authoredTrack === undefined ? {} : { authoredTrack }),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("keys rows by zone and authored track, numbering repeats and empty lanes apart, and finds each row's clips", () => {
|
|
15
|
+
const rows = timelineRows([
|
|
16
|
+
[0, [el("a", 0, 3)]],
|
|
17
|
+
[1, [el("b", 1, 3)]],
|
|
18
|
+
[2, [el("c", 2, 3, "audio")]],
|
|
19
|
+
[3, []],
|
|
20
|
+
]);
|
|
21
|
+
expect([0, 1, 2, 3, 9].map(rows.reactKey)).toEqual([
|
|
22
|
+
"visual:3",
|
|
23
|
+
"visual:3#1",
|
|
24
|
+
"audio:3",
|
|
25
|
+
"lane:3",
|
|
26
|
+
"lane:9",
|
|
27
|
+
]);
|
|
28
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { TimelineElement } from "../store/playerStore";
|
|
2
|
+
import { resolveElementTrack } from "../../utils/studioHelpers";
|
|
3
|
+
import { classifyZone } from "./timelineZones";
|
|
4
|
+
|
|
5
|
+
type Tracks = readonly (readonly [number, readonly TimelineElement[]])[];
|
|
6
|
+
const NO_CLIPS: readonly TimelineElement[] = [];
|
|
7
|
+
|
|
8
|
+
/** Each row's clips, and its React key: the clips' zone and authored track, which adding a track does not renumber
|
|
9
|
+
* as it does display lanes. Rows sharing one (overlap sub-lanes, expanded children) take a #n suffix in row order. */
|
|
10
|
+
export function timelineRows(tracks: Tracks) {
|
|
11
|
+
const seen = new Map<string, number>();
|
|
12
|
+
const keys = new Map<number, string>();
|
|
13
|
+
const clips = new Map<number, readonly TimelineElement[]>();
|
|
14
|
+
for (const [track, els] of tracks) {
|
|
15
|
+
const base = els[0]
|
|
16
|
+
? `${classifyZone(els[0])}:${resolveElementTrack(els[0])}`
|
|
17
|
+
: `lane:${track}`;
|
|
18
|
+
const repeat = seen.get(base) ?? 0;
|
|
19
|
+
seen.set(base, repeat + 1);
|
|
20
|
+
keys.set(track, repeat ? `${base}#${repeat}` : base);
|
|
21
|
+
clips.set(track, els);
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
reactKey: (track: number) => keys.get(track) ?? `lane:${track}`,
|
|
25
|
+
clips: (track: number) => clips.get(track) ?? NO_CLIPS,
|
|
26
|
+
};
|
|
27
|
+
}
|