@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
package/dist/player.js
CHANGED
package/dist/ui.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/studio",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.63",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -64,12 +64,12 @@
|
|
|
64
64
|
"dockview-react": "8.3.1",
|
|
65
65
|
"gsap": "^3.13.0",
|
|
66
66
|
"mediabunny": "^1.66.0",
|
|
67
|
-
"@hyperframes/
|
|
68
|
-
"@hyperframes/
|
|
69
|
-
"@hyperframes/
|
|
70
|
-
"@hyperframes/
|
|
71
|
-
"@hyperframes/shader-transitions": "0.9.
|
|
72
|
-
"@hyperframes/studio-server": "0.9.
|
|
67
|
+
"@hyperframes/parsers": "0.9.63",
|
|
68
|
+
"@hyperframes/sdk": "0.9.63",
|
|
69
|
+
"@hyperframes/player": "0.9.63",
|
|
70
|
+
"@hyperframes/core": "0.9.63",
|
|
71
|
+
"@hyperframes/shader-transitions": "0.9.63",
|
|
72
|
+
"@hyperframes/studio-server": "0.9.63"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"vite": "^6.4.5",
|
|
87
87
|
"vitest": "^4.1.12",
|
|
88
88
|
"zustand": "^5.0.0",
|
|
89
|
-
"@hyperframes/producer": "0.9.
|
|
89
|
+
"@hyperframes/producer": "0.9.63"
|
|
90
90
|
},
|
|
91
91
|
"peerDependencies": {
|
|
92
92
|
"react": "19",
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { act, createElement, Fragment, useRef } from "react";
|
|
3
|
+
import { createRoot } from "react-dom/client";
|
|
4
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
5
|
+
// The frame's real runtime agent, serving the opaque frame from this document.
|
|
6
|
+
import { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
|
|
7
|
+
import { installReactActEnvironment } from "../../hooks/domSelectionTestHarness";
|
|
8
|
+
import { detachedFakeIframe } from "../../player/hooks/timelinePlayerTestHarness";
|
|
9
|
+
import { previewRequest } from "../../player/lib/previewChannel";
|
|
10
|
+
import { usePreviewIframeStore } from "../../player/store/previewIframeStore";
|
|
11
|
+
import { useCaptionDetection } from "../../hooks/useCaptionDetection";
|
|
12
|
+
import { studioApiFetch } from "../../utils/studioApiFetch";
|
|
13
|
+
import type { useCaptionSync } from "../hooks/useCaptionSync";
|
|
14
|
+
import { useCaptionStore } from "../store";
|
|
15
|
+
import { CaptionOverlay } from "./CaptionOverlay";
|
|
16
|
+
import { applyCaptionModelToIframe } from "./CaptionOverlayUtils";
|
|
17
|
+
import { CaptionPropertyPanel } from "./CaptionPropertyPanel";
|
|
18
|
+
|
|
19
|
+
installReactActEnvironment();
|
|
20
|
+
|
|
21
|
+
const SOURCE = `const TRANSCRIPT = [
|
|
22
|
+
{ text: "Hello", start: 0, end: 0.5 },
|
|
23
|
+
{ text: "world", start: 0.5, end: 1 },
|
|
24
|
+
];`;
|
|
25
|
+
vi.mock("../../utils/studioApiFetch", () => ({
|
|
26
|
+
studioApiFetch: vi.fn(async () => ({ json: async () => ({ content: SOURCE }) })),
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
const closers: Array<() => void> = [];
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
closers.splice(0).forEach((close) => close());
|
|
32
|
+
useCaptionStore.getState().reset();
|
|
33
|
+
usePreviewIframeStore.setState({ iframe: null });
|
|
34
|
+
document.body.innerHTML = "";
|
|
35
|
+
vi.unstubAllGlobals();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
type PortRequest = { id?: unknown; kind?: unknown; params?: unknown };
|
|
39
|
+
|
|
40
|
+
/** A frame Studio cannot read, whose runtime is the real editing agent over this document. */
|
|
41
|
+
function opaqueFrame() {
|
|
42
|
+
const frame: Record<string, unknown> = {};
|
|
43
|
+
const iframe = detachedFakeIframe(frame);
|
|
44
|
+
Object.defineProperty(iframe, "contentDocument", { value: null });
|
|
45
|
+
Object.defineProperty(frame, "document", {
|
|
46
|
+
get: () => {
|
|
47
|
+
throw new DOMException("blocked", "SecurityError");
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
let pick: ((request: PortRequest) => boolean) | null = null;
|
|
51
|
+
const heldIds = new Set<unknown>();
|
|
52
|
+
const held: Array<() => void> = [];
|
|
53
|
+
// Studio's end of the port, so a test can keep the frame's answer to a request until it releases it.
|
|
54
|
+
const tap = (port: MessagePort) => {
|
|
55
|
+
const end = {
|
|
56
|
+
onmessage: null as ((event: MessageEvent) => void) | null,
|
|
57
|
+
postMessage(request: PortRequest) {
|
|
58
|
+
if (pick?.(request)) heldIds.add(request.id);
|
|
59
|
+
port.postMessage(request);
|
|
60
|
+
},
|
|
61
|
+
close: () => port.close(),
|
|
62
|
+
};
|
|
63
|
+
port.onmessage = (event) => {
|
|
64
|
+
const deliver = () => end.onmessage?.(event);
|
|
65
|
+
if (heldIds.has(event.data?.id)) held.push(deliver);
|
|
66
|
+
else deliver();
|
|
67
|
+
};
|
|
68
|
+
return end as unknown as MessagePort;
|
|
69
|
+
};
|
|
70
|
+
const parent = {
|
|
71
|
+
postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
|
|
72
|
+
window.dispatchEvent(
|
|
73
|
+
new MessageEvent("message", {
|
|
74
|
+
source: frame as unknown as Window,
|
|
75
|
+
data,
|
|
76
|
+
ports: ports.map(tap),
|
|
77
|
+
}),
|
|
78
|
+
),
|
|
79
|
+
} as unknown as Window;
|
|
80
|
+
const agent = installMarkedEditingAgent(parent);
|
|
81
|
+
frame.postMessage = (data: unknown) =>
|
|
82
|
+
window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
|
|
83
|
+
closers.push(() => agent.dispose());
|
|
84
|
+
iframe.style.width = "1920px";
|
|
85
|
+
iframe.getBoundingClientRect = () => new DOMRect(0, 0, 1920, 1080);
|
|
86
|
+
/** Keeps the answers to the requests `match` picks; the returned call hands them to Studio. */
|
|
87
|
+
const hold = (match: (request: PortRequest) => boolean) => {
|
|
88
|
+
pick = match;
|
|
89
|
+
return () => {
|
|
90
|
+
pick = null;
|
|
91
|
+
heldIds.clear();
|
|
92
|
+
held.splice(0).forEach((deliver) => deliver());
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
return { iframe, hold, held };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Settles after one frame round trip, once Studio has acted on every answer it was handed before. */
|
|
99
|
+
const frameRoundTrip = (iframe: HTMLIFrameElement) =>
|
|
100
|
+
previewRequest(iframe, "query", { selector: "body" });
|
|
101
|
+
|
|
102
|
+
const isWrite = ({ kind, params }: PortRequest) =>
|
|
103
|
+
kind === "caption-transform" &&
|
|
104
|
+
(params as { entries: Array<{ set?: unknown }> }).entries.some((entry) => entry.set);
|
|
105
|
+
|
|
106
|
+
const compIdToSrc = new Map([["captions", "compositions/captions.html"]]);
|
|
107
|
+
const captionSync = { loadOverrides: vi.fn() } as unknown as ReturnType<typeof useCaptionSync>;
|
|
108
|
+
|
|
109
|
+
function CaptionEditor({ iframe }: { iframe: HTMLIFrameElement }) {
|
|
110
|
+
const iframeRef = useRef(iframe);
|
|
111
|
+
useCaptionDetection({
|
|
112
|
+
projectId: "p",
|
|
113
|
+
activeCompPath: "index.html",
|
|
114
|
+
compIdToSrc,
|
|
115
|
+
captionEditMode: false,
|
|
116
|
+
captionHasSelection: false,
|
|
117
|
+
previewIframeRef: iframeRef,
|
|
118
|
+
captionSync,
|
|
119
|
+
setRightCollapsed: () => {},
|
|
120
|
+
});
|
|
121
|
+
const editing = useCaptionStore((s) => s.isEditMode);
|
|
122
|
+
// Studio mounts both only in caption edit mode.
|
|
123
|
+
if (!editing) return null;
|
|
124
|
+
return createElement(
|
|
125
|
+
Fragment,
|
|
126
|
+
null,
|
|
127
|
+
createElement(CaptionOverlay, { iframeRef }),
|
|
128
|
+
createElement(CaptionPropertyPanel, { iframeRef }),
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const pointer = (type: string, x: number, y: number) =>
|
|
133
|
+
new PointerEvent(type, { bubbles: true, clientX: x, clientY: y, pointerId: 1 });
|
|
134
|
+
|
|
135
|
+
const WORDS = `<span class="word">Hello</span> <span class="word">world</span>`;
|
|
136
|
+
|
|
137
|
+
/** Mounts Studio's caption editing over an opaque frame holding one caption group of `words`. */
|
|
138
|
+
function mountEditor(words = WORDS) {
|
|
139
|
+
vi.stubGlobal(
|
|
140
|
+
"ResizeObserver",
|
|
141
|
+
class {
|
|
142
|
+
observe() {}
|
|
143
|
+
disconnect() {}
|
|
144
|
+
},
|
|
145
|
+
);
|
|
146
|
+
Element.prototype.setPointerCapture ??= () => {};
|
|
147
|
+
document.body.innerHTML = `<div data-composition-id="captions" data-width="1920" data-height="1080" data-duration="1">
|
|
148
|
+
<div class="caption-group">${words}</div></div>`;
|
|
149
|
+
const frame = opaqueFrame();
|
|
150
|
+
usePreviewIframeStore.setState({ iframe: frame.iframe });
|
|
151
|
+
const host = document.createElement("div");
|
|
152
|
+
document.body.append(host);
|
|
153
|
+
const root = createRoot(host);
|
|
154
|
+
act(() => root.render(createElement(CaptionEditor, { iframe: frame.iframe })));
|
|
155
|
+
const unmount = () => act(() => root.unmount());
|
|
156
|
+
closers.push(unmount);
|
|
157
|
+
const boxes = () =>
|
|
158
|
+
[...host.querySelectorAll<HTMLElement>("div.absolute")].filter((el) => el.style.cursor);
|
|
159
|
+
return { ...frame, host, boxes, unmount };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async function openEditor(words?: string) {
|
|
163
|
+
const editor = mountEditor(words);
|
|
164
|
+
await vi.waitFor(() => expect(editor.boxes()).toHaveLength(2), { timeout: 3_000 });
|
|
165
|
+
return editor;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const styleOf = (segmentId: string) =>
|
|
169
|
+
useCaptionStore.getState().model!.segments.get(segmentId)!.style;
|
|
170
|
+
|
|
171
|
+
it("caption overlay shows + edits sealed", async () => {
|
|
172
|
+
const { host, boxes } = await openEditor();
|
|
173
|
+
const hello = document.querySelector<HTMLElement>(".word")!;
|
|
174
|
+
|
|
175
|
+
act(() => boxes()[0]!.click());
|
|
176
|
+
const segmentId = [...useCaptionStore.getState().selectedSegmentIds][0]!;
|
|
177
|
+
const overlay = boxes()[0]!.parentElement!;
|
|
178
|
+
// The move lands before the frame answers the press's read; it must still draw.
|
|
179
|
+
act(() => void boxes()[0]!.dispatchEvent(pointer("pointerdown", 100, 100)));
|
|
180
|
+
act(() => void overlay.dispatchEvent(pointer("pointermove", 130, 110)));
|
|
181
|
+
act(() => void overlay.dispatchEvent(pointer("pointerup", 130, 110)));
|
|
182
|
+
const transform = () => hello.parentElement!.style.transform;
|
|
183
|
+
await vi.waitFor(() =>
|
|
184
|
+
expect(transform()).toBe("translate(30.0px, 10.0px) rotate(0.0deg) scale(1.000)"),
|
|
185
|
+
);
|
|
186
|
+
await vi.waitFor(() =>
|
|
187
|
+
expect(useCaptionStore.getState().model!.segments.get(segmentId)!.style).toMatchObject({
|
|
188
|
+
x: 30,
|
|
189
|
+
y: 10,
|
|
190
|
+
}),
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
const xField = host.querySelector<HTMLInputElement>('input[aria-label="X position"]')!;
|
|
194
|
+
const setValue = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")!.set!;
|
|
195
|
+
act(() => {
|
|
196
|
+
setValue.call(xField, "50");
|
|
197
|
+
xField.dispatchEvent(new Event("input", { bubbles: true }));
|
|
198
|
+
});
|
|
199
|
+
await vi.waitFor(() => expect(transform()).toContain("translate(50.0px, 10.0px)"));
|
|
200
|
+
|
|
201
|
+
act(() => void window.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowRight" })));
|
|
202
|
+
await vi.waitFor(() => expect(transform()).toContain("translate(51.0px, 10.0px)"));
|
|
203
|
+
|
|
204
|
+
const model = useCaptionStore.getState().model!;
|
|
205
|
+
const segments = new Map(model.segments);
|
|
206
|
+
segments.set(segmentId, { ...segments.get(segmentId)!, style: { x: 5, y: 6 } });
|
|
207
|
+
applyCaptionModelToIframe({ ...model, segments });
|
|
208
|
+
await vi.waitFor(() => expect(transform()).toContain("translate(5.0px, 6.0px)"));
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("a detection still waiting on the frame when Studio unmounts it loads no captions", async () => {
|
|
212
|
+
vi.mocked(studioApiFetch).mockClear();
|
|
213
|
+
const { iframe, hold, held, unmount } = mountEditor();
|
|
214
|
+
// The detection's last question to the frame before it fetches the caption source.
|
|
215
|
+
const release = hold(({ kind, params }) => {
|
|
216
|
+
const selector = (params as { selector?: unknown } | undefined)?.selector;
|
|
217
|
+
return kind === "query" && selector === '[data-composition-id*="caption"]';
|
|
218
|
+
});
|
|
219
|
+
await vi.waitFor(() => expect(held).toHaveLength(1));
|
|
220
|
+
unmount();
|
|
221
|
+
release();
|
|
222
|
+
await frameRoundTrip(iframe);
|
|
223
|
+
expect(studioApiFetch).not.toHaveBeenCalled();
|
|
224
|
+
expect(useCaptionStore.getState()).toMatchObject({ isEditMode: false, model: null });
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it("a sealed drag the frame answers after the overlay unmounts stores no style", async () => {
|
|
228
|
+
const { iframe, hold, held, boxes, unmount } = await openEditor();
|
|
229
|
+
act(() => boxes()[0]!.click());
|
|
230
|
+
const segmentId = [...useCaptionStore.getState().selectedSegmentIds][0]!;
|
|
231
|
+
const overlay = boxes()[0]!.parentElement!;
|
|
232
|
+
const release = hold(isWrite);
|
|
233
|
+
act(() => void boxes()[0]!.dispatchEvent(pointer("pointerdown", 100, 100)));
|
|
234
|
+
act(() => void overlay.dispatchEvent(pointer("pointermove", 130, 110)));
|
|
235
|
+
act(() => void overlay.dispatchEvent(pointer("pointerup", 130, 110)));
|
|
236
|
+
await vi.waitFor(() => expect(held).toHaveLength(1));
|
|
237
|
+
unmount();
|
|
238
|
+
release();
|
|
239
|
+
await frameRoundTrip(iframe);
|
|
240
|
+
expect(styleOf(segmentId)?.x).toBeUndefined();
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it("a sealed nudge the frame answers after the overlay unmounts stores no style", async () => {
|
|
244
|
+
const { iframe, hold, held, boxes, unmount } = await openEditor();
|
|
245
|
+
act(() => boxes()[0]!.click());
|
|
246
|
+
const segmentId = [...useCaptionStore.getState().selectedSegmentIds][0]!;
|
|
247
|
+
const release = hold(isWrite);
|
|
248
|
+
act(() => void window.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowRight" })));
|
|
249
|
+
await vi.waitFor(() => expect(held).toHaveLength(1));
|
|
250
|
+
unmount();
|
|
251
|
+
release();
|
|
252
|
+
await frameRoundTrip(iframe);
|
|
253
|
+
expect(styleOf(segmentId)?.x).toBeUndefined();
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it("a frame word past the write bound is not stored, and a word within it still is", async () => {
|
|
257
|
+
const far = `<span data-caption-wrapper="true" style="display:inline-block; transform: translate(200000px, 0px)"><span class="word">world</span></span>`;
|
|
258
|
+
const { boxes } = await openEditor(`<span class="word">Hello</span> ${far}`);
|
|
259
|
+
const press = (box: HTMLElement, dx: number, dy: number) => {
|
|
260
|
+
act(() => box.click());
|
|
261
|
+
const overlay = box.parentElement!;
|
|
262
|
+
act(() => void box.dispatchEvent(pointer("pointerdown", 100, 100)));
|
|
263
|
+
if (dx || dy) act(() => void overlay.dispatchEvent(pointer("pointermove", 100 + dx, 100 + dy)));
|
|
264
|
+
act(() => void overlay.dispatchEvent(pointer("pointerup", 100 + dx, 100 + dy)));
|
|
265
|
+
return [...useCaptionStore.getState().selectedSegmentIds][0]!;
|
|
266
|
+
};
|
|
267
|
+
// A press and release with no move stores where the frame says the word is.
|
|
268
|
+
const farWord = press(boxes()[1]!, 0, 0);
|
|
269
|
+
const nearWord = press(boxes()[0]!, 30, 10);
|
|
270
|
+
// The frame answers in order, so the far word's answer was handled before this one's.
|
|
271
|
+
await vi.waitFor(() => expect(styleOf(nearWord)).toMatchObject({ x: 30, y: 10 }));
|
|
272
|
+
expect(styleOf(farWord)?.x).toBeUndefined();
|
|
273
|
+
});
|
|
@@ -4,7 +4,17 @@ import { useCaptionStore } from "../store";
|
|
|
4
4
|
import { usePlayerStore } from "../../player";
|
|
5
5
|
import { resolveCaptionNudge, isEditableEventTarget } from "../keyboard";
|
|
6
6
|
import { matchesKey } from "../../player/components/studioShortcuts";
|
|
7
|
+
import { previewFrameOpaque } from "../../player/lib/previewChannel";
|
|
7
8
|
import {
|
|
9
|
+
dragTransform,
|
|
10
|
+
moveSealedDrag,
|
|
11
|
+
pressSealedDrag,
|
|
12
|
+
readFrameWordBoxes,
|
|
13
|
+
restoreSealedDrag,
|
|
14
|
+
sealedNudger,
|
|
15
|
+
transformStyle,
|
|
16
|
+
type DragStart,
|
|
17
|
+
type SealedDrag,
|
|
8
18
|
readWordBoxes,
|
|
9
19
|
getWordEl,
|
|
10
20
|
readGsapTransform,
|
|
@@ -25,7 +35,10 @@ const ROTATION_OFFSET = 20; // px above the selection box
|
|
|
25
35
|
|
|
26
36
|
/** Sync canvas state back to the Zustand store so the property panel reflects it. */
|
|
27
37
|
function syncToStore(segmentId: string, el: HTMLElement, iframeWin: Window) {
|
|
28
|
-
|
|
38
|
+
storeStyle(segmentId, computeTransformStyle(el, iframeWin));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function storeStyle(segmentId: string, style: Record<string, number>) {
|
|
29
42
|
if (Object.keys(style).length > 0) {
|
|
30
43
|
useCaptionStore.getState().updateSegmentStyle(segmentId, style);
|
|
31
44
|
}
|
|
@@ -47,59 +60,57 @@ export const CaptionOverlay = memo(function CaptionOverlay({ iframeRef }: Captio
|
|
|
47
60
|
const cancelDragRef = useRef<(() => boolean) | null>(null);
|
|
48
61
|
|
|
49
62
|
// Interaction mode — only one active at a time
|
|
50
|
-
const interactionRef = useRef<
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
startMX: number;
|
|
56
|
-
startMY: number;
|
|
57
|
-
origTX: number;
|
|
58
|
-
origTY: number;
|
|
59
|
-
origScale: number;
|
|
60
|
-
origRotation: number;
|
|
61
|
-
}
|
|
62
|
-
| {
|
|
63
|
-
type: "scale";
|
|
64
|
-
wordEl: HTMLElement;
|
|
65
|
-
segmentId: string;
|
|
66
|
-
startMX: number;
|
|
67
|
-
startDxFromCenter: number;
|
|
68
|
-
origTX: number;
|
|
69
|
-
origTY: number;
|
|
70
|
-
origScale: number;
|
|
71
|
-
origRotation: number;
|
|
72
|
-
}
|
|
73
|
-
| {
|
|
74
|
-
type: "rotate";
|
|
75
|
-
wordEl: HTMLElement;
|
|
76
|
-
segmentId: string;
|
|
77
|
-
startMX: number;
|
|
78
|
-
origTX: number;
|
|
79
|
-
origTY: number;
|
|
80
|
-
origRotation: number;
|
|
81
|
-
origScale: number;
|
|
82
|
-
}
|
|
83
|
-
| null
|
|
84
|
-
>(null);
|
|
63
|
+
const interactionRef = useRef<(DragStart & { wordEl: HTMLElement; segmentId: string }) | null>(
|
|
64
|
+
null,
|
|
65
|
+
);
|
|
66
|
+
const sealedDragRef = useRef<SealedDrag | null>(null);
|
|
67
|
+
const liveRef = useRef(false);
|
|
85
68
|
|
|
86
69
|
// The observer and message filter bind to the live iframe element, which a promoted reload replaces.
|
|
87
70
|
// eslint-disable-next-line no-restricted-syntax
|
|
88
71
|
useEffect(() => {
|
|
89
72
|
if (!isEditMode) return;
|
|
73
|
+
liveRef.current = true;
|
|
90
74
|
|
|
91
75
|
// Let undo/redo (useAppHotkeys) reapply restored models to this iframe.
|
|
92
76
|
const unregisterIframe = registerCaptionIframe(iframeRef);
|
|
93
77
|
|
|
94
78
|
let prevBoxes: WordBox[] = [];
|
|
95
79
|
let rafId: number | null = null;
|
|
80
|
+
let disposed = false;
|
|
81
|
+
let reading = false;
|
|
82
|
+
let readAgain = false;
|
|
96
83
|
const tick = () => {
|
|
97
84
|
rafId = null;
|
|
98
85
|
const iframe = iframeRef.current;
|
|
99
86
|
const m = modelRef.current;
|
|
100
87
|
const overlay = overlayRef.current;
|
|
101
88
|
if (!iframe || !m || !overlay) return;
|
|
102
|
-
|
|
89
|
+
if (previewFrameOpaque(iframe)) return readSealed(iframe, m, overlay);
|
|
90
|
+
show(readWordBoxes(iframe, m, overlay));
|
|
91
|
+
};
|
|
92
|
+
// One frame read in flight; triggers meanwhile collapse into one more read after it.
|
|
93
|
+
const readSealed = (
|
|
94
|
+
iframe: HTMLIFrameElement,
|
|
95
|
+
m: NonNullable<typeof model>,
|
|
96
|
+
overlay: HTMLElement,
|
|
97
|
+
) => {
|
|
98
|
+
if (reading) {
|
|
99
|
+
readAgain = true;
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
reading = true;
|
|
103
|
+
void readFrameWordBoxes(iframe, m, overlay).then((next) => {
|
|
104
|
+
reading = false;
|
|
105
|
+
if (disposed) return;
|
|
106
|
+
if (next) show(next);
|
|
107
|
+
if (readAgain) {
|
|
108
|
+
readAgain = false;
|
|
109
|
+
scheduleTick();
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
const show = (next: WordBox[]) => {
|
|
103
114
|
if (
|
|
104
115
|
next.length === prevBoxes.length &&
|
|
105
116
|
next.every(
|
|
@@ -155,6 +166,12 @@ export const CaptionOverlay = memo(function CaptionOverlay({ iframeRef }: Captio
|
|
|
155
166
|
};
|
|
156
167
|
|
|
157
168
|
const cancelActiveDrag = (): boolean => {
|
|
169
|
+
const sealed = sealedDragRef.current;
|
|
170
|
+
if (sealed) {
|
|
171
|
+
sealedDragRef.current = null;
|
|
172
|
+
restoreSealedDrag(sealed);
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
158
175
|
const i = interactionRef.current;
|
|
159
176
|
if (!i) return false;
|
|
160
177
|
const win = getWin();
|
|
@@ -202,6 +219,10 @@ export const CaptionOverlay = memo(function CaptionOverlay({ iframeRef }: Captio
|
|
|
202
219
|
const { dx, dy } = nudge;
|
|
203
220
|
|
|
204
221
|
const iframe = iframeRef.current;
|
|
222
|
+
if (iframe && previewFrameOpaque(iframe)) {
|
|
223
|
+
void nudgeSealed(iframe, m, sel, dx, dy).then(scheduleTick);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
205
226
|
const win = iframe?.contentWindow;
|
|
206
227
|
if (!iframe || !win) return;
|
|
207
228
|
|
|
@@ -223,8 +244,15 @@ export const CaptionOverlay = memo(function CaptionOverlay({ iframeRef }: Captio
|
|
|
223
244
|
scheduleTick();
|
|
224
245
|
};
|
|
225
246
|
|
|
247
|
+
const nudgeSealed = sealedNudger(
|
|
248
|
+
() => !disposed,
|
|
249
|
+
(segId, moved) => storeStyle(segId, transformStyle(moved)),
|
|
250
|
+
);
|
|
251
|
+
|
|
226
252
|
window.addEventListener("keydown", handleKeyDown);
|
|
227
253
|
return () => {
|
|
254
|
+
disposed = true;
|
|
255
|
+
liveRef.current = false;
|
|
228
256
|
unregisterIframe();
|
|
229
257
|
unsubPlayer();
|
|
230
258
|
unsubPlayback();
|
|
@@ -247,6 +275,27 @@ export const CaptionOverlay = memo(function CaptionOverlay({ iframeRef }: Captio
|
|
|
247
275
|
return rect.width / nativeW;
|
|
248
276
|
}, [iframeRef]);
|
|
249
277
|
|
|
278
|
+
/** A press on a frame Studio cannot read: the drag starts from the word the frame reports. */
|
|
279
|
+
const startSealedDrag = useCallback(
|
|
280
|
+
(
|
|
281
|
+
type: DragStart["type"],
|
|
282
|
+
word: { group: number; word: number },
|
|
283
|
+
segmentId: string,
|
|
284
|
+
e: React.PointerEvent,
|
|
285
|
+
) => {
|
|
286
|
+
const iframe = iframeRef.current;
|
|
287
|
+
if (!iframe) return;
|
|
288
|
+
const press = {
|
|
289
|
+
startMX: e.clientX,
|
|
290
|
+
startMY: e.clientY,
|
|
291
|
+
cssScale: getCssScale(),
|
|
292
|
+
left: iframe.getBoundingClientRect().left,
|
|
293
|
+
};
|
|
294
|
+
sealedDragRef.current = pressSealedDrag(iframe, type, word, segmentId, press);
|
|
295
|
+
},
|
|
296
|
+
[iframeRef, getCssScale],
|
|
297
|
+
);
|
|
298
|
+
|
|
250
299
|
// --- Move ---
|
|
251
300
|
const startMove = useCallback(
|
|
252
301
|
(groupIndex: number, wordIndex: number, segmentId: string, e: React.PointerEvent) => {
|
|
@@ -254,6 +303,8 @@ export const CaptionOverlay = memo(function CaptionOverlay({ iframeRef }: Captio
|
|
|
254
303
|
(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);
|
|
255
304
|
const iframe = iframeRef.current;
|
|
256
305
|
if (!iframe) return;
|
|
306
|
+
if (previewFrameOpaque(iframe))
|
|
307
|
+
return startSealedDrag("move", { group: groupIndex, word: wordIndex }, segmentId, e);
|
|
257
308
|
const wordEl = getWordEl(iframe, groupIndex, wordIndex);
|
|
258
309
|
const win = iframe.contentWindow;
|
|
259
310
|
if (!wordEl || !win) return;
|
|
@@ -270,7 +321,7 @@ export const CaptionOverlay = memo(function CaptionOverlay({ iframeRef }: Captio
|
|
|
270
321
|
origRotation: state.rotation,
|
|
271
322
|
};
|
|
272
323
|
},
|
|
273
|
-
[iframeRef],
|
|
324
|
+
[iframeRef, startSealedDrag],
|
|
274
325
|
);
|
|
275
326
|
|
|
276
327
|
// --- Scale ---
|
|
@@ -281,6 +332,8 @@ export const CaptionOverlay = memo(function CaptionOverlay({ iframeRef }: Captio
|
|
|
281
332
|
(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);
|
|
282
333
|
const iframe = iframeRef.current;
|
|
283
334
|
if (!iframe) return;
|
|
335
|
+
if (previewFrameOpaque(iframe))
|
|
336
|
+
return startSealedDrag("scale", { group: groupIndex, word: wordIndex }, segmentId, e);
|
|
284
337
|
const wordEl = getWordEl(iframe, groupIndex, wordIndex);
|
|
285
338
|
const win = iframe.contentWindow;
|
|
286
339
|
if (!wordEl || !win) return;
|
|
@@ -303,7 +356,7 @@ export const CaptionOverlay = memo(function CaptionOverlay({ iframeRef }: Captio
|
|
|
303
356
|
origRotation: state.rotation,
|
|
304
357
|
};
|
|
305
358
|
},
|
|
306
|
-
[iframeRef, getCssScale],
|
|
359
|
+
[iframeRef, getCssScale, startSealedDrag],
|
|
307
360
|
);
|
|
308
361
|
|
|
309
362
|
// --- Rotate ---
|
|
@@ -314,6 +367,13 @@ export const CaptionOverlay = memo(function CaptionOverlay({ iframeRef }: Captio
|
|
|
314
367
|
(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);
|
|
315
368
|
const iframe = iframeRef.current;
|
|
316
369
|
if (!iframe) return;
|
|
370
|
+
if (previewFrameOpaque(iframe))
|
|
371
|
+
return startSealedDrag(
|
|
372
|
+
"rotate",
|
|
373
|
+
{ group: box.groupIndex, word: box.wordIndex },
|
|
374
|
+
box.segmentId,
|
|
375
|
+
e,
|
|
376
|
+
);
|
|
317
377
|
const wordEl = getWordEl(iframe, box.groupIndex, box.wordIndex);
|
|
318
378
|
const win = iframe.contentWindow;
|
|
319
379
|
if (!wordEl || !win) return;
|
|
@@ -329,7 +389,7 @@ export const CaptionOverlay = memo(function CaptionOverlay({ iframeRef }: Captio
|
|
|
329
389
|
origScale: state.scale,
|
|
330
390
|
};
|
|
331
391
|
},
|
|
332
|
-
[iframeRef],
|
|
392
|
+
[iframeRef, startSealedDrag],
|
|
333
393
|
);
|
|
334
394
|
|
|
335
395
|
const getIframeWin = useCallback((): Window | null => {
|
|
@@ -343,34 +403,29 @@ export const CaptionOverlay = memo(function CaptionOverlay({ iframeRef }: Captio
|
|
|
343
403
|
// --- Unified pointer move ---
|
|
344
404
|
const handlePointerMove = useCallback(
|
|
345
405
|
(e: React.PointerEvent) => {
|
|
406
|
+
const sealed = sealedDragRef.current;
|
|
407
|
+
if (sealed) return moveSealedDrag(sealed, e.clientX, e.clientY, getCssScale());
|
|
346
408
|
const i = interactionRef.current;
|
|
347
409
|
if (!i) return;
|
|
348
410
|
const win = getIframeWin();
|
|
349
411
|
if (!win) return;
|
|
350
412
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
const dx = (e.clientX - i.startMX) / cssScale;
|
|
354
|
-
const dy = (e.clientY - i.startMY) / cssScale;
|
|
355
|
-
writeTransform(i.wordEl, win, i.origTX + dx, i.origTY + dy, i.origScale, i.origRotation);
|
|
356
|
-
} else if (i.type === "scale") {
|
|
357
|
-
const cx = i.startMX - i.startDxFromCenter;
|
|
358
|
-
const startDist = Math.abs(i.startDxFromCenter);
|
|
359
|
-
const currentDist = Math.abs(e.clientX - cx);
|
|
360
|
-
const factor = startDist > 5 ? currentDist / startDist : 1;
|
|
361
|
-
const newScale = Math.max(0.1, i.origScale * factor);
|
|
362
|
-
writeTransform(i.wordEl, win, i.origTX, i.origTY, newScale, i.origRotation);
|
|
363
|
-
} else if (i.type === "rotate") {
|
|
364
|
-
const dx = e.clientX - i.startMX;
|
|
365
|
-
const delta = (dx / 200) * 90;
|
|
366
|
-
writeTransform(i.wordEl, win, i.origTX, i.origTY, i.origScale, i.origRotation + delta);
|
|
367
|
-
}
|
|
413
|
+
const t = dragTransform(i, e.clientX, e.clientY, getCssScale());
|
|
414
|
+
writeTransform(i.wordEl, win, t.x, t.y, t.scale, t.rotation);
|
|
368
415
|
},
|
|
369
416
|
[getCssScale, getIframeWin],
|
|
370
417
|
);
|
|
371
418
|
|
|
372
419
|
// --- Unified pointer up — sync back to store ---
|
|
373
420
|
const handlePointerUp = useCallback(() => {
|
|
421
|
+
const sealed = sealedDragRef.current;
|
|
422
|
+
if (sealed) {
|
|
423
|
+
sealedDragRef.current = null;
|
|
424
|
+
void sealed.last.then(
|
|
425
|
+
(t) => t && liveRef.current && storeStyle(sealed.segmentId, transformStyle(t)),
|
|
426
|
+
);
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
374
429
|
const i = interactionRef.current;
|
|
375
430
|
if (i) {
|
|
376
431
|
const win = getIframeWin();
|