@hyperframes/studio 0.9.59 → 0.9.63
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-bya4hgms.js → hyperframes-player-CUQxAJaE.js} +1 -1
- package/dist/assets/{index--dcfSUzI.js → index-D3rdYBVx.js} +1 -1
- package/dist/assets/{index-Bxh5lW0C.js → index-DSrTQv-k.js} +204 -204
- package/dist/assets/{pausedVideoDecoder-BKym1jA6.js → pausedVideoDecoder-BWllfjF-.js} +1 -1
- package/dist/{chunk-G6FJSL7X.js → chunk-JTUKMELR.js} +34 -6
- package/dist/{chunk-5EEM5WO4.js → chunk-ZUDVUI7K.js} +11 -1
- package/dist/index.d.ts +28 -1
- package/dist/index.html +1 -1
- package/dist/index.js +1815 -1104
- package/dist/player.js +2 -2
- package/dist/ui.js +1 -1
- package/package.json +8 -8
- package/src/captions/components/CaptionOverlay.sealed.test.ts +273 -0
- package/src/captions/components/CaptionOverlay.tsx +112 -57
- package/src/captions/components/CaptionOverlayUtils.ts +319 -33
- package/src/captions/components/CaptionPropertyPanel.tsx +17 -0
- package/src/components/editor/LayersPanel.opaque.test.ts +2 -2
- package/src/components/editor/previewDrafts.test.ts +2 -2
- package/src/components/editor/previewGestureStartRead.test.ts +2 -2
- package/src/components/editor/previewLayers.test.ts +2 -2
- package/src/components/editor/previewOverlayRects.test.ts +2 -2
- package/src/components/editor/previewPointerTargets.test.ts +2 -2
- package/src/components/editor/previewSelection.test.ts +2 -2
- package/src/components/editor/useColorGradingController.sealed.test.ts +165 -0
- package/src/components/editor/useColorGradingController.ts +20 -1
- package/src/components/editor/useColorGradingPreviews.ts +127 -43
- package/src/components/nle/AudioMeterStrip.tsx +63 -2
- package/src/components/nle/NLEPreview.test.ts +24 -0
- package/src/components/nle/NLEPreview.tsx +2 -6
- package/src/components/nle/audioSealedPreview.test.ts +254 -0
- package/src/components/nle/previewStage.ts +11 -1
- package/src/components/nle/zLaneGesture.test.ts +67 -0
- package/src/components/nle/zLaneGesture.ts +4 -0
- package/src/components/panels/VariablesPanel.test.tsx +90 -1
- package/src/components/panels/VariablesPanel.tsx +41 -17
- package/src/components/panels/renderHandoff.test.ts +86 -0
- package/src/components/panels/renderHandoff.ts +28 -0
- package/src/components/ui/Menu.test.tsx +77 -0
- package/src/components/ui/Menu.tsx +47 -4
- package/src/components/ui/Popover.tsx +5 -2
- package/src/elementAnimations.test.ts +13 -0
- package/src/hooks/timelineAudioGroupCreate.ts +57 -7
- package/src/hooks/timelineAudioGroupVolume.ts +110 -34
- package/src/hooks/useCaptionDetection.ts +175 -54
- package/src/hooks/usePersistentEditHistory.test.ts +84 -0
- package/src/hooks/usePersistentEditHistory.ts +36 -3
- package/src/index.ts +1 -0
- 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/useShadowPreviewReload.ts +7 -0
- package/src/player/hooks/useTimelinePlayer.shadowReload.test.ts +20 -0
- package/src/player/lib/previewChannel.ts +10 -0
- package/src/utils/gsapUndoRestore.sealed.test.ts +73 -0
- package/src/utils/gsapUndoRestore.ts +66 -0
- package/src/utils/studioPendingEdits.test.ts +20 -0
- package/src/utils/studioPendingEdits.ts +11 -4
|
@@ -5,7 +5,16 @@ import { useCaptionStore } from "../captions/store";
|
|
|
5
5
|
import { acceptStudioRuntimeMessage } from "../player/lib/runtimeProtocol";
|
|
6
6
|
import { useCaptionSync } from "../captions/hooks/useCaptionSync";
|
|
7
7
|
import { parseCaptionComposition } from "../captions/parser";
|
|
8
|
+
import type { CaptionModel } from "../captions/types";
|
|
8
9
|
import { studioApiFetch } from "../utils/studioApiFetch";
|
|
10
|
+
import { MAX_DESCRIBE_HANDLES } from "@hyperframes/core/runtime/editing-port";
|
|
11
|
+
import { previewComputedStyles, previewFrameOpaque } from "../player/lib/previewChannel";
|
|
12
|
+
import {
|
|
13
|
+
describePreviewElements,
|
|
14
|
+
previewAncestors,
|
|
15
|
+
queryPreviewElements,
|
|
16
|
+
type PreviewElement,
|
|
17
|
+
} from "../player/lib/previewElements";
|
|
9
18
|
|
|
10
19
|
interface UseCaptionDetectionParams {
|
|
11
20
|
projectId: string | null;
|
|
@@ -18,6 +27,91 @@ interface UseCaptionDetectionParams {
|
|
|
18
27
|
setRightCollapsed: (collapsed: boolean) => void;
|
|
19
28
|
}
|
|
20
29
|
|
|
30
|
+
// The parser's GROUP_SELECTOR and WORD_SELECTOR, the elements it reads.
|
|
31
|
+
const GROUP_SELECTOR = ".caption-group, .caption-line, .caption-block";
|
|
32
|
+
const WORD_SELECTOR = ".word, .caption-word";
|
|
33
|
+
|
|
34
|
+
const attribute = (el: PreviewElement | null | undefined, name: string) =>
|
|
35
|
+
el?.attributes.find(([key]) => key === name)?.[1] ?? null;
|
|
36
|
+
|
|
37
|
+
/** The styles `parseCaptionComposition` reads off its first word and group. */
|
|
38
|
+
const CAPTION_STYLES = [
|
|
39
|
+
"font-size",
|
|
40
|
+
"font-weight",
|
|
41
|
+
"font-family",
|
|
42
|
+
"color",
|
|
43
|
+
"text-transform",
|
|
44
|
+
"letter-spacing",
|
|
45
|
+
"background-color",
|
|
46
|
+
"border-radius",
|
|
47
|
+
"padding-top",
|
|
48
|
+
"padding-right",
|
|
49
|
+
"padding-bottom",
|
|
50
|
+
"padding-left",
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
async function frameStyles(iframe: HTMLIFrameElement, handle: string | undefined) {
|
|
54
|
+
if (!handle) return null;
|
|
55
|
+
const styles = await previewComputedStyles(iframe, { handle }, CAPTION_STYLES);
|
|
56
|
+
if (!styles) return null;
|
|
57
|
+
const camel = (name: string) => name.replace(/-(\w)/g, (_, c: string) => c.toUpperCase());
|
|
58
|
+
return Object.fromEntries(CAPTION_STYLES.map((name) => [camel(name), styles[name] ?? ""]));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** A frame's caption groups and words rebuilt in order in a detached document, with a stand-in
|
|
62
|
+
* `getComputedStyle` for the parser; null past one query's matches or with no answer. */
|
|
63
|
+
async function frameCaptionDom(
|
|
64
|
+
iframe: HTMLIFrameElement,
|
|
65
|
+
): Promise<{ doc: Document; win: Window } | null> {
|
|
66
|
+
const [all, groups, words] = await Promise.all(
|
|
67
|
+
[`${GROUP_SELECTOR}, ${WORD_SELECTOR}`, GROUP_SELECTOR, WORD_SELECTOR].map((selector) =>
|
|
68
|
+
queryPreviewElements(iframe, selector),
|
|
69
|
+
),
|
|
70
|
+
);
|
|
71
|
+
if (!all || !groups || !words || all.truncated) return null;
|
|
72
|
+
const handles = all.matches.map((match) => match.handle);
|
|
73
|
+
const chains: Array<string[] | null> = [];
|
|
74
|
+
for (let i = 0; i < handles.length; i += MAX_DESCRIBE_HANDLES) {
|
|
75
|
+
const part = await previewAncestors(iframe, handles.slice(i, i + MAX_DESCRIBE_HANDLES));
|
|
76
|
+
if (!part) return null;
|
|
77
|
+
chains.push(...part);
|
|
78
|
+
}
|
|
79
|
+
const isGroup = new Set(groups.matches.map((match) => match.handle));
|
|
80
|
+
const isWord = new Set(words.matches.map((match) => match.handle));
|
|
81
|
+
const doc = document.implementation.createHTMLDocument("");
|
|
82
|
+
const mirrored = new Map<string, Element>();
|
|
83
|
+
handles.forEach((handle, i) => {
|
|
84
|
+
const el = doc.createElement("span");
|
|
85
|
+
if (isGroup.has(handle)) el.classList.add("caption-group");
|
|
86
|
+
if (isWord.has(handle)) el.classList.add("word");
|
|
87
|
+
const parent = chains[i]?.find((ancestor) => mirrored.has(ancestor));
|
|
88
|
+
(parent ? mirrored.get(parent)! : doc.body).append(el);
|
|
89
|
+
mirrored.set(handle, el);
|
|
90
|
+
});
|
|
91
|
+
const firstWord = words.matches[0]?.handle;
|
|
92
|
+
const firstGroup = groups.matches[0]?.handle;
|
|
93
|
+
const styles = new Map<Element | undefined, Record<string, string> | null>([
|
|
94
|
+
[mirrored.get(firstWord ?? ""), await frameStyles(iframe, firstWord)],
|
|
95
|
+
[mirrored.get(firstGroup ?? ""), await frameStyles(iframe, firstGroup)],
|
|
96
|
+
]);
|
|
97
|
+
const win = { getComputedStyle: (el: Element) => styles.get(el) ?? {} } as unknown as Window;
|
|
98
|
+
return { doc, win };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function frameCaptionModel(
|
|
102
|
+
iframe: HTMLIFrameElement,
|
|
103
|
+
content: string,
|
|
104
|
+
): Promise<CaptionModel | null> {
|
|
105
|
+
const [root] = (await queryPreviewElements(iframe, "[data-composition-id]"))?.matches ?? [];
|
|
106
|
+
const rootEl = root ? (await describePreviewElements(iframe, [root.handle]))?.[0] : null;
|
|
107
|
+
const frame = await frameCaptionDom(iframe);
|
|
108
|
+
if (!frame) return null;
|
|
109
|
+
const w = parseInt(attribute(rootEl, "data-width") ?? "1920", 10);
|
|
110
|
+
const h = parseInt(attribute(rootEl, "data-height") ?? "1080", 10);
|
|
111
|
+
const dur = parseFloat(attribute(rootEl, "data-duration") ?? "0");
|
|
112
|
+
return parseCaptionComposition(frame.doc, frame.win, content, w, h, dur);
|
|
113
|
+
}
|
|
114
|
+
|
|
21
115
|
export function useCaptionDetection({
|
|
22
116
|
projectId,
|
|
23
117
|
activeCompPath,
|
|
@@ -52,6 +146,51 @@ export function useCaptionDetection({
|
|
|
52
146
|
if (!projectId) return;
|
|
53
147
|
|
|
54
148
|
let activating = false;
|
|
149
|
+
// A detection still in flight when the composition changes must not enter edit mode for the old one.
|
|
150
|
+
let disposed = false;
|
|
151
|
+
|
|
152
|
+
const pickCaptionSource = (hostSrcs: Array<string | null>, captionCompId: string | null) => {
|
|
153
|
+
const host = hostSrcs.find((src) => src && src.includes("captions"));
|
|
154
|
+
if (host) return host;
|
|
155
|
+
for (const [id, src] of compIdToSrc) {
|
|
156
|
+
if (id.includes("caption") || src.includes("caption")) return src;
|
|
157
|
+
}
|
|
158
|
+
if (activeCompPath?.includes("captions")) return activeCompPath;
|
|
159
|
+
return captionCompId === null ? null : compIdToSrc.get(captionCompId) || null;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const loadCaptions = (
|
|
163
|
+
srcPath: string,
|
|
164
|
+
parse: (content: string) => Promise<CaptionModel | null>,
|
|
165
|
+
) =>
|
|
166
|
+
studioApiFetch(buildProjectApiPath(projectId, `/files/${encodeURIComponent(srcPath)}`))
|
|
167
|
+
.then((r) => r.json())
|
|
168
|
+
.then(async (data: { content?: string }) => {
|
|
169
|
+
if (disposed || !data.content || useCaptionStore.getState().isEditMode) return;
|
|
170
|
+
const model = await parse(data.content);
|
|
171
|
+
if (disposed || !model || useCaptionStore.getState().isEditMode) return;
|
|
172
|
+
const store = useCaptionStore.getState();
|
|
173
|
+
store.setModel(model);
|
|
174
|
+
store.setSourceFilePath(srcPath);
|
|
175
|
+
store.setEditMode(true);
|
|
176
|
+
captionSync.loadOverrides();
|
|
177
|
+
})
|
|
178
|
+
.catch(() => {});
|
|
179
|
+
|
|
180
|
+
const frameCaptionSource = async (iframe: HTMLIFrameElement) => {
|
|
181
|
+
if (!(await queryPreviewElements(iframe, ".caption-group"))?.matches.length) return null;
|
|
182
|
+
const hosts = await queryPreviewElements(
|
|
183
|
+
iframe,
|
|
184
|
+
"[data-composition-src], [data-composition-file]",
|
|
185
|
+
);
|
|
186
|
+
const handles = (hosts?.matches ?? []).slice(0, MAX_DESCRIBE_HANDLES).map((m) => m.handle);
|
|
187
|
+
const described = handles.length ? await describePreviewElements(iframe, handles) : [];
|
|
188
|
+
const hostSrcs = (described ?? []).map(
|
|
189
|
+
(el) => attribute(el, "data-composition-src") || attribute(el, "data-composition-file"),
|
|
190
|
+
);
|
|
191
|
+
const captionComp = await queryPreviewElements(iframe, '[data-composition-id*="caption"]');
|
|
192
|
+
return pickCaptionSource(hostSrcs, captionComp?.matches[0]?.source.compositionId ?? null);
|
|
193
|
+
};
|
|
55
194
|
|
|
56
195
|
const tryActivateCaptions = () => {
|
|
57
196
|
const captionState = useCaptionStore.getState();
|
|
@@ -61,6 +200,19 @@ export function useCaptionDetection({
|
|
|
61
200
|
}
|
|
62
201
|
|
|
63
202
|
const iframe = previewIframeRef.current;
|
|
203
|
+
if (iframe && previewFrameOpaque(iframe)) {
|
|
204
|
+
activating = true;
|
|
205
|
+
void frameCaptionSource(iframe)
|
|
206
|
+
.then((src) =>
|
|
207
|
+
src && !disposed
|
|
208
|
+
? loadCaptions(src, (content) => frameCaptionModel(iframe, content))
|
|
209
|
+
: null,
|
|
210
|
+
)
|
|
211
|
+
.finally(() => {
|
|
212
|
+
activating = false;
|
|
213
|
+
});
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
64
216
|
let doc: Document | null = null;
|
|
65
217
|
let win: Window | null = null;
|
|
66
218
|
try {
|
|
@@ -74,63 +226,31 @@ export function useCaptionDetection({
|
|
|
74
226
|
const groups = doc.querySelectorAll(".caption-group");
|
|
75
227
|
if (groups.length === 0) return;
|
|
76
228
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (!captionSrcPath) {
|
|
90
|
-
for (const [id, src] of compIdToSrc) {
|
|
91
|
-
if (id.includes("caption") || src.includes("caption")) {
|
|
92
|
-
captionSrcPath = src;
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (!captionSrcPath && activeCompPath?.includes("captions")) {
|
|
99
|
-
captionSrcPath = activeCompPath;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (!captionSrcPath) {
|
|
103
|
-
const captionComp = doc.querySelector('[data-composition-id*="caption"]');
|
|
104
|
-
if (captionComp) {
|
|
105
|
-
const compId = captionComp.getAttribute("data-composition-id") || "";
|
|
106
|
-
captionSrcPath = compIdToSrc.get(compId) || null;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
229
|
+
const hostSrcs = [
|
|
230
|
+
...doc.querySelectorAll("[data-composition-src], [data-composition-file]"),
|
|
231
|
+
].map(
|
|
232
|
+
(host) =>
|
|
233
|
+
host.getAttribute("data-composition-src") || host.getAttribute("data-composition-file"),
|
|
234
|
+
);
|
|
235
|
+
const captionComp = doc.querySelector('[data-composition-id*="caption"]');
|
|
236
|
+
const captionCompId = captionComp
|
|
237
|
+
? captionComp.getAttribute("data-composition-id") || ""
|
|
238
|
+
: null;
|
|
239
|
+
const captionSrcPath = pickCaptionSource(hostSrcs, captionCompId);
|
|
110
240
|
if (!captionSrcPath) return;
|
|
111
241
|
|
|
112
242
|
activating = true;
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const store = useCaptionStore.getState();
|
|
125
|
-
store.setModel(model);
|
|
126
|
-
store.setSourceFilePath(srcPath);
|
|
127
|
-
store.setEditMode(true);
|
|
128
|
-
captionSync.loadOverrides();
|
|
129
|
-
})
|
|
130
|
-
.catch(() => {})
|
|
131
|
-
.finally(() => {
|
|
132
|
-
activating = false;
|
|
133
|
-
});
|
|
243
|
+
const frameDoc = doc;
|
|
244
|
+
const frameWin = win;
|
|
245
|
+
void loadCaptions(captionSrcPath, async (content) => {
|
|
246
|
+
const root = frameDoc.querySelector("[data-composition-id]");
|
|
247
|
+
const w = parseInt(root?.getAttribute("data-width") ?? "1920", 10);
|
|
248
|
+
const h = parseInt(root?.getAttribute("data-height") ?? "1080", 10);
|
|
249
|
+
const dur = parseFloat(root?.getAttribute("data-duration") ?? "0");
|
|
250
|
+
return parseCaptionComposition(frameDoc, frameWin, content, w, h, dur);
|
|
251
|
+
}).finally(() => {
|
|
252
|
+
activating = false;
|
|
253
|
+
});
|
|
134
254
|
};
|
|
135
255
|
|
|
136
256
|
const handleMessage = (e: MessageEvent) => {
|
|
@@ -146,6 +266,7 @@ export function useCaptionDetection({
|
|
|
146
266
|
tryActivateCaptions();
|
|
147
267
|
|
|
148
268
|
return () => {
|
|
269
|
+
disposed = true;
|
|
149
270
|
window.removeEventListener("message", handleMessage);
|
|
150
271
|
};
|
|
151
272
|
}, [activeCompPath, projectId, compIdToSrc, captionSync, previewIframeRef, livePreviewIframe]);
|
|
@@ -724,3 +724,87 @@ it("stores DOM targets in existing history and retains them through undo and red
|
|
|
724
724
|
await act(() => hook().redo({ readFile }));
|
|
725
725
|
expect(history.list().at(-1)?.targets).toEqual(targets);
|
|
726
726
|
});
|
|
727
|
+
|
|
728
|
+
it("three quick drags are three entries in the list as soon as each drag's saves are in", async () => {
|
|
729
|
+
const { hook, save, history } = await studio();
|
|
730
|
+
const moves = [
|
|
731
|
+
["A", "B"],
|
|
732
|
+
["B", "C"],
|
|
733
|
+
["C", "D"],
|
|
734
|
+
] as const;
|
|
735
|
+
for (const [i, [before, after]] of moves.entries()) {
|
|
736
|
+
// A drag claims under its own key with no idle limit, as a plain move does, and settles after its save.
|
|
737
|
+
const drag = beginStudioPendingEdit(() => () => {});
|
|
738
|
+
save(after);
|
|
739
|
+
const saved = hook().recordEdit({
|
|
740
|
+
label: "Move layer",
|
|
741
|
+
coalesceKey: `move:${i}`,
|
|
742
|
+
coalesceMs: Number.POSITIVE_INFINITY,
|
|
743
|
+
files: { "index.html": { before, after } },
|
|
744
|
+
});
|
|
745
|
+
drag.settle(saved);
|
|
746
|
+
await act(() => saved);
|
|
747
|
+
}
|
|
748
|
+
await vi.waitFor(() =>
|
|
749
|
+
expect(history.list().filter((entry) => entry.label === "Move layer")).toHaveLength(3),
|
|
750
|
+
);
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
it("the next drag's claim reaches the server after the settled drag's empty claim, however slow that one is", async () => {
|
|
754
|
+
const { hook, save } = await studio();
|
|
755
|
+
const forward = globalThis.fetch;
|
|
756
|
+
const arrived: string[] = [];
|
|
757
|
+
let release = () => {};
|
|
758
|
+
const held = new Promise<void>((resolve) => (release = resolve));
|
|
759
|
+
vi.stubGlobal("fetch", async (url: string, init?: RequestInit) => {
|
|
760
|
+
const claim = url.endsWith("/claim")
|
|
761
|
+
? (JSON.parse(String(init?.body)) as { paths: string[] })
|
|
762
|
+
: null;
|
|
763
|
+
if (claim && !claim.paths.length) await held;
|
|
764
|
+
if (claim) arrived.push(claim.paths.length ? "claim" : "empty");
|
|
765
|
+
return forward(url, init);
|
|
766
|
+
});
|
|
767
|
+
const drag = (i: number, before: string, after: string) => {
|
|
768
|
+
const pending = beginStudioPendingEdit(() => () => {});
|
|
769
|
+
save(after);
|
|
770
|
+
const saved = hook().recordEdit({
|
|
771
|
+
label: "Move layer",
|
|
772
|
+
coalesceKey: `move:${i}`,
|
|
773
|
+
coalesceMs: Number.POSITIVE_INFINITY,
|
|
774
|
+
files: { "index.html": { before, after } },
|
|
775
|
+
});
|
|
776
|
+
pending.settle(saved);
|
|
777
|
+
return saved;
|
|
778
|
+
};
|
|
779
|
+
await act(() => drag(0, "A", "B"));
|
|
780
|
+
const next = drag(1, "B", "C");
|
|
781
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
782
|
+
release();
|
|
783
|
+
await act(() => next);
|
|
784
|
+
expect(arrived.slice(0, 3)).toEqual(["claim", "empty", "claim"]);
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
it("a gesture that writes twice under one key stays one entry once it settles", async () => {
|
|
788
|
+
const { hook, save, history } = await studio();
|
|
789
|
+
const resize = beginStudioPendingEdit(() => () => {});
|
|
790
|
+
const writes = (async () => {
|
|
791
|
+
for (const [before, after] of [
|
|
792
|
+
["A", "B"],
|
|
793
|
+
["B", "C"],
|
|
794
|
+
] as const) {
|
|
795
|
+
save(after);
|
|
796
|
+
await hook().recordEdit({
|
|
797
|
+
label: "Resize layer",
|
|
798
|
+
coalesceKey: "tx:resize",
|
|
799
|
+
coalesceMs: Number.POSITIVE_INFINITY,
|
|
800
|
+
files: { "index.html": { before, after } },
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
})();
|
|
804
|
+
resize.settle(writes);
|
|
805
|
+
await act(() => writes);
|
|
806
|
+
await vi.waitFor(() =>
|
|
807
|
+
expect(history.list().filter((entry) => entry.label === "Resize layer")).toHaveLength(1),
|
|
808
|
+
);
|
|
809
|
+
expect(history.list().find((entry) => entry.label === "Resize layer")?.files.length).toBe(1);
|
|
810
|
+
});
|
|
@@ -3,7 +3,10 @@ import type { HistoryListItem, HistoryResult } from "@hyperframes/studio-server"
|
|
|
3
3
|
import { studioFileContentVersion, studioWriteHeaders } from "../utils/studioFileVersion";
|
|
4
4
|
import type { RestoreFiles } from "../utils/gsapUndoRestore";
|
|
5
5
|
import { studioApiFetch } from "../utils/studioApiFetch";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
setStudioPendingEditClaimClock,
|
|
8
|
+
setStudioPendingEditsSettled,
|
|
9
|
+
} from "../utils/studioPendingEdits";
|
|
7
10
|
import type { RecordEditInput } from "../utils/studioFileHistory";
|
|
8
11
|
import { generateId } from "../utils/generateId";
|
|
9
12
|
|
|
@@ -41,6 +44,7 @@ interface HistoryView {
|
|
|
41
44
|
forward: NextStep | null;
|
|
42
45
|
}
|
|
43
46
|
|
|
47
|
+
const APP_KEEPS_NO_HISTORY = 404;
|
|
44
48
|
const EMPTY: HistoryView = { entries: [], back: null, forward: null };
|
|
45
49
|
/** ponytail: the newest entries' content is kept; older ones step through the server only. */
|
|
46
50
|
const OWN_ENTRIES_KEPT = 100;
|
|
@@ -201,12 +205,28 @@ function redoneAt(view: HistoryView): number | null {
|
|
|
201
205
|
return view.entries.find((entry) => entry.id === undo?.undoes)?.endedAt ?? null;
|
|
202
206
|
}
|
|
203
207
|
|
|
208
|
+
function closeHeldClaimWithAClaimOfNothing(
|
|
209
|
+
projectId: string,
|
|
210
|
+
heldClaimRef: { current: { paths: string[]; at: number } | null },
|
|
211
|
+
refresh: () => Promise<void>,
|
|
212
|
+
): Promise<void> {
|
|
213
|
+
if (!heldClaimRef.current) return Promise.resolve();
|
|
214
|
+
heldClaimRef.current = null;
|
|
215
|
+
return post(historyUrl(projectId, "/claim"), { label: "Edited in Studio", paths: [] }).then(
|
|
216
|
+
(reply) => {
|
|
217
|
+
if (reply.ok) void refresh();
|
|
218
|
+
},
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
204
222
|
/** Studio's undo over the server's project history: an edit claims what it wrote; Cmd+Z steps the person's. */
|
|
223
|
+
// fallow-ignore-next-line complexity
|
|
205
224
|
export function usePersistentEditHistory({ projectId }: UsePersistentEditHistoryOptions) {
|
|
206
225
|
const [view, setView] = useState<HistoryView>(EMPTY);
|
|
207
226
|
const [loaded, setLoaded] = useState(false);
|
|
208
227
|
// A coalescing claim the server just took, until `refresh()` brings its entry into `view`.
|
|
209
228
|
const heldClaimRef = useRef<{ paths: string[]; at: number } | null>(null);
|
|
229
|
+
const claimsAfterTheClose = useRef<Promise<void>>(Promise.resolve());
|
|
210
230
|
const projectIdRef = useRef(projectId);
|
|
211
231
|
projectIdRef.current = projectId;
|
|
212
232
|
const [own] = useState(createOwnHistory);
|
|
@@ -239,11 +259,24 @@ export function usePersistentEditHistory({ projectId }: UsePersistentEditHistory
|
|
|
239
259
|
return () => setStudioPendingEditClaimClock(null);
|
|
240
260
|
}, [own]);
|
|
241
261
|
|
|
262
|
+
useEffect(() => {
|
|
263
|
+
if (!projectId) return;
|
|
264
|
+
setStudioPendingEditsSettled(() => {
|
|
265
|
+
claimsAfterTheClose.current = closeHeldClaimWithAClaimOfNothing(
|
|
266
|
+
projectId,
|
|
267
|
+
heldClaimRef,
|
|
268
|
+
refresh,
|
|
269
|
+
);
|
|
270
|
+
});
|
|
271
|
+
return () => setStudioPendingEditsSettled(null);
|
|
272
|
+
}, [projectId, refresh]);
|
|
273
|
+
|
|
242
274
|
const recordEdit = useCallback(
|
|
243
275
|
async ({ label, coalesceKey, coalesceMs, files, targets, created = [] }: RecordEditInput) => {
|
|
244
276
|
if (!projectId) return;
|
|
245
277
|
const paths = [...Object.keys(files), ...created];
|
|
246
278
|
own.overtake();
|
|
279
|
+
await claimsAfterTheClose.current;
|
|
247
280
|
const reply = await post(historyUrl(projectId, "/claim"), {
|
|
248
281
|
label,
|
|
249
282
|
paths,
|
|
@@ -286,8 +319,8 @@ export function usePersistentEditHistory({ projectId }: UsePersistentEditHistory
|
|
|
286
319
|
);
|
|
287
320
|
heldClaimRef.current = null;
|
|
288
321
|
void refresh();
|
|
289
|
-
|
|
290
|
-
|
|
322
|
+
if (!posted.ok && posted.status === APP_KEEPS_NO_HISTORY)
|
|
323
|
+
return { ok: false, reason: "empty" };
|
|
291
324
|
if (!posted.ok) return { ok: false, reason: "failed", message: posted.error };
|
|
292
325
|
const reply = posted.body as HistoryResult;
|
|
293
326
|
if (!reply.ok) {
|
package/src/index.ts
CHANGED
|
@@ -117,6 +117,7 @@ export { ImageThumbnail } from "./player/components/ImageThumbnail";
|
|
|
117
117
|
export type { ImageThumbnailProps } from "./player/components/ImageThumbnail";
|
|
118
118
|
export { useRenderClipContent } from "./hooks/useRenderClipContent";
|
|
119
119
|
export { useThumbnailStill } from "./hooks/useThumbnailStill";
|
|
120
|
+
export { fetchParsedAnimations, getAnimationsForElement } from "./hooks/useGsapTweenCache";
|
|
120
121
|
export type { ThumbnailStill, UseThumbnailStillOptions } from "./hooks/useThumbnailStill";
|
|
121
122
|
export type { UseRenderClipContentOptions } from "./hooks/useRenderClipContent";
|
|
122
123
|
export type { ThumbnailPriority } from "./player/lib/thumbnailScheduler";
|
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 (
|