@hyperframes/studio 0.9.59 → 0.9.61
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-Cm0hYGm2.js} +1 -1
- package/dist/assets/{index-Bxh5lW0C.js → index-BGrNWeLK.js} +199 -199
- package/dist/assets/{index--dcfSUzI.js → index-REqr_dLu.js} +1 -1
- package/dist/assets/{pausedVideoDecoder-BKym1jA6.js → pausedVideoDecoder-DqLDSq8J.js} +1 -1
- package/dist/{chunk-5EEM5WO4.js → chunk-3KCEIESB.js} +1 -1
- package/dist/{chunk-G6FJSL7X.js → chunk-JTUKMELR.js} +34 -6
- package/dist/index.d.ts +28 -1
- package/dist/index.html +1 -1
- package/dist/index.js +689 -177
- 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/NLEPreview.test.ts +24 -0
- package/src/components/nle/NLEPreview.tsx +2 -6
- package/src/components/nle/previewStage.ts +11 -1
- 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/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/player/hooks/useShadowPreviewReload.ts +7 -0
- package/src/player/hooks/useTimelinePlayer.shadowReload.test.ts +20 -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
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
// DOM helpers for CaptionOverlay — word box reading, transform I/O, wrapper management
|
|
2
|
+
import {
|
|
3
|
+
isPlainRecord,
|
|
4
|
+
MAX_CAPTION_TRANSFORM,
|
|
5
|
+
MAX_DESCRIBE_HANDLES,
|
|
6
|
+
type EditingParams,
|
|
7
|
+
} from "@hyperframes/core/runtime/editing-port";
|
|
8
|
+
import { previewFrameOpaque, previewRequest } from "../../player/lib/previewChannel";
|
|
2
9
|
|
|
3
10
|
export interface WordBox {
|
|
4
11
|
segmentId: string;
|
|
@@ -11,6 +18,34 @@ export interface WordBox {
|
|
|
11
18
|
height: number;
|
|
12
19
|
}
|
|
13
20
|
|
|
21
|
+
/** Maps a box in the frame's CSS pixels into the overlay's. */
|
|
22
|
+
function overlayPlacement(iframe: HTMLIFrameElement, overlayEl: HTMLElement) {
|
|
23
|
+
const iframeDisplayRect = iframe.getBoundingClientRect();
|
|
24
|
+
const overlayRect = overlayEl.getBoundingClientRect();
|
|
25
|
+
const nativeW = parseFloat(iframe.style.width) || iframeDisplayRect.width;
|
|
26
|
+
const cssScale = iframeDisplayRect.width / nativeW;
|
|
27
|
+
const offsetX = iframeDisplayRect.left - overlayRect.left;
|
|
28
|
+
const offsetY = iframeDisplayRect.top - overlayRect.top;
|
|
29
|
+
return (x: number, y: number, width: number, height: number) => ({
|
|
30
|
+
x: x * cssScale + offsetX,
|
|
31
|
+
y: y * cssScale + offsetY,
|
|
32
|
+
width: width * cssScale,
|
|
33
|
+
height: height * cssScale,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function splitIntoSpans(doc: Document, text: string, into: HTMLElement[]): DocumentFragment {
|
|
38
|
+
const frag = doc.createDocumentFragment();
|
|
39
|
+
for (const word of text.split(/\s+/).filter(Boolean)) {
|
|
40
|
+
const span = doc.createElement("span");
|
|
41
|
+
span.textContent = word + " ";
|
|
42
|
+
span.style.display = "inline";
|
|
43
|
+
frag.appendChild(span);
|
|
44
|
+
into.push(span);
|
|
45
|
+
}
|
|
46
|
+
return frag;
|
|
47
|
+
}
|
|
48
|
+
|
|
14
49
|
export function readWordBoxes(
|
|
15
50
|
iframe: HTMLIFrameElement,
|
|
16
51
|
model: {
|
|
@@ -29,13 +64,7 @@ export function readWordBoxes(
|
|
|
29
64
|
}
|
|
30
65
|
if (!doc || !win) return [];
|
|
31
66
|
|
|
32
|
-
const
|
|
33
|
-
const overlayRect = overlayEl.getBoundingClientRect();
|
|
34
|
-
const nativeW = parseFloat(iframe.style.width) || iframeDisplayRect.width;
|
|
35
|
-
const cssScale = iframeDisplayRect.width / nativeW;
|
|
36
|
-
const offsetX = iframeDisplayRect.left - overlayRect.left;
|
|
37
|
-
const offsetY = iframeDisplayRect.top - overlayRect.top;
|
|
38
|
-
|
|
67
|
+
const place = overlayPlacement(iframe, overlayEl);
|
|
39
68
|
const groupEls = doc.querySelectorAll<HTMLElement>(".caption-group");
|
|
40
69
|
const boxes: WordBox[] = [];
|
|
41
70
|
|
|
@@ -60,29 +89,14 @@ export function readWordBoxes(
|
|
|
60
89
|
if (resolvedWordEls.length === 0 && groupEl.textContent?.trim()) {
|
|
61
90
|
const textNode = groupEl.childNodes[0];
|
|
62
91
|
if (textNode && textNode.nodeType === Node.TEXT_NODE) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
span.textContent = word + " ";
|
|
68
|
-
span.style.display = "inline";
|
|
69
|
-
frag.appendChild(span);
|
|
70
|
-
resolvedWordEls.push(span);
|
|
71
|
-
}
|
|
72
|
-
groupEl.replaceChild(frag, textNode);
|
|
92
|
+
groupEl.replaceChild(
|
|
93
|
+
splitIntoSpans(doc, textNode.textContent || "", resolvedWordEls),
|
|
94
|
+
textNode,
|
|
95
|
+
);
|
|
73
96
|
} else {
|
|
74
97
|
const singleSpan = groupEl.querySelector<HTMLElement>(":scope > span");
|
|
75
98
|
if (singleSpan && singleSpan.textContent?.trim()) {
|
|
76
|
-
|
|
77
|
-
const frag = doc.createDocumentFragment();
|
|
78
|
-
for (const word of words) {
|
|
79
|
-
const span = doc.createElement("span");
|
|
80
|
-
span.textContent = word + " ";
|
|
81
|
-
span.style.display = "inline";
|
|
82
|
-
frag.appendChild(span);
|
|
83
|
-
resolvedWordEls.push(span);
|
|
84
|
-
}
|
|
85
|
-
singleSpan.replaceWith(frag);
|
|
99
|
+
singleSpan.replaceWith(splitIntoSpans(doc, singleSpan.textContent, resolvedWordEls));
|
|
86
100
|
}
|
|
87
101
|
}
|
|
88
102
|
}
|
|
@@ -96,10 +110,7 @@ export function readWordBoxes(
|
|
|
96
110
|
groupId,
|
|
97
111
|
groupIndex: gi,
|
|
98
112
|
wordIndex: wi,
|
|
99
|
-
|
|
100
|
-
y: rect.top * cssScale + offsetY,
|
|
101
|
-
width: rect.width * cssScale,
|
|
102
|
-
height: rect.height * cssScale,
|
|
113
|
+
...place(rect.left, rect.top, rect.width, rect.height),
|
|
103
114
|
});
|
|
104
115
|
}
|
|
105
116
|
}
|
|
@@ -237,6 +248,17 @@ export function applyCaptionModelToIframe(model: {
|
|
|
237
248
|
}): void {
|
|
238
249
|
const iframe = registeredIframe?.current;
|
|
239
250
|
if (!iframe) return;
|
|
251
|
+
if (previewFrameOpaque(iframe)) {
|
|
252
|
+
model.groupOrder.forEach((groupId, group) =>
|
|
253
|
+
model.groups.get(groupId)?.segmentIds.forEach((segmentId, word) => {
|
|
254
|
+
const s = model.segments.get(segmentId)?.style;
|
|
255
|
+
if (!s) return;
|
|
256
|
+
const set = { x: s.x ?? 0, y: s.y ?? 0, scale: s.scaleX ?? 1, rotation: s.rotation ?? 0 };
|
|
257
|
+
void frameWordTransform(iframe, { group, word, set });
|
|
258
|
+
}),
|
|
259
|
+
);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
240
262
|
let win: Window | null = null;
|
|
241
263
|
try {
|
|
242
264
|
win = iframe.contentWindow;
|
|
@@ -260,8 +282,10 @@ export function applyCaptionModelToIframe(model: {
|
|
|
260
282
|
|
|
261
283
|
/** Compute style deltas from the current wrapper transform — used by syncToStore in the overlay. */
|
|
262
284
|
export function computeTransformStyle(el: HTMLElement, iframeWin: Window): Record<string, number> {
|
|
263
|
-
|
|
264
|
-
|
|
285
|
+
return transformStyle(readGsapTransform(getOrCreateWrapper(el), iframeWin));
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export function transformStyle({ x, y, scale, rotation }: WordTransform): Record<string, number> {
|
|
265
289
|
const style: Record<string, number> = {};
|
|
266
290
|
if (Math.abs(x) > 0.5) style.x = x;
|
|
267
291
|
if (Math.abs(y) > 0.5) style.y = y;
|
|
@@ -272,3 +296,265 @@ export function computeTransformStyle(el: HTMLElement, iframeWin: Window): Recor
|
|
|
272
296
|
if (Math.abs(rotation) > 0.1) style.rotation = rotation;
|
|
273
297
|
return style;
|
|
274
298
|
}
|
|
299
|
+
|
|
300
|
+
interface WordTransform {
|
|
301
|
+
x: number;
|
|
302
|
+
y: number;
|
|
303
|
+
scale: number;
|
|
304
|
+
rotation: number;
|
|
305
|
+
}
|
|
306
|
+
type WordEntry = EditingParams<"caption-transform">["entries"][number];
|
|
307
|
+
interface FrameWord {
|
|
308
|
+
transform: WordTransform;
|
|
309
|
+
rect: { x: number; y: number; width: number; height: number };
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const allFinite = (value: unknown, keys: string[]) =>
|
|
313
|
+
isPlainRecord(value) && keys.every((key) => Number.isFinite(value[key]));
|
|
314
|
+
|
|
315
|
+
// The frame's own write bound: a larger reply, once stored, would make every later write to the word refused.
|
|
316
|
+
const allBounded = (value: unknown, keys: string[]) =>
|
|
317
|
+
isPlainRecord(value) &&
|
|
318
|
+
keys.every(
|
|
319
|
+
(key) => Number.isFinite(value[key]) && Math.abs(value[key] as number) <= MAX_CAPTION_TRANSFORM,
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
function readFrameWord(value: unknown): FrameWord | null {
|
|
323
|
+
if (!isPlainRecord(value)) return null;
|
|
324
|
+
const ok =
|
|
325
|
+
allBounded(value.transform, ["x", "y", "scale", "rotation"]) &&
|
|
326
|
+
allFinite(value.rect, ["x", "y", "width", "height"]);
|
|
327
|
+
return ok ? (value as unknown as FrameWord) : null;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export function findCaptionWord(
|
|
331
|
+
model: { groupOrder: string[]; groups: Map<string, { segmentIds: string[] }> },
|
|
332
|
+
segmentId: string,
|
|
333
|
+
): { group: number; word: number } | null {
|
|
334
|
+
for (let group = 0; group < model.groupOrder.length; group++) {
|
|
335
|
+
const word = model.groups.get(model.groupOrder[group])?.segmentIds.indexOf(segmentId) ?? -1;
|
|
336
|
+
if (word >= 0) return { group, word };
|
|
337
|
+
}
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/** `readWordBoxes` for a frame Studio cannot read; null when its runtime does not answer. */
|
|
342
|
+
export async function readFrameWordBoxes(
|
|
343
|
+
iframe: HTMLIFrameElement,
|
|
344
|
+
model: { groupOrder: string[]; groups: Map<string, { segmentIds: string[] }> },
|
|
345
|
+
overlayEl: HTMLElement,
|
|
346
|
+
): Promise<WordBox[] | null> {
|
|
347
|
+
const words = model.groupOrder.map((id) => model.groups.get(id)?.segmentIds.length ?? 0);
|
|
348
|
+
const reply = await previewRequest(iframe, "caption-words", { words });
|
|
349
|
+
const boxes: unknown = reply?.boxes;
|
|
350
|
+
if (!Array.isArray(boxes)) return null;
|
|
351
|
+
const place = overlayPlacement(iframe, overlayEl);
|
|
352
|
+
return boxes.flatMap((box: unknown): WordBox[] => {
|
|
353
|
+
if (!isPlainRecord(box) || !allFinite(box.rect, ["x", "y", "width", "height"])) return [];
|
|
354
|
+
const { group, word } = box;
|
|
355
|
+
if (!Number.isSafeInteger(group) || !Number.isSafeInteger(word)) return [];
|
|
356
|
+
const groupId = model.groupOrder[group as number];
|
|
357
|
+
const segmentId = groupId && model.groups.get(groupId)?.segmentIds[word as number];
|
|
358
|
+
if (!segmentId) return [];
|
|
359
|
+
const { x, y, width, height } = box.rect as FrameWord["rect"];
|
|
360
|
+
const at = place(x, y, width, height);
|
|
361
|
+
return [{ segmentId, groupId, groupIndex: group as number, wordIndex: word as number, ...at }];
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
type Op = { entry: WordEntry; done: Array<(word: FrameWord | null) => void> };
|
|
366
|
+
const transformQueues = new WeakMap<HTMLIFrameElement, { ops: Op[]; sending: boolean }>();
|
|
367
|
+
|
|
368
|
+
function sendTransforms(iframe: HTMLIFrameElement, queue: { ops: Op[]; sending: boolean }) {
|
|
369
|
+
if (queue.sending || !queue.ops.length) return;
|
|
370
|
+
const ops = queue.ops.splice(0, MAX_DESCRIBE_HANDLES);
|
|
371
|
+
queue.sending = true;
|
|
372
|
+
const entries = ops.map((op) => op.entry);
|
|
373
|
+
void previewRequest(iframe, "caption-transform", { entries })
|
|
374
|
+
.then((reply) => {
|
|
375
|
+
const words: unknown = reply?.words;
|
|
376
|
+
ops.forEach((op, i) => {
|
|
377
|
+
const word = Array.isArray(words) ? readFrameWord(words[i]) : null;
|
|
378
|
+
op.done.forEach((done) => done(word));
|
|
379
|
+
});
|
|
380
|
+
})
|
|
381
|
+
.finally(() => {
|
|
382
|
+
queue.sending = false;
|
|
383
|
+
sendTransforms(iframe, queue);
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/** One request in flight per frame; a waiting write to the same word takes the later one's parts. */
|
|
388
|
+
export function frameWordTransform(
|
|
389
|
+
iframe: HTMLIFrameElement,
|
|
390
|
+
entry: WordEntry,
|
|
391
|
+
): Promise<FrameWord | null> {
|
|
392
|
+
let queue = transformQueues.get(iframe);
|
|
393
|
+
if (!queue) transformQueues.set(iframe, (queue = { ops: [], sending: false }));
|
|
394
|
+
const { ops } = queue;
|
|
395
|
+
const promise = new Promise<FrameWord | null>((resolve) => {
|
|
396
|
+
const last = ops[ops.length - 1];
|
|
397
|
+
const sameWord = last?.entry.group === entry.group && last.entry.word === entry.word;
|
|
398
|
+
if (last && sameWord && last.entry.set && entry.set) {
|
|
399
|
+
last.entry = { ...entry, set: { ...last.entry.set, ...entry.set } };
|
|
400
|
+
last.done.push(resolve);
|
|
401
|
+
} else ops.push({ entry, done: [resolve] });
|
|
402
|
+
});
|
|
403
|
+
sendTransforms(iframe, queue);
|
|
404
|
+
return promise;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/** What a drag knows from its press: where it started and the word's transform then. */
|
|
408
|
+
export type DragStart =
|
|
409
|
+
| {
|
|
410
|
+
type: "move";
|
|
411
|
+
startMX: number;
|
|
412
|
+
startMY: number;
|
|
413
|
+
origTX: number;
|
|
414
|
+
origTY: number;
|
|
415
|
+
origScale: number;
|
|
416
|
+
origRotation: number;
|
|
417
|
+
}
|
|
418
|
+
| {
|
|
419
|
+
type: "scale";
|
|
420
|
+
startMX: number;
|
|
421
|
+
startDxFromCenter: number;
|
|
422
|
+
origTX: number;
|
|
423
|
+
origTY: number;
|
|
424
|
+
origScale: number;
|
|
425
|
+
origRotation: number;
|
|
426
|
+
}
|
|
427
|
+
| {
|
|
428
|
+
type: "rotate";
|
|
429
|
+
startMX: number;
|
|
430
|
+
origTX: number;
|
|
431
|
+
origTY: number;
|
|
432
|
+
origRotation: number;
|
|
433
|
+
origScale: number;
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
/** The word's transform with the pointer at (`clientX`, `clientY`). */
|
|
437
|
+
export function dragTransform(
|
|
438
|
+
i: DragStart,
|
|
439
|
+
clientX: number,
|
|
440
|
+
clientY: number,
|
|
441
|
+
cssScale: number,
|
|
442
|
+
): WordTransform {
|
|
443
|
+
const orig = { x: i.origTX, y: i.origTY, scale: i.origScale, rotation: i.origRotation };
|
|
444
|
+
if (i.type === "move") {
|
|
445
|
+
const dx = (clientX - i.startMX) / cssScale;
|
|
446
|
+
const dy = (clientY - i.startMY) / cssScale;
|
|
447
|
+
return { ...orig, x: i.origTX + dx, y: i.origTY + dy };
|
|
448
|
+
}
|
|
449
|
+
if (i.type === "scale") {
|
|
450
|
+
const cx = i.startMX - i.startDxFromCenter;
|
|
451
|
+
const startDist = Math.abs(i.startDxFromCenter);
|
|
452
|
+
const currentDist = Math.abs(clientX - cx);
|
|
453
|
+
const factor = startDist > 5 ? currentDist / startDist : 1;
|
|
454
|
+
return { ...orig, scale: Math.max(0.1, i.origScale * factor) };
|
|
455
|
+
}
|
|
456
|
+
const dx = clientX - i.startMX;
|
|
457
|
+
return { ...orig, rotation: i.origRotation + (dx / 200) * 90 };
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/** A drag on a frame Studio cannot read: its press read lands later, and moves wait for it. */
|
|
461
|
+
export interface SealedDrag {
|
|
462
|
+
iframe: HTMLIFrameElement;
|
|
463
|
+
word: { group: number; word: number };
|
|
464
|
+
segmentId: string;
|
|
465
|
+
start: Promise<DragStart | null>;
|
|
466
|
+
/** The word's transform once the latest write lands. */
|
|
467
|
+
last: Promise<WordTransform | null>;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
const restOf = (drag: DragStart | null): WordTransform | null =>
|
|
471
|
+
drag && { x: drag.origTX, y: drag.origTY, scale: drag.origScale, rotation: drag.origRotation };
|
|
472
|
+
|
|
473
|
+
/** The drag a press starts from the word the frame reports; `left` is the frame's left edge on screen. */
|
|
474
|
+
function toDragStart(
|
|
475
|
+
type: DragStart["type"],
|
|
476
|
+
{ transform: t, rect }: FrameWord,
|
|
477
|
+
press: { startMX: number; startMY: number; cssScale: number; left: number },
|
|
478
|
+
): DragStart {
|
|
479
|
+
const { startMX, startMY, cssScale, left } = press;
|
|
480
|
+
const orig = { origTX: t.x, origTY: t.y, origScale: t.scale, origRotation: t.rotation };
|
|
481
|
+
if (type === "move") return { type, startMX, startMY, ...orig };
|
|
482
|
+
if (type === "rotate") return { type, startMX, ...orig };
|
|
483
|
+
const boxCenterX = rect.x * cssScale + left + (rect.width * cssScale) / 2;
|
|
484
|
+
return { type, startMX, startDxFromCenter: startMX - boxCenterX, ...orig };
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/** Moves a frame's word by (`dx`, `dy`) from where the frame has it now. */
|
|
488
|
+
async function nudgeFrameWord(
|
|
489
|
+
iframe: HTMLIFrameElement,
|
|
490
|
+
word: { group: number; word: number },
|
|
491
|
+
dx: number,
|
|
492
|
+
dy: number,
|
|
493
|
+
): Promise<FrameWord | null> {
|
|
494
|
+
const now = await frameWordTransform(iframe, word);
|
|
495
|
+
if (!now) return null;
|
|
496
|
+
const { x, y } = now.transform;
|
|
497
|
+
return frameWordTransform(iframe, { ...word, set: { x: x + dx, y: y + dy } });
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/** Nudges run one after another, so quick repeats all count; none starts or stores once `live` is false. */
|
|
501
|
+
export function sealedNudger(
|
|
502
|
+
live: () => boolean,
|
|
503
|
+
onMoved: (segmentId: string, transform: WordTransform) => void,
|
|
504
|
+
) {
|
|
505
|
+
let nudging = Promise.resolve();
|
|
506
|
+
return (
|
|
507
|
+
iframe: HTMLIFrameElement,
|
|
508
|
+
model: Parameters<typeof findCaptionWord>[0],
|
|
509
|
+
segmentIds: Iterable<string>,
|
|
510
|
+
dx: number,
|
|
511
|
+
dy: number,
|
|
512
|
+
): Promise<void> => {
|
|
513
|
+
for (const segmentId of segmentIds) {
|
|
514
|
+
const word = findCaptionWord(model, segmentId);
|
|
515
|
+
if (!word) continue;
|
|
516
|
+
nudging = nudging.then(async () => {
|
|
517
|
+
if (!live()) return;
|
|
518
|
+
const moved = await nudgeFrameWord(iframe, word, dx, dy);
|
|
519
|
+
if (moved && live()) onMoved(segmentId, moved.transform);
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
return nudging;
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/** Draws the drag at the pointer once the press read lands; `last` follows the newest write. */
|
|
527
|
+
export function moveSealedDrag(
|
|
528
|
+
drag: SealedDrag,
|
|
529
|
+
clientX: number,
|
|
530
|
+
clientY: number,
|
|
531
|
+
cssScale: number,
|
|
532
|
+
) {
|
|
533
|
+
drag.last = drag.start.then(async (start) => {
|
|
534
|
+
if (!start) return null;
|
|
535
|
+
const set = dragTransform(start, clientX, clientY, cssScale);
|
|
536
|
+
return (await frameWordTransform(drag.iframe, { ...drag.word, set }))?.transform ?? null;
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/** Puts the word back where the press found it. */
|
|
541
|
+
export function restoreSealedDrag(drag: SealedDrag): void {
|
|
542
|
+
void drag.start.then((start) => {
|
|
543
|
+
const set = restOf(start);
|
|
544
|
+
if (set) void frameWordTransform(drag.iframe, { ...drag.word, set });
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/** A press on a word of a frame Studio cannot read; moves wait for the frame's answer. */
|
|
549
|
+
export function pressSealedDrag(
|
|
550
|
+
iframe: HTMLIFrameElement,
|
|
551
|
+
type: DragStart["type"],
|
|
552
|
+
word: { group: number; word: number },
|
|
553
|
+
segmentId: string,
|
|
554
|
+
press: { startMX: number; startMY: number; cssScale: number; left: number },
|
|
555
|
+
): SealedDrag {
|
|
556
|
+
const start = frameWordTransform(iframe, word).then(
|
|
557
|
+
(read) => read && toDragStart(type, read, press),
|
|
558
|
+
);
|
|
559
|
+
return { iframe, word, segmentId, start, last: start.then(restOf) };
|
|
560
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { memo, useCallback, useState } from "react";
|
|
2
|
+
import { previewFrameOpaque } from "../../player/lib/previewChannel";
|
|
2
3
|
import { useCaptionStore } from "../store";
|
|
3
4
|
import type { CaptionStyle } from "../types";
|
|
4
5
|
import { CaptionAnimationPanel } from "./CaptionAnimationPanel";
|
|
5
6
|
import { Section, Row, NumberField } from "./shared";
|
|
7
|
+
import { findCaptionWord, frameWordTransform } from "./CaptionOverlayUtils";
|
|
6
8
|
|
|
7
9
|
/** True when the given style key differs across the selected segments. */
|
|
8
10
|
function isMixedValue(
|
|
@@ -78,6 +80,21 @@ export const CaptionPropertyPanel = memo(function CaptionPropertyPanel({
|
|
|
78
80
|
(updates: Partial<CaptionStyle>) => {
|
|
79
81
|
const iframe = iframeRef.current;
|
|
80
82
|
if (!iframe || !model) return;
|
|
83
|
+
if (previewFrameOpaque(iframe)) {
|
|
84
|
+
const parts = {
|
|
85
|
+
x: updates.x,
|
|
86
|
+
y: updates.y,
|
|
87
|
+
scale: updates.scaleX,
|
|
88
|
+
rotation: updates.rotation,
|
|
89
|
+
};
|
|
90
|
+
const set = Object.fromEntries(Object.entries(parts).filter(([, v]) => v !== undefined));
|
|
91
|
+
if (Object.keys(set).length === 0) return;
|
|
92
|
+
for (const segId of selectedSegmentIds) {
|
|
93
|
+
const word = findCaptionWord(model, segId);
|
|
94
|
+
if (word) void frameWordTransform(iframe, { ...word, set });
|
|
95
|
+
}
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
81
98
|
let doc: Document | null = null;
|
|
82
99
|
try {
|
|
83
100
|
doc = iframe.contentDocument;
|
|
@@ -4,7 +4,7 @@ import { act, createElement } from "react";
|
|
|
4
4
|
import { createRoot } from "react-dom/client";
|
|
5
5
|
import { afterEach, expect, it, vi } from "vitest";
|
|
6
6
|
// The frame's real runtime agent, serving the opaque frame from this document.
|
|
7
|
-
import {
|
|
7
|
+
import { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
|
|
8
8
|
import { installReactActEnvironment } from "../../hooks/domSelectionTestHarness";
|
|
9
9
|
import { detachedFakeIframe } from "../../player/hooks/timelinePlayerTestHarness";
|
|
10
10
|
import { usePreviewIframeStore } from "../../player/store/previewIframeStore";
|
|
@@ -91,7 +91,7 @@ function opaqueFrame() {
|
|
|
91
91
|
new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
|
|
92
92
|
),
|
|
93
93
|
} as unknown as Window;
|
|
94
|
-
const agent =
|
|
94
|
+
const agent = installMarkedEditingAgent(parent);
|
|
95
95
|
frame.postMessage = (data: unknown) =>
|
|
96
96
|
window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
|
|
97
97
|
closers.push(() => agent.dispose());
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
4
|
// The frame's real runtime agent, serving the opaque frame from this document.
|
|
5
|
-
import {
|
|
5
|
+
import { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
|
|
6
6
|
import { detachedFakeIframe } from "../../player/hooks/timelinePlayerTestHarness";
|
|
7
7
|
import { describePreviewElements, queryPreviewElements } from "../../player/lib/previewElements";
|
|
8
8
|
import { resolvePreviewSelection, standInFor } from "./previewSelection";
|
|
@@ -61,7 +61,7 @@ function opaqueFrame(): HTMLIFrameElement {
|
|
|
61
61
|
new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
|
|
62
62
|
),
|
|
63
63
|
} as unknown as Window;
|
|
64
|
-
const agent =
|
|
64
|
+
const agent = installMarkedEditingAgent(parent);
|
|
65
65
|
target.postMessage = (data: unknown) =>
|
|
66
66
|
window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
|
|
67
67
|
closers.push(() => agent.dispose());
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
4
|
// The frame's real runtime agent, serving the opaque frame from this document.
|
|
5
|
-
import {
|
|
5
|
+
import { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
|
|
6
6
|
import { makeSelection } from "../../hooks/domSelectionTestHarness";
|
|
7
7
|
import { computeDraggedGsapPosition } from "../../hooks/draggedGsapPosition";
|
|
8
8
|
import { watchPreviewFrame } from "../../player/lib/bridgePlayback";
|
|
@@ -100,7 +100,7 @@ function opaqueFrame() {
|
|
|
100
100
|
new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
|
|
101
101
|
),
|
|
102
102
|
} as unknown as Window;
|
|
103
|
-
const agent =
|
|
103
|
+
const agent = installMarkedEditingAgent(parent);
|
|
104
104
|
frame.postMessage = (data: unknown) =>
|
|
105
105
|
window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
|
|
106
106
|
closers.push(() => agent.dispose());
|
|
@@ -5,7 +5,7 @@ import { MAX_QUERY_MATCHES } from "@hyperframes/core/runtime/editing-port";
|
|
|
5
5
|
import { createRoot } from "react-dom/client";
|
|
6
6
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
7
7
|
// The frame's real runtime agent, serving the opaque frame from this document.
|
|
8
|
-
import {
|
|
8
|
+
import { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
|
|
9
9
|
import { installReactActEnvironment } from "../../hooks/domSelectionTestHarness";
|
|
10
10
|
import { watchPreviewFrame } from "../../player/lib/bridgePlayback";
|
|
11
11
|
import { getElementZIndex } from "../../player/lib/layerOrdering";
|
|
@@ -97,7 +97,7 @@ function opaqueFrame() {
|
|
|
97
97
|
new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
|
|
98
98
|
),
|
|
99
99
|
} as unknown as Window;
|
|
100
|
-
const agent =
|
|
100
|
+
const agent = installMarkedEditingAgent(parent);
|
|
101
101
|
frame.postMessage = (data: unknown) =>
|
|
102
102
|
window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
|
|
103
103
|
closers.push(() => agent.dispose());
|
|
@@ -4,7 +4,7 @@ import React, { act } from "react";
|
|
|
4
4
|
import { createRoot } from "react-dom/client";
|
|
5
5
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
6
|
// The frame's real runtime agent, serving the opaque frame from this document.
|
|
7
|
-
import {
|
|
7
|
+
import { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
|
|
8
8
|
import { makeSelection, installReactActEnvironment } from "../../hooks/domSelectionTestHarness";
|
|
9
9
|
import { watchPreviewFrame } from "../../player/lib/bridgePlayback";
|
|
10
10
|
import { queryPreviewElements } from "../../player/lib/previewElements";
|
|
@@ -131,7 +131,7 @@ function opaqueFrame() {
|
|
|
131
131
|
new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
|
|
132
132
|
),
|
|
133
133
|
} as unknown as Window;
|
|
134
|
-
const agent =
|
|
134
|
+
const agent = installMarkedEditingAgent(parent);
|
|
135
135
|
frame.postMessage = (data: unknown) =>
|
|
136
136
|
window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
|
|
137
137
|
closers.push(() => agent.dispose());
|
|
@@ -4,7 +4,7 @@ import React, { act } from "react";
|
|
|
4
4
|
import { createRoot } from "react-dom/client";
|
|
5
5
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
6
|
// The frame's real runtime agent, serving the opaque frame from this document.
|
|
7
|
-
import {
|
|
7
|
+
import { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
|
|
8
8
|
import {
|
|
9
9
|
getAllPreviewTargetsFromPointer,
|
|
10
10
|
getPreviewTargetFromPointer,
|
|
@@ -106,7 +106,7 @@ function opaqueFrame(): HTMLIFrameElement {
|
|
|
106
106
|
new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
|
|
107
107
|
),
|
|
108
108
|
} as unknown as Window;
|
|
109
|
-
const agent =
|
|
109
|
+
const agent = installMarkedEditingAgent(parent);
|
|
110
110
|
frame.postMessage = (data: unknown) =>
|
|
111
111
|
window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
|
|
112
112
|
closers.push(() => agent.dispose());
|
|
@@ -5,7 +5,7 @@ import { createRoot } from "react-dom/client";
|
|
|
5
5
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
6
6
|
import { EDITING_ELEMENT_HANDLE, MAX_ELEMENT_TEXT } from "@hyperframes/core/runtime/editing-port";
|
|
7
7
|
// The frame's real runtime agent, serving the opaque frame from this document.
|
|
8
|
-
import {
|
|
8
|
+
import { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
|
|
9
9
|
import {
|
|
10
10
|
findElementForSelection,
|
|
11
11
|
findElementForTimelineElement,
|
|
@@ -68,7 +68,7 @@ function opaqueFrame(): HTMLIFrameElement {
|
|
|
68
68
|
new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
|
|
69
69
|
),
|
|
70
70
|
} as unknown as Window;
|
|
71
|
-
const agent =
|
|
71
|
+
const agent = installMarkedEditingAgent(parent);
|
|
72
72
|
frame.postMessage = (data: unknown) =>
|
|
73
73
|
window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
|
|
74
74
|
closers.push(() => agent.dispose());
|