@hyperframes/studio 0.8.214 → 0.8.217

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/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-BftVE_0y.js"></script>
17
+ <script type="module" crossorigin src="/assets/index-zVoFhoyD.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 {
@@ -32188,6 +32197,17 @@ function shadowPlayerReachable(iframe) {
32188
32197
  return false;
32189
32198
  }
32190
32199
  }
32200
+ function shadowPagePhase(iframe) {
32201
+ const doc = iframe?.contentDocument;
32202
+ if (!doc || doc.URL === "about:blank") return "no-page";
32203
+ const win = iframe.contentWindow;
32204
+ if (doc.readyState === "loading") return "page-loading";
32205
+ if (win.__hfStartupError) return "startup-error";
32206
+ if (!win.__hyperframes) return "runtime-not-run";
32207
+ if (!win.__hyperframeRuntimeBootstrapped) return "scripts-waiting";
32208
+ return "no-player";
32209
+ }
32210
+ var pageGotTo = (iframe) => shadowPlayerReachable(iframe) ? "" : ` Its page had got to: ${shadowPagePhase(iframe)}.`;
32191
32211
  function isDocumentHidden() {
32192
32212
  return typeof document !== "undefined" && document.visibilityState === "hidden";
32193
32213
  }
@@ -32244,6 +32264,7 @@ function useShadowPreviewReload({
32244
32264
  (gen, cause) => {
32245
32265
  if (gen !== shadowGenRef.current) return;
32246
32266
  const waitingFor = !shadowPlayerReachable(shadowIframeRef.current) ? "the page and its runtime to load" : pendingCommitRef.current?.gen !== gen ? "its timeline to be ready" : "its loaders to clear";
32267
+ const got = pageGotTo(shadowIframeRef.current);
32247
32268
  shadowGenRef.current += 1;
32248
32269
  stopPendingShadow();
32249
32270
  shadowIframeRef.current = null;
@@ -32251,7 +32272,7 @@ function useShadowPreviewReload({
32251
32272
  pendingSeekRef.current = null;
32252
32273
  setPreviewSlots(planShadowDiscard);
32253
32274
  setPreviewReloading(false);
32254
- const message = `The preview did not reload (${cause}). It was still waiting for ${waitingFor}. The previous preview is still showing.`;
32275
+ const message = `The preview did not reload (${cause}). It was still waiting for ${waitingFor}.${got} The previous preview is still showing.`;
32255
32276
  logReload("shadow-failed", { cause, waitingFor });
32256
32277
  const refused = refusedPreviewStatus(cause);
32257
32278
  const pageMissingNow = refused !== null && refused < 500;
@@ -88869,8 +88890,8 @@ function useEditHistoryActions({
88869
88890
  forceReloadSdkSession
88870
88891
  ]
88871
88892
  );
88872
- const undo = useCallback153(() => apply("undo"), [apply]);
88873
- const redo = useCallback153(() => apply("redo"), [apply]);
88893
+ const undo = useCallback153(() => whileScriptWrites(() => apply("undo")), [apply]);
88894
+ const redo = useCallback153(() => whileScriptWrites(() => apply("redo")), [apply]);
88874
88895
  return useMemo76(() => ({ undo, redo }), [undo, redo]);
88875
88896
  }
88876
88897
  function fromShown(files, shown3) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/studio",
3
- "version": "0.8.214",
3
+ "version": "0.8.217",
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.214",
64
- "@hyperframes/parsers": "0.8.214",
65
- "@hyperframes/player": "0.8.214",
66
- "@hyperframes/sdk": "0.8.214",
67
- "@hyperframes/studio-server": "0.8.214",
68
- "@hyperframes/shader-transitions": "0.8.214"
63
+ "@hyperframes/core": "0.8.217",
64
+ "@hyperframes/parsers": "0.8.217",
65
+ "@hyperframes/player": "0.8.217",
66
+ "@hyperframes/shader-transitions": "0.8.217",
67
+ "@hyperframes/studio-server": "0.8.217",
68
+ "@hyperframes/sdk": "0.8.217"
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.214"
85
+ "@hyperframes/producer": "0.8.217"
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
 
@@ -44,6 +44,20 @@ function shadowPlayerReachable(iframe: HTMLIFrameElement | null): boolean {
44
44
  }
45
45
  }
46
46
 
47
+ function shadowPagePhase(iframe: HTMLIFrameElement | null): string {
48
+ const doc = iframe?.contentDocument;
49
+ if (!doc || doc.URL === "about:blank") return "no-page";
50
+ const win = iframe!.contentWindow as unknown as Record<string, unknown>;
51
+ if (doc.readyState === "loading") return "page-loading";
52
+ if (win.__hfStartupError) return "startup-error";
53
+ if (!win.__hyperframes) return "runtime-not-run";
54
+ if (!win.__hyperframeRuntimeBootstrapped) return "scripts-waiting";
55
+ return "no-player";
56
+ }
57
+
58
+ const pageGotTo = (iframe: HTMLIFrameElement | null) =>
59
+ shadowPlayerReachable(iframe) ? "" : ` Its page had got to: ${shadowPagePhase(iframe)}.`;
60
+
47
61
  function isDocumentHidden(): boolean {
48
62
  return typeof document !== "undefined" && document.visibilityState === "hidden";
49
63
  }
@@ -123,6 +137,7 @@ export function useShadowPreviewReload({
123
137
  : pendingCommitRef.current?.gen !== gen
124
138
  ? "its timeline to be ready"
125
139
  : "its loaders to clear";
140
+ const got = pageGotTo(shadowIframeRef.current);
126
141
  shadowGenRef.current += 1;
127
142
  stopPendingShadow();
128
143
  shadowIframeRef.current = null;
@@ -130,7 +145,7 @@ export function useShadowPreviewReload({
130
145
  pendingSeekRef.current = null;
131
146
  setPreviewSlots(planShadowDiscard);
132
147
  setPreviewReloading(false);
133
- const message = `The preview did not reload (${cause}). It was still waiting for ${waitingFor}. The previous preview is still showing.`;
148
+ const message = `The preview did not reload (${cause}). It was still waiting for ${waitingFor}.${got} The previous preview is still showing.`;
134
149
  logReload("shadow-failed", { cause, waitingFor });
135
150
  const refused = refusedPreviewStatus(cause);
136
151
  const pageMissingNow = refused !== null && refused < 500;
@@ -405,6 +405,36 @@ describe("shadow reload readiness and failure", () => {
405
405
  unmount(root);
406
406
  });
407
407
 
408
+ const loaded = { URL: "http://127.0.0.1/preview", readyState: "complete" };
409
+ it.each([
410
+ ["no-page", {}, { ...loaded, URL: "about:blank" }],
411
+ ["page-loading", {}, { ...loaded, readyState: "loading" }],
412
+ ["startup-error", { __hfStartupError: "failed", __hyperframes: {} }, loaded],
413
+ ["runtime-not-run", {}, loaded],
414
+ // Its runtime ran, but the composition's scripts never finished (fonts that never load, say).
415
+ ["scripts-waiting", { __hyperframes: {} }, loaded],
416
+ ["no-player", { __hyperframes: {}, __hyperframeRuntimeBootstrapped: true }, loaded],
417
+ ])(
418
+ "says its page got to %s when a shadow gives up waiting for the runtime",
419
+ (phase, win, doc) => {
420
+ vi.useFakeTimers();
421
+ vi.spyOn(console, "error").mockImplementation(() => {});
422
+ const onPreviewReloadFailed = vi.fn();
423
+ const { getApi, gen, root } = beginReload({ onPreviewReloadFailed });
424
+ const shadow = makeFakeIframe(win);
425
+ Object.defineProperty(shadow, "contentDocument", { value: doc });
426
+ act(() => {
427
+ getApi().setShadowIframeNode(shadow);
428
+ getApi().onShadowIframeLoad(gen);
429
+ });
430
+ act(() => void vi.advanceTimersByTime(FULL_WAIT_MS));
431
+ expect(onPreviewReloadFailed).toHaveBeenCalledWith(
432
+ expect.stringContaining(`Its page had got to: ${phase}.`),
433
+ );
434
+ unmount(root);
435
+ },
436
+ );
437
+
408
438
  it("names the timeline when a shadow's runtime runs but never reports a length", () => {
409
439
  vi.useFakeTimers();
410
440
  vi.spyOn(console, "error").mockImplementation(() => {});
@@ -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 or scene swap counts from its send until its preview update is applied, or it fails. */
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?: { getTime?: () => number; seek?: (t: number) => void };
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
  /**