@hyperframes/studio 0.8.214 → 0.8.216
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-H1DIJsJZ.js → hyperframes-player-D38lr2hR.js} +3 -3
- package/dist/assets/{index-BftVE_0y.js → index-C-DCQ7nQ.js} +120 -120
- package/dist/assets/{index-v_hWj6Kv.js → index-CJ28BLvq.js} +1 -1
- package/dist/index.html +1 -1
- package/dist/index.js +11 -2
- package/package.json +8 -8
- package/src/hooks/useEditHistoryActions.test.tsx +25 -0
- package/src/hooks/useEditHistoryActions.ts +3 -2
- package/src/player/previewReloading.test.ts +17 -0
- package/src/player/previewReloading.ts +8 -1
- package/src/utils/gsapSoftReload.test.ts +43 -0
- package/src/utils/gsapSoftReload.ts +9 -1
package/dist/index.html
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
document.documentElement.dataset.theme = "paper";
|
|
15
15
|
}
|
|
16
16
|
</script>
|
|
17
|
-
<script type="module" crossorigin src="/assets/index-
|
|
17
|
+
<script type="module" crossorigin src="/assets/index-C-DCQ7nQ.js"></script>
|
|
18
18
|
<link rel="stylesheet" crossorigin href="/assets/index-RUPGNyct.css">
|
|
19
19
|
</head>
|
|
20
20
|
<body>
|
package/dist/index.js
CHANGED
|
@@ -18032,9 +18032,11 @@ function runSuppressed(win, reload) {
|
|
|
18032
18032
|
}
|
|
18033
18033
|
}
|
|
18034
18034
|
function finalizeSoftReload(win, currentTime) {
|
|
18035
|
+
const wasPlaying = win.__player?.isPlaying?.() === true;
|
|
18035
18036
|
win.__player?.seek?.(currentTime);
|
|
18036
18037
|
win.__hfForceTimelineRebind?.();
|
|
18037
18038
|
win.__hfStudioManualEditsApply?.();
|
|
18039
|
+
if (wasPlaying) win.__player?.play?.();
|
|
18038
18040
|
}
|
|
18039
18041
|
function applySoftReloadFinalization(iframe, currentTime) {
|
|
18040
18042
|
const win = iframe?.contentWindow;
|
|
@@ -32144,9 +32146,14 @@ var givenUp = false;
|
|
|
32144
32146
|
var changing = () => reloading || reloadRequested || scriptWrites > 0;
|
|
32145
32147
|
var noteIdle = () => {
|
|
32146
32148
|
if (!changing()) givenUp = false;
|
|
32149
|
+
globalThis.document?.documentElement.toggleAttribute(
|
|
32150
|
+
"data-preview-changing",
|
|
32151
|
+
isPreviewChanging()
|
|
32152
|
+
);
|
|
32147
32153
|
};
|
|
32148
32154
|
function giveUpOnPreviewChange() {
|
|
32149
32155
|
givenUp = changing();
|
|
32156
|
+
noteIdle();
|
|
32150
32157
|
}
|
|
32151
32158
|
function setPreviewReloading(next) {
|
|
32152
32159
|
reloading = next;
|
|
@@ -32155,6 +32162,7 @@ function setPreviewReloading(next) {
|
|
|
32155
32162
|
}
|
|
32156
32163
|
function requestPreviewReload() {
|
|
32157
32164
|
reloadRequested = true;
|
|
32165
|
+
noteIdle();
|
|
32158
32166
|
}
|
|
32159
32167
|
function previewReloadBegun() {
|
|
32160
32168
|
reloadRequested = false;
|
|
@@ -32162,6 +32170,7 @@ function previewReloadBegun() {
|
|
|
32162
32170
|
}
|
|
32163
32171
|
async function whileScriptWrites(write) {
|
|
32164
32172
|
scriptWrites += 1;
|
|
32173
|
+
noteIdle();
|
|
32165
32174
|
try {
|
|
32166
32175
|
return await write();
|
|
32167
32176
|
} finally {
|
|
@@ -88869,8 +88878,8 @@ function useEditHistoryActions({
|
|
|
88869
88878
|
forceReloadSdkSession
|
|
88870
88879
|
]
|
|
88871
88880
|
);
|
|
88872
|
-
const undo = useCallback153(() => apply("undo"), [apply]);
|
|
88873
|
-
const redo = useCallback153(() => apply("redo"), [apply]);
|
|
88881
|
+
const undo = useCallback153(() => whileScriptWrites(() => apply("undo")), [apply]);
|
|
88882
|
+
const redo = useCallback153(() => whileScriptWrites(() => apply("redo")), [apply]);
|
|
88874
88883
|
return useMemo76(() => ({ undo, redo }), [undo, redo]);
|
|
88875
88884
|
}
|
|
88876
88885
|
function fromShown(files, shown3) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/studio",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.216",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -60,12 +60,12 @@
|
|
|
60
60
|
"dockview-react": "8.3.1",
|
|
61
61
|
"gsap": "^3.13.0",
|
|
62
62
|
"mediabunny": "^1.45.3",
|
|
63
|
-
"@hyperframes/core": "0.8.
|
|
64
|
-
"@hyperframes/parsers": "0.8.
|
|
65
|
-
"@hyperframes/player": "0.8.
|
|
66
|
-
"@hyperframes/sdk": "0.8.
|
|
67
|
-
"@hyperframes/
|
|
68
|
-
"@hyperframes/
|
|
63
|
+
"@hyperframes/core": "0.8.216",
|
|
64
|
+
"@hyperframes/parsers": "0.8.216",
|
|
65
|
+
"@hyperframes/player": "0.8.216",
|
|
66
|
+
"@hyperframes/sdk": "0.8.216",
|
|
67
|
+
"@hyperframes/shader-transitions": "0.8.216",
|
|
68
|
+
"@hyperframes/studio-server": "0.8.216"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"vite": "^6.4.2",
|
|
83
83
|
"vitest": "^4.1.11",
|
|
84
84
|
"zustand": "^5.0.0",
|
|
85
|
-
"@hyperframes/producer": "0.8.
|
|
85
|
+
"@hyperframes/producer": "0.8.216"
|
|
86
86
|
},
|
|
87
87
|
"peerDependencies": {
|
|
88
88
|
"react": "19",
|
|
@@ -4,6 +4,7 @@ import { act, createElement } from "react";
|
|
|
4
4
|
import { createRoot, type Root } from "react-dom/client";
|
|
5
5
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
6
6
|
import { STUDIO_MOTION_PATH } from "../components/editor/studioMotion";
|
|
7
|
+
import { isPreviewChanging } from "../player/previewReloading";
|
|
7
8
|
import { useEditHistoryActions, type EditHistoryHandle } from "./useEditHistoryActions";
|
|
8
9
|
import {
|
|
9
10
|
beginStudioPendingEdit,
|
|
@@ -73,6 +74,30 @@ const PREDICTED = { id: "e1", files: { "index.html": { previous: "B", restored:
|
|
|
73
74
|
const SERVER_FILES = { "index.html": { previous: "B", restored: "A2" } };
|
|
74
75
|
|
|
75
76
|
describe("useEditHistoryActions", () => {
|
|
77
|
+
it("counts an undo as a preview change from its key until its preview update is applied", async () => {
|
|
78
|
+
const files = { "index.html": { previous: "B", restored: "A" } };
|
|
79
|
+
const stepped = { ok: true, label: "Undid: Move", paths: ["index.html"], files };
|
|
80
|
+
const { deps, actions } = mount(stepped);
|
|
81
|
+
let answer: () => void = () => {};
|
|
82
|
+
deps.editHistory.undo.mockImplementationOnce(
|
|
83
|
+
() => new Promise((resolve) => (answer = () => resolve(stepped))),
|
|
84
|
+
);
|
|
85
|
+
let applied: () => void = () => {};
|
|
86
|
+
deps.syncHistoryPreviewAfterApply.mockImplementationOnce(
|
|
87
|
+
() => new Promise<undefined>((resolve) => (applied = () => resolve(undefined))),
|
|
88
|
+
);
|
|
89
|
+
const undone = actions.undo();
|
|
90
|
+
expect(isPreviewChanging(), "from the key, before the server answers").toBe(true);
|
|
91
|
+
await vi.waitFor(() => expect(deps.editHistory.undo).toHaveBeenCalled());
|
|
92
|
+
expect(isPreviewChanging(), "while the server has the step").toBe(true);
|
|
93
|
+
answer();
|
|
94
|
+
await vi.waitFor(() => expect(deps.syncHistoryPreviewAfterApply).toHaveBeenCalled());
|
|
95
|
+
expect(isPreviewChanging(), "until the preview update is applied").toBe(true);
|
|
96
|
+
applied();
|
|
97
|
+
await act(() => undone);
|
|
98
|
+
expect(isPreviewChanging()).toBe(false);
|
|
99
|
+
});
|
|
100
|
+
|
|
76
101
|
it("takes back a canvas press still waiting to run, with no history step", async () => {
|
|
77
102
|
const { deps, actions } = mount({ ok: true, label: "Undid: Move" });
|
|
78
103
|
const cancel = vi.fn(() => (setStudioWaitingPressCancel(null), true));
|
|
@@ -3,6 +3,7 @@ import { useCallback, useMemo } from "react";
|
|
|
3
3
|
import { STUDIO_MOTION_PATH } from "../components/editor/studioMotion";
|
|
4
4
|
import { serializeStudioFileMutations } from "../utils/studioFileMutationCoordinator";
|
|
5
5
|
import type { RestoreFiles } from "../utils/gsapUndoRestore";
|
|
6
|
+
import { whileScriptWrites } from "../player/previewReloading";
|
|
6
7
|
import {
|
|
7
8
|
beginStudioShownRestore,
|
|
8
9
|
cancelNewestStudioWaitingPress,
|
|
@@ -152,8 +153,8 @@ export function useEditHistoryActions({
|
|
|
152
153
|
],
|
|
153
154
|
);
|
|
154
155
|
|
|
155
|
-
const undo = useCallback(() => apply("undo"), [apply]);
|
|
156
|
-
const redo = useCallback(() => apply("redo"), [apply]);
|
|
156
|
+
const undo = useCallback(() => whileScriptWrites(() => apply("undo")), [apply]);
|
|
157
|
+
const redo = useCallback(() => whileScriptWrites(() => apply("redo")), [apply]);
|
|
157
158
|
return useMemo(() => ({ undo, redo }), [undo, redo]);
|
|
158
159
|
}
|
|
159
160
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
1
3
|
import { afterEach, describe, expect, it } from "vitest";
|
|
2
4
|
import {
|
|
3
5
|
giveUpOnPreviewChange,
|
|
@@ -45,4 +47,19 @@ describe("the preview is changing", () => {
|
|
|
45
47
|
requestPreviewReload();
|
|
46
48
|
expect(isPreviewChanging(), "the next change counts again").toBe(true);
|
|
47
49
|
});
|
|
50
|
+
|
|
51
|
+
it("is mirrored on the page for a tool that watches the preview from outside", async () => {
|
|
52
|
+
const shown = () => document.documentElement.hasAttribute("data-preview-changing");
|
|
53
|
+
expect(shown()).toBe(false);
|
|
54
|
+
requestPreviewReload();
|
|
55
|
+
expect(shown()).toBe(true);
|
|
56
|
+
previewReloadBegun();
|
|
57
|
+
expect(shown()).toBe(false);
|
|
58
|
+
let land: () => void = () => {};
|
|
59
|
+
const write = whileScriptWrites(() => new Promise<void>((resolve) => (land = resolve)));
|
|
60
|
+
expect(shown()).toBe(true);
|
|
61
|
+
land();
|
|
62
|
+
await write;
|
|
63
|
+
expect(shown()).toBe(false);
|
|
64
|
+
});
|
|
48
65
|
});
|
|
@@ -9,10 +9,15 @@ let givenUp = false;
|
|
|
9
9
|
const changing = () => reloading || reloadRequested || scriptWrites > 0;
|
|
10
10
|
const noteIdle = () => {
|
|
11
11
|
if (!changing()) givenUp = false;
|
|
12
|
+
globalThis.document?.documentElement.toggleAttribute(
|
|
13
|
+
"data-preview-changing",
|
|
14
|
+
isPreviewChanging(),
|
|
15
|
+
);
|
|
12
16
|
};
|
|
13
17
|
|
|
14
18
|
export function giveUpOnPreviewChange(): void {
|
|
15
19
|
givenUp = changing();
|
|
20
|
+
noteIdle();
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
export function setPreviewReloading(next: boolean): void {
|
|
@@ -24,6 +29,7 @@ export function setPreviewReloading(next: boolean): void {
|
|
|
24
29
|
/** Studio asked for a reload that has not begun yet; `previewReloadBegun` closes that gap. */
|
|
25
30
|
export function requestPreviewReload(): void {
|
|
26
31
|
reloadRequested = true;
|
|
32
|
+
noteIdle();
|
|
27
33
|
}
|
|
28
34
|
|
|
29
35
|
export function previewReloadBegun(): void {
|
|
@@ -31,9 +37,10 @@ export function previewReloadBegun(): void {
|
|
|
31
37
|
noteIdle();
|
|
32
38
|
}
|
|
33
39
|
|
|
34
|
-
/** A script write
|
|
40
|
+
/** A script write, scene swap or history step counts from its send until its preview update is applied, or it fails. */
|
|
35
41
|
export async function whileScriptWrites<T>(write: () => Promise<T>): Promise<T> {
|
|
36
42
|
scriptWrites += 1;
|
|
43
|
+
noteIdle();
|
|
37
44
|
try {
|
|
38
45
|
return await write();
|
|
39
46
|
} finally {
|
|
@@ -379,6 +379,49 @@ describe("applySoftReloadFinalization", () => {
|
|
|
379
379
|
expect(contentWindow.__timelines.root).toBe(mockTimeline);
|
|
380
380
|
});
|
|
381
381
|
|
|
382
|
+
describe("play state", () => {
|
|
383
|
+
function playerThatLogs(playing: boolean) {
|
|
384
|
+
const calls: string[] = [];
|
|
385
|
+
const player = {
|
|
386
|
+
getTime: () => 2.0,
|
|
387
|
+
isPlaying: () => playing,
|
|
388
|
+
seek: vi.fn(() => calls.push("seek")),
|
|
389
|
+
play: vi.fn(() => calls.push("play")),
|
|
390
|
+
};
|
|
391
|
+
const built = buildMockIframe({
|
|
392
|
+
__player: player,
|
|
393
|
+
__hfForceTimelineRebind: vi.fn(() => calls.push("rebind")),
|
|
394
|
+
__hfStudioManualEditsApply: vi.fn(() => calls.push("edits")),
|
|
395
|
+
});
|
|
396
|
+
return { ...built, player, calls };
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
it("resumes playing once the timeline is rebuilt when an edit lands during playback", () => {
|
|
400
|
+
const { iframe, calls } = playerThatLogs(true);
|
|
401
|
+
|
|
402
|
+
expect(applySoftReloadFinalization(iframe, 2.0)).toBe(true);
|
|
403
|
+
|
|
404
|
+
expect(calls).toEqual(["seek", "rebind", "edits", "play"]);
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
it("leaves a paused player paused", () => {
|
|
408
|
+
const { iframe, player } = playerThatLogs(false);
|
|
409
|
+
|
|
410
|
+
expect(applySoftReloadFinalization(iframe, 2.0)).toBe(true);
|
|
411
|
+
|
|
412
|
+
expect(player.seek).toHaveBeenCalledWith(2.0);
|
|
413
|
+
expect(player.play).not.toHaveBeenCalled();
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
it("resumes after a script soft reload too, which shares the finalization", () => {
|
|
417
|
+
const { iframe, calls } = playerThatLogs(true);
|
|
418
|
+
|
|
419
|
+
expect(applySoftReload(iframe, SCRIPT_TEXT)).toBe("applied");
|
|
420
|
+
|
|
421
|
+
expect(calls.at(-1)).toBe("play");
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
|
|
382
425
|
it("runs inside __hfSuppressSceneMutations when the runtime provides it", () => {
|
|
383
426
|
const suppress = vi.fn(<T>(fn: () => T): T => fn());
|
|
384
427
|
const { iframe, contentWindow } = buildMockIframe({
|
|
@@ -12,7 +12,12 @@ import {
|
|
|
12
12
|
|
|
13
13
|
type IframeWindow = Window & {
|
|
14
14
|
__timelines?: Record<string, { kill?: () => void; pause?: () => void }>;
|
|
15
|
-
__player?: {
|
|
15
|
+
__player?: {
|
|
16
|
+
getTime?: () => number;
|
|
17
|
+
seek?: (t: number) => void;
|
|
18
|
+
isPlaying?: () => boolean;
|
|
19
|
+
play?: () => void;
|
|
20
|
+
};
|
|
16
21
|
__hfForceTimelineRebind?: () => void;
|
|
17
22
|
__hfSuppressSceneMutations?: <T>(fn: () => T) => T;
|
|
18
23
|
__hfStudioManualEditsApply?: () => void;
|
|
@@ -252,9 +257,12 @@ export interface SoftReloadOptions {
|
|
|
252
257
|
* no-op if the timeline already reports being at that time internally.
|
|
253
258
|
*/
|
|
254
259
|
function finalizeSoftReload(win: IframeWindow, currentTime: number): void {
|
|
260
|
+
// A seek pauses the player, so an edit made while playing resumes it once the timeline is rebuilt.
|
|
261
|
+
const wasPlaying = win.__player?.isPlaying?.() === true;
|
|
255
262
|
win.__player?.seek?.(currentTime);
|
|
256
263
|
win.__hfForceTimelineRebind?.();
|
|
257
264
|
win.__hfStudioManualEditsApply?.();
|
|
265
|
+
if (wasPlaying) win.__player?.play?.();
|
|
258
266
|
}
|
|
259
267
|
|
|
260
268
|
/**
|