@hyperframes/studio 0.9.64 → 0.9.66
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-VGx6ow_e.js +573 -0
- package/dist/assets/{index-CVmmHGol.js → index-B8Xt_Oyw.js} +190 -186
- package/dist/assets/{index-DN167Uqf.js → index-BH18TdX9.js} +1 -1
- package/dist/assets/{pausedVideoDecoder-C8rhpGPx.js → pausedVideoDecoder-Bx3fGNkU.js} +1 -1
- package/dist/{chunk-VDDEXNVX.js → chunk-ESTBKVCB.js} +8 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.html +1 -1
- package/dist/index.js +1580 -882
- package/dist/player.js +1 -1
- package/package.json +8 -8
- package/src/captions/components/CaptionOverlay.sealed.test.ts +2 -25
- package/src/captions/hooks/useCaptionSync.ts +4 -1
- package/src/components/editor/LayersPanel.opaque.test.ts +4 -29
- package/src/components/editor/MotionPathOverlay.sealed.test.tsx +85 -0
- package/src/components/editor/MotionPathOverlay.tsx +26 -12
- package/src/components/editor/domEditOverlayCrop.ts +78 -15
- package/src/components/editor/domEditOverlayCropFrameLift.test.ts +64 -0
- package/src/components/editor/domEditOverlayStartGesture.ts +0 -14
- package/src/components/editor/gestureUndoRevert.ts +3 -6
- package/src/components/editor/gsapMoveSealedPreview.test.ts +247 -0
- package/src/components/editor/manualEditsSnapshot.ts +2 -0
- package/src/components/editor/manualOffsetDrag.ts +13 -18
- package/src/components/editor/plainTranslate.test.ts +22 -1
- package/src/components/editor/plainTranslate.ts +8 -6
- package/src/components/editor/previewDrafts.test.ts +13 -39
- package/src/components/editor/previewDrafts.ts +4 -0
- package/src/components/editor/previewGestureStartRead.test.ts +59 -32
- package/src/components/editor/previewGestureStartRead.ts +9 -0
- package/src/components/editor/previewLayers.test.ts +3 -20
- package/src/components/editor/previewOverlayRects.test.ts +3 -20
- package/src/components/editor/previewPointerTargets.test.ts +3 -20
- package/src/components/editor/previewSelection.test.ts +51 -35
- package/src/components/editor/previewSelection.ts +18 -0
- package/src/components/editor/useColorGradingController.sealed.test.ts +5 -30
- package/src/components/editor/useMotionPathData.reply.test.ts +40 -0
- package/src/components/editor/useMotionPathData.sealed.test.ts +57 -0
- package/src/components/editor/useMotionPathData.test.tsx +1 -1
- package/src/components/editor/useMotionPathData.ts +83 -33
- package/src/components/nle/CompositionBreadcrumb.tsx +2 -5
- package/src/components/nle/NLEContext.drillDown.test.ts +85 -0
- package/src/components/nle/NLEContext.tsx +21 -23
- package/src/components/nle/NLEPreview.test.ts +18 -3
- package/src/components/nle/NLEPreview.tsx +10 -1
- package/src/components/nle/audioSealedPreview.test.ts +5 -32
- package/src/components/panels/motionBlurPanelModel.sealed.test.ts +30 -0
- package/src/components/panels/motionBlurPanelModel.ts +37 -7
- package/src/hooks/appHotkeysDispatch.ts +38 -1
- package/src/hooks/domEditCommits.sealed.test.ts +191 -0
- package/src/hooks/domStyleCommit.ts +18 -7
- package/src/hooks/draggedGsapPosition.ts +20 -0
- package/src/hooks/gsapEditOutcome.ts +3 -0
- package/src/hooks/gsapFrameSnapshot.test.ts +113 -0
- package/src/hooks/gsapFrameSnapshot.ts +246 -0
- package/src/hooks/gsapParsedTween.ts +16 -9
- package/src/hooks/gsapResizeIntercept.ts +7 -2
- package/src/hooks/gsapRuntimeBridge.ts +4 -0
- package/src/hooks/gsapRuntimeKeyframes.ts +23 -15
- package/src/hooks/gsapShared.ts +4 -0
- package/src/hooks/gsapSnapshotReply.ts +105 -0
- package/src/hooks/useAppHotkeys.previewForwarding.test.tsx +134 -0
- package/src/hooks/useAppHotkeys.ts +36 -1
- package/src/hooks/useDomEditAttributeCommits.ts +43 -19
- package/src/hooks/useDomEditCommits.test.tsx +1 -1
- package/src/hooks/useDomEditPreviewSync.test.ts +36 -1
- package/src/hooks/useDomEditPreviewSync.ts +3 -3
- package/src/hooks/useEditorSave.ts +2 -1
- package/src/hooks/useEnableKeyframes.sealed.test.ts +70 -0
- package/src/hooks/useEnableKeyframes.ts +9 -2
- package/src/hooks/useGsapTweenCache.ts +9 -3
- package/src/hooks/usePreviewPersistence.ts +18 -11
- package/src/hooks/useSdkSession.lifecycle.test.tsx +1 -0
- package/src/hooks/useSdkSession.ts +2 -0
- package/src/hooks/useSlideshowTabState.test.ts +47 -3
- package/src/hooks/useSlideshowTabState.ts +32 -16
- package/src/player/hooks/timelinePlayerTestHarness.ts +2 -1
- package/src/player/hooks/usePlaybackKeyboard.ts +1 -1
- package/src/player/hooks/useTimelineSyncCallbacks.sealed.test.ts +2 -29
- package/src/player/lib/previewChannel.test.ts +10 -0
- package/src/player/lib/previewChannel.ts +9 -0
- package/src/player/lib/previewElements.test.ts +34 -1
- package/src/player/lib/previewElements.ts +101 -18
- package/src/player/lib/sealedPreviewFrame.test-helpers.ts +38 -0
- package/src/player/lib/timelineIframeHelpers.ts +1 -1
- package/src/telemetry/client.ts +4 -2
- package/src/telemetry/eventShape.test.ts +189 -0
- package/src/telemetry/eventShape.ts +192 -0
- package/src/utils/blockInstaller.test.ts +82 -48
- package/src/utils/blockInstaller.ts +6 -14
- package/src/utils/domEditSaveQueue.test.ts +12 -2
- package/src/utils/domEditSaveQueue.ts +4 -4
- package/src/utils/previewCompositionSize.test.ts +61 -0
- package/src/utils/previewCompositionSize.ts +21 -1
- package/src/utils/sdkEditTransaction.ts +6 -2
- package/src/utils/sdkResolverShadow.ts +16 -15
- package/src/utils/studioSaveDiagnostics.test.ts +21 -3
- package/src/utils/studioSaveDiagnostics.ts +71 -6
- package/src/utils/studioTelemetry.ts +6 -1
- package/dist/assets/hyperframes-player-mSF_GvRs.js +0 -573
- package/src/components/editor/motionPathHome.ts +0 -75
|
@@ -9,7 +9,12 @@ import { shouldIgnoreHistoryShortcut } from "../utils/studioHelpers";
|
|
|
9
9
|
import { canSplitElement } from "../utils/timelineElementSplit";
|
|
10
10
|
import { trackStudioEvent } from "../utils/studioTelemetry";
|
|
11
11
|
import { razorClaimsKey } from "../player/lib/playbackShortcuts";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
getStudioKeys,
|
|
14
|
+
keyHint,
|
|
15
|
+
matchesKey,
|
|
16
|
+
type StudioKeyAction,
|
|
17
|
+
} from "../player/components/studioShortcuts";
|
|
13
18
|
import { zoomTimelineToSelectedClips } from "../player/components/timelineZoomInput";
|
|
14
19
|
import { openAudioGainDialog } from "../player/components/audioGainDialogStore";
|
|
15
20
|
import type { LinkShortcutCallbacks } from "./linkShortcuts";
|
|
@@ -119,6 +124,38 @@ function dispatchClipboardKey(event: KeyboardEvent, cb: HotkeyCallbacks): boolea
|
|
|
119
124
|
return true;
|
|
120
125
|
}
|
|
121
126
|
|
|
127
|
+
/** Every action the dispatchers here and dispatchLinkShortcut answer: what a sealed preview forwards to them. */
|
|
128
|
+
export const APP_HOTKEY_ACTIONS = [
|
|
129
|
+
"undo",
|
|
130
|
+
"redo",
|
|
131
|
+
"redoAlt",
|
|
132
|
+
"tabCompositions",
|
|
133
|
+
"tabAssets",
|
|
134
|
+
"group",
|
|
135
|
+
"ungroup",
|
|
136
|
+
"copy",
|
|
137
|
+
"paste",
|
|
138
|
+
"cut",
|
|
139
|
+
"duplicate",
|
|
140
|
+
"zoomSelection",
|
|
141
|
+
"fullscreen",
|
|
142
|
+
"split",
|
|
143
|
+
"audioGain",
|
|
144
|
+
"razorTool",
|
|
145
|
+
"selectTool",
|
|
146
|
+
"selectLeftward",
|
|
147
|
+
"selectRightward",
|
|
148
|
+
"cancel",
|
|
149
|
+
"deleteSelected",
|
|
150
|
+
"deleteSelectedAlt",
|
|
151
|
+
"resetKeyframes",
|
|
152
|
+
"record",
|
|
153
|
+
"linkToggle",
|
|
154
|
+
"detachAudio",
|
|
155
|
+
"deleteLinked",
|
|
156
|
+
"deleteLinkedAlt",
|
|
157
|
+
] as const satisfies readonly StudioKeyAction[];
|
|
158
|
+
|
|
122
159
|
/** Exported for tests: the shortcuts that act on the editor, each read as a combo at event time. */
|
|
123
160
|
export function dispatchModifierKey(
|
|
124
161
|
event: KeyboardEvent,
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import { act, createElement } from "react";
|
|
4
|
+
import { createRoot } from "react-dom/client";
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
// The frame's real runtime agent, serving the opaque frame from this document.
|
|
7
|
+
import { installMarkedEditingAgent } from "../../../core/src/runtime/editingAgent.test-helpers";
|
|
8
|
+
import { detachedFakeIframe } from "../player/hooks/timelinePlayerTestHarness";
|
|
9
|
+
import {
|
|
10
|
+
findPreviewElementForSelection,
|
|
11
|
+
resolvePreviewSelection,
|
|
12
|
+
} from "../components/editor/previewSelection";
|
|
13
|
+
import type { DomEditSelection } from "../components/editor/domEditing";
|
|
14
|
+
import type { PersistDomEditOperations } from "./domEditCommitTypes";
|
|
15
|
+
import { commitDomStyles } from "./domStyleCommit";
|
|
16
|
+
import { useDomEditAttributeCommits } from "./useDomEditAttributeCommits";
|
|
17
|
+
|
|
18
|
+
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
19
|
+
|
|
20
|
+
const closers: Array<() => void> = [];
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
closers.splice(0).forEach((close) => close());
|
|
23
|
+
document.body.innerHTML = "";
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/** A frame Studio cannot read, whose runtime is the real editing agent over this document. */
|
|
27
|
+
function opaqueFrame(): HTMLIFrameElement {
|
|
28
|
+
const frame: Record<string, unknown> = {};
|
|
29
|
+
const iframe = detachedFakeIframe(frame);
|
|
30
|
+
Object.defineProperty(iframe, "contentDocument", { value: null });
|
|
31
|
+
Object.defineProperty(frame, "document", {
|
|
32
|
+
get: () => {
|
|
33
|
+
throw new DOMException("blocked", "SecurityError");
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
const parent = {
|
|
37
|
+
postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
|
|
38
|
+
window.dispatchEvent(
|
|
39
|
+
new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
|
|
40
|
+
),
|
|
41
|
+
} as unknown as Window;
|
|
42
|
+
const agent = installMarkedEditingAgent(parent);
|
|
43
|
+
frame.postMessage = (data: unknown) =>
|
|
44
|
+
window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
|
|
45
|
+
closers.push(() => agent.dispose());
|
|
46
|
+
return iframe;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const PATH = "index.html";
|
|
50
|
+
|
|
51
|
+
async function sealedCard(markup: string) {
|
|
52
|
+
document.body.innerHTML = markup;
|
|
53
|
+
const card = document.getElementById("card")!;
|
|
54
|
+
const iframe = opaqueFrame();
|
|
55
|
+
const target = { id: "card", sourceFile: PATH };
|
|
56
|
+
const found = await findPreviewElementForSelection(iframe, target, PATH);
|
|
57
|
+
const selection = await resolvePreviewSelection(iframe, found!, {
|
|
58
|
+
activeCompositionPath: PATH,
|
|
59
|
+
isMasterView: false,
|
|
60
|
+
skipSourceProbe: true,
|
|
61
|
+
});
|
|
62
|
+
return { card, iframe, selection: selection! };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Lets the port's request and the frame's reply land. */
|
|
66
|
+
const settle = () => act(() => new Promise((resolve) => setTimeout(resolve, 20)));
|
|
67
|
+
|
|
68
|
+
function styleContext(iframe: HTMLIFrameElement, persist: PersistDomEditOperations) {
|
|
69
|
+
return {
|
|
70
|
+
activeCompPath: PATH,
|
|
71
|
+
previewIframeRef: { current: iframe },
|
|
72
|
+
persistDomEditOperations: persist,
|
|
73
|
+
showToast: vi.fn(),
|
|
74
|
+
versions: new Map<string, symbol>(),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function attributeCommits(
|
|
79
|
+
iframe: HTMLIFrameElement,
|
|
80
|
+
selection: DomEditSelection,
|
|
81
|
+
persist: PersistDomEditOperations,
|
|
82
|
+
) {
|
|
83
|
+
let commits: ReturnType<typeof useDomEditAttributeCommits> | undefined;
|
|
84
|
+
function Harness() {
|
|
85
|
+
commits = useDomEditAttributeCommits({
|
|
86
|
+
activeCompPath: PATH,
|
|
87
|
+
previewIframeRef: { current: iframe },
|
|
88
|
+
showToast: vi.fn(),
|
|
89
|
+
domEditSelection: selection,
|
|
90
|
+
refreshDomEditSelectionFromPreview: vi.fn(),
|
|
91
|
+
persistDomEditOperations: persist,
|
|
92
|
+
});
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
act(() => createRoot(document.createElement("div")).render(createElement(Harness)));
|
|
96
|
+
return commits!;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
describe("DOM edit commits in a sealed preview", () => {
|
|
100
|
+
it("draws a style commit on the frame's element and saves it without a reload", async () => {
|
|
101
|
+
const { card, iframe, selection } = await sealedCard(`<div id="card">Hi</div>`);
|
|
102
|
+
const persist = vi.fn<PersistDomEditOperations>(async () => undefined);
|
|
103
|
+
const outcome = await commitDomStyles(styleContext(iframe, persist), selection, {
|
|
104
|
+
opacity: "0.5",
|
|
105
|
+
});
|
|
106
|
+
await settle();
|
|
107
|
+
expect(outcome.ok).toBe(true);
|
|
108
|
+
expect(card.style.opacity).toBe("0.5");
|
|
109
|
+
expect(persist.mock.calls[0]?.[2]).toMatchObject({ skipRefresh: true });
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("puts the frame's style back when the save fails", async () => {
|
|
113
|
+
const { card, iframe, selection } = await sealedCard(
|
|
114
|
+
`<div id="card" style="color: red">Hi</div>`,
|
|
115
|
+
);
|
|
116
|
+
const persist = vi.fn<PersistDomEditOperations>(async () => {
|
|
117
|
+
throw new Error("disk full");
|
|
118
|
+
});
|
|
119
|
+
await commitDomStyles(styleContext(iframe, persist), selection, { color: "blue" });
|
|
120
|
+
await settle();
|
|
121
|
+
expect(card.style.color).toBe("red");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("reloads a sealed frame for a font change, which it cannot load from Studio", async () => {
|
|
125
|
+
const { iframe, selection } = await sealedCard(`<div id="card">Hi</div>`);
|
|
126
|
+
const persist = vi.fn<PersistDomEditOperations>(async () => undefined);
|
|
127
|
+
await commitDomStyles(styleContext(iframe, persist), selection, { "font-family": "Inter" });
|
|
128
|
+
expect(persist.mock.calls[0]?.[2]).toMatchObject({ skipRefresh: false });
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("reloads when the frame no longer has the element to draw on", async () => {
|
|
132
|
+
const { card, iframe, selection } = await sealedCard(`<div id="card">Hi</div>`);
|
|
133
|
+
card.remove();
|
|
134
|
+
const persist = vi.fn<PersistDomEditOperations>(async () => undefined);
|
|
135
|
+
await commitDomStyles(styleContext(iframe, persist), selection, { opacity: "0.5" });
|
|
136
|
+
expect(persist.mock.calls[0]?.[2]).toMatchObject({ skipRefresh: false });
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("reloads when the frame refuses the edit", async () => {
|
|
140
|
+
const { card, iframe, selection } = await sealedCard(`<div id="card">Hi</div>`);
|
|
141
|
+
const persist = vi.fn<PersistDomEditOperations>(async () => undefined);
|
|
142
|
+
const tooLong = `"${"x".repeat(200_001)}"`;
|
|
143
|
+
await commitDomStyles(styleContext(iframe, persist), selection, {
|
|
144
|
+
"font-feature-settings": tooLong,
|
|
145
|
+
});
|
|
146
|
+
expect(persist.mock.calls[0]?.[2]).toMatchObject({ skipRefresh: false });
|
|
147
|
+
expect(card.style.fontFeatureSettings).toBe("");
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("draws data and HTML attribute commits on the frame's element", async () => {
|
|
151
|
+
const { card, iframe, selection } = await sealedCard(`<div id="card" data-volume="1">Hi</div>`);
|
|
152
|
+
const persist = vi.fn<PersistDomEditOperations>(async () => undefined);
|
|
153
|
+
const commits = attributeCommits(iframe, selection, persist);
|
|
154
|
+
await act(() => commits.handleDomAttributeQuietCommit("volume", "0.25"));
|
|
155
|
+
await act(() => commits.handleDomHtmlAttributeCommit("title", "Card"));
|
|
156
|
+
await settle();
|
|
157
|
+
expect(card.dataset.volume).toBe("0.25");
|
|
158
|
+
expect(card.getAttribute("title")).toBe("Card");
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("never puts back a value over a newer edit that saved", async () => {
|
|
162
|
+
const { card, iframe, selection } = await sealedCard(
|
|
163
|
+
`<div id="card" title="original">Hi</div>`,
|
|
164
|
+
);
|
|
165
|
+
let saves = 0;
|
|
166
|
+
const persist = vi.fn<PersistDomEditOperations>(async () => {
|
|
167
|
+
if (saves++ === 0) throw new Error("disk full");
|
|
168
|
+
});
|
|
169
|
+
const commits = attributeCommits(iframe, selection, persist);
|
|
170
|
+
await act(async () => {
|
|
171
|
+
const first = commits.handleDomHtmlAttributeCommit("title", "first");
|
|
172
|
+
for (let i = 0; i < 5; i++) await Promise.resolve();
|
|
173
|
+
await Promise.all([first, commits.handleDomHtmlAttributeCommit("title", "second")]);
|
|
174
|
+
});
|
|
175
|
+
await settle();
|
|
176
|
+
expect(card.getAttribute("title")).toBe("second");
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("puts the frame's attributes back when a batch save fails", async () => {
|
|
180
|
+
const { card, iframe, selection } = await sealedCard(
|
|
181
|
+
`<div id="card" data-start="1" data-duration="2">Hi</div>`,
|
|
182
|
+
);
|
|
183
|
+
const persist = vi.fn<PersistDomEditOperations>(async () => {
|
|
184
|
+
throw new Error("disk full");
|
|
185
|
+
});
|
|
186
|
+
const commits = attributeCommits(iframe, selection, persist);
|
|
187
|
+
await act(() => commits.handleDomAttributesCommit(selection, { start: "3", duration: "4" }));
|
|
188
|
+
await settle();
|
|
189
|
+
expect([card.dataset.start, card.dataset.duration]).toEqual(["1", "2"]);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
type DomEditSelection,
|
|
14
14
|
} from "../components/editor/domEditing";
|
|
15
15
|
import type { ImportedFontAsset } from "../components/editor/fontAssets";
|
|
16
|
+
import { editSealedSelection } from "../components/editor/previewSelection";
|
|
17
|
+
import { afterSealedDraw, type PreviewElementEdit } from "../player/lib/previewElements";
|
|
16
18
|
import type { PersistDomEditOperations } from "./domEditCommitTypes";
|
|
17
19
|
import { reportDomEditPersistFailure } from "./domEditPersistFailure";
|
|
18
20
|
import {
|
|
@@ -86,6 +88,7 @@ export async function commitDomStyles(
|
|
|
86
88
|
}
|
|
87
89
|
let editedElement: HTMLElement | null = null;
|
|
88
90
|
const previousInline = new Map<string, string>();
|
|
91
|
+
let sealedEdit: PreviewElementEdit | null = null;
|
|
89
92
|
|
|
90
93
|
return runReportedDomEditCommit({
|
|
91
94
|
capture: () => {
|
|
@@ -96,7 +99,12 @@ export async function commitDomStyles(
|
|
|
96
99
|
previousInline.set(property, el.style.getPropertyValue(property));
|
|
97
100
|
},
|
|
98
101
|
apply: () => {
|
|
99
|
-
if (!editedElement)
|
|
102
|
+
if (!editedElement) {
|
|
103
|
+
sealedEdit = editSealedSelection(previewIframeRef.current, selection, {
|
|
104
|
+
styles: liveStyles,
|
|
105
|
+
});
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
100
108
|
for (const [property, value] of liveStyles) editedElement.style.setProperty(property, value);
|
|
101
109
|
if (fontFamily !== undefined && doc) {
|
|
102
110
|
injectPreviewGoogleFont(doc, fontFamily);
|
|
@@ -104,14 +112,17 @@ export async function commitDomStyles(
|
|
|
104
112
|
}
|
|
105
113
|
},
|
|
106
114
|
persist: () =>
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
115
|
+
afterSealedDraw(sealedEdit, (drawn) =>
|
|
116
|
+
persistDomEditOperations(selection, operations, {
|
|
117
|
+
label: "Edit layer style",
|
|
118
|
+
// Live styles skip the reload; a sealed frame reloads to load a new font.
|
|
119
|
+
skipRefresh: drawn && !(sealedEdit && fontFamily !== undefined),
|
|
120
|
+
importedFont: importedFont ?? undefined,
|
|
121
|
+
}),
|
|
122
|
+
),
|
|
113
123
|
shouldRevert: ownsAny,
|
|
114
124
|
revert: () => {
|
|
125
|
+
sealedEdit?.restore(owned.filter(({ isLatest }) => isLatest()).map((o) => o.property));
|
|
115
126
|
const el = editedElement;
|
|
116
127
|
if (!el) return;
|
|
117
128
|
// ponytail: background-image fit styles are not reverted here.
|
|
@@ -37,6 +37,8 @@ export function readCssRotation(element: HTMLElement, withRotate = true): number
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
export const DRAG_MOVING_ATTR = "data-hf-drag-gsap-moving";
|
|
41
|
+
|
|
40
42
|
export interface DragStamp {
|
|
41
43
|
origX: number;
|
|
42
44
|
origY: number;
|
|
@@ -44,6 +46,23 @@ export interface DragStamp {
|
|
|
44
46
|
baseY: number;
|
|
45
47
|
at?: EditMoment;
|
|
46
48
|
frozen?: boolean;
|
|
49
|
+
moving?: true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Writes the gesture-start stamp `readDragStamp` reads. The member's JS values are re-stamped before the commit
|
|
53
|
+
* because a mid-gesture re-render can wipe these attributes, and without the base the drop re-adds the drag. */
|
|
54
|
+
export function stampGestureBase(
|
|
55
|
+
el: HTMLElement,
|
|
56
|
+
initialOffset: { x: number; y: number },
|
|
57
|
+
baseGsap: { x: number; y: number },
|
|
58
|
+
moving = false,
|
|
59
|
+
): void {
|
|
60
|
+
if (moving) el.setAttribute(DRAG_MOVING_ATTR, "");
|
|
61
|
+
else el.removeAttribute(DRAG_MOVING_ATTR);
|
|
62
|
+
el.setAttribute("data-hf-drag-gsap-base-x", String(baseGsap.x));
|
|
63
|
+
el.setAttribute("data-hf-drag-gsap-base-y", String(baseGsap.y));
|
|
64
|
+
el.setAttribute("data-hf-drag-initial-offset-x", String(initialOffset.x));
|
|
65
|
+
el.setAttribute("data-hf-drag-initial-offset-y", String(initialOffset.y));
|
|
47
66
|
}
|
|
48
67
|
|
|
49
68
|
/** The drag-start attributes as they are now; NaN for an absent base. */
|
|
@@ -55,6 +74,7 @@ export function readDragStamp(element: HTMLElement): DragStamp {
|
|
|
55
74
|
baseX: read("data-hf-drag-gsap-base-x"),
|
|
56
75
|
baseY: read("data-hf-drag-gsap-base-y"),
|
|
57
76
|
at: readEditMoment(element),
|
|
77
|
+
...(element.getAttribute(DRAG_MOVING_ATTR) !== null && { moving: true }),
|
|
58
78
|
};
|
|
59
79
|
}
|
|
60
80
|
|
|
@@ -27,6 +27,7 @@ export type GsapEditBlockDetail =
|
|
|
27
27
|
| "live-rotation-no-source-tween"
|
|
28
28
|
| "live-resize-no-source-tween"
|
|
29
29
|
| "zero-duration-tween"
|
|
30
|
+
| "frame-tweens-unreadable"
|
|
30
31
|
| PlayheadEditRefusal;
|
|
31
32
|
|
|
32
33
|
/** Why an edit at the playhead could not be written as keyframes of the file's tween. */
|
|
@@ -90,6 +91,8 @@ const GSAP_EDIT_DETAIL_COPY: Partial<Record<GsapEditBlockDetail, string>> = {
|
|
|
90
91
|
"array-step-computed": `${STEP_LIST} whose value comes from code, which Studio can't keep while it edits them. ${IN_CODE}`,
|
|
91
92
|
"array-step-relative": `${STEP_LIST} with a relative value (like "+=40"), which an edit would apply again. ${IN_CODE}`,
|
|
92
93
|
"array-step-random": `${STEP_LIST} with a random() value, which an edit would roll again. ${IN_CODE}`,
|
|
94
|
+
"frame-tweens-unreadable":
|
|
95
|
+
"This preview couldn't read the layer's animation, so Studio can't save the move. Move it in the Code tab.",
|
|
93
96
|
};
|
|
94
97
|
|
|
95
98
|
export function gsapEditBlockMessage(
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
4
|
+
|
|
5
|
+
const request = vi.hoisted(() => vi.fn());
|
|
6
|
+
vi.mock("../player/lib/previewChannel", () => {
|
|
7
|
+
const clients = new WeakMap<HTMLIFrameElement, object>();
|
|
8
|
+
return {
|
|
9
|
+
previewEditingClient: (iframe: HTMLIFrameElement) => {
|
|
10
|
+
if (!clients.has(iframe)) clients.set(iframe, {});
|
|
11
|
+
return clients.get(iframe);
|
|
12
|
+
},
|
|
13
|
+
previewFrameOpaque: () => true,
|
|
14
|
+
previewRequest: request,
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
import { usePlayerStore } from "../player/store/playerStore";
|
|
19
|
+
import { frameDocument, frameGsap, frameTimelines, settleGsapSnapshot } from "./gsapFrameSnapshot";
|
|
20
|
+
|
|
21
|
+
const HANDLE = "0123456789abcdef:1";
|
|
22
|
+
const tween = {
|
|
23
|
+
targets: [HANDLE],
|
|
24
|
+
vars: { x: 200 },
|
|
25
|
+
start: 0,
|
|
26
|
+
duration: 1,
|
|
27
|
+
from: false,
|
|
28
|
+
initted: true,
|
|
29
|
+
parsed: [{ p: "x", s: 0, c: 200 }],
|
|
30
|
+
parts: [],
|
|
31
|
+
};
|
|
32
|
+
const target = { handle: HANDLE, id: "box", className: "", values: { x: 120 } };
|
|
33
|
+
const snapshot = (over: Record<string, unknown> = {}) => ({
|
|
34
|
+
time: 0.5,
|
|
35
|
+
defaultEase: null,
|
|
36
|
+
timelines: [{ id: "main", time: 0.5, defaultEase: null, tweens: [tween] }],
|
|
37
|
+
targets: [target],
|
|
38
|
+
...over,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
afterEach(() => {
|
|
42
|
+
request.mockReset();
|
|
43
|
+
usePlayerStore.setState({ currentTime: 0, isPlaying: false });
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
async function readReply(reply: unknown, holds = true) {
|
|
47
|
+
usePlayerStore.setState({ currentTime: 0.5, isPlaying: false });
|
|
48
|
+
request.mockResolvedValue(reply);
|
|
49
|
+
const iframe = document.createElement("iframe");
|
|
50
|
+
await expect(settleGsapSnapshot(iframe)).resolves.toBe(holds);
|
|
51
|
+
return iframe;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
it("holds a well-formed reply", async () => {
|
|
55
|
+
const iframe = await readReply(snapshot());
|
|
56
|
+
|
|
57
|
+
expect(Object.keys(frameTimelines(iframe) ?? {})).toEqual(["main"]);
|
|
58
|
+
expect(frameDocument(iframe)?.getElementById("box")).not.toBeNull();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// fails without the fix: the frame's reply was used unchecked, so a malformed one threw or was held as is.
|
|
62
|
+
it.each([
|
|
63
|
+
["targets that are not a list", snapshot({ targets: null })],
|
|
64
|
+
[
|
|
65
|
+
"more targets than the frame may send",
|
|
66
|
+
snapshot({ targets: Array.from({ length: 513 }, () => target) }),
|
|
67
|
+
],
|
|
68
|
+
["a value that is not a number", snapshot({ targets: [{ ...target, values: { x: "7" } }] })],
|
|
69
|
+
[
|
|
70
|
+
"a tween start that is not finite",
|
|
71
|
+
snapshot({
|
|
72
|
+
timelines: [
|
|
73
|
+
{ id: "main", time: 0.5, defaultEase: null, tweens: [{ ...tween, start: Number.NaN }] },
|
|
74
|
+
],
|
|
75
|
+
}),
|
|
76
|
+
],
|
|
77
|
+
["a target that is not a handle", snapshot({ targets: [{ ...target, handle: "#box" }] })],
|
|
78
|
+
["an id past the text bound", snapshot({ targets: [{ ...target, id: "b".repeat(4_097) }] })],
|
|
79
|
+
["a reply that is not a record", "gsap"],
|
|
80
|
+
])("refuses %s and holds nothing", async (_name, reply) => {
|
|
81
|
+
const iframe = await readReply(reply, false);
|
|
82
|
+
|
|
83
|
+
expect(frameTimelines(iframe)).toBeNull();
|
|
84
|
+
expect(frameDocument(iframe)).toBeNull();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("keeps a timeline named __proto__ as a timeline, not the record's prototype", async () => {
|
|
88
|
+
const iframe = await readReply(
|
|
89
|
+
snapshot({ timelines: [{ id: "__proto__", time: 0.5, defaultEase: null, tweens: [tween] }] }),
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
expect(Object.keys(frameTimelines(iframe) ?? {})).toEqual(["__proto__"]);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// fails without the fix: a click waited on the read the first seek started, which holds that seek's time, so right
|
|
96
|
+
// after a second seek it found no GSAP values at the playhead and the add did nothing.
|
|
97
|
+
it("waits for a read at the playhead when a second seek lands while the first read is out", async () => {
|
|
98
|
+
usePlayerStore.setState({ currentTime: 0.5, isPlaying: false });
|
|
99
|
+
let answerFirst = (_reply: unknown) => {};
|
|
100
|
+
request.mockImplementationOnce(() => new Promise((resolve) => (answerFirst = resolve)));
|
|
101
|
+
const atOne = { id: "main", time: 1, defaultEase: null, tweens: [tween] };
|
|
102
|
+
request.mockResolvedValueOnce(snapshot({ time: 1, timelines: [atOne] }));
|
|
103
|
+
const iframe = document.createElement("iframe");
|
|
104
|
+
|
|
105
|
+
const first = settleGsapSnapshot(iframe);
|
|
106
|
+
usePlayerStore.setState({ currentTime: 1 });
|
|
107
|
+
const click = settleGsapSnapshot(iframe);
|
|
108
|
+
answerFirst(snapshot());
|
|
109
|
+
await Promise.all([first, click]);
|
|
110
|
+
|
|
111
|
+
expect(request).toHaveBeenCalledTimes(2);
|
|
112
|
+
expect(frameGsap(iframe)).not.toBeNull();
|
|
113
|
+
});
|