@hyperframes/studio 0.8.213 → 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.
@@ -1,4 +1,4 @@
1
- import{n as Qi}from"./index-pq574E5O.js";/*!
1
+ import{n as Qi}from"./index-C-DCQ7nQ.js";/*!
2
2
  * Copyright (c) 2026-present, Vanilagy and contributors
3
3
  *
4
4
  * This Source Code Form is subject to the terms of the Mozilla Public
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-pq574E5O.js"></script>
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;
@@ -28472,6 +28474,7 @@ var ENTRY_ORIGIN = "https://hf-thumbnail.invalid/";
28472
28474
  var STORED_THUMBNAIL_BYTES = 256 * 1024 * 1024;
28473
28475
  var index;
28474
28476
  var dropped = /* @__PURE__ */ new Set();
28477
+ var sourcesThisTabMovedOn = /* @__PURE__ */ new Set();
28475
28478
  var saveTimer;
28476
28479
  var warned = false;
28477
28480
  var available = () => typeof caches !== "undefined" && typeof crypto?.subtle !== "undefined";
@@ -28507,6 +28510,12 @@ function laterOf(own, theirs) {
28507
28510
  if (own && own.usedAt >= theirs.usedAt) return void 0;
28508
28511
  return { usedAt: theirs.usedAt, bytes: Math.max(theirs.bytes, own?.bytes ?? 0) };
28509
28512
  }
28513
+ function savedEtagsButThisTabsMoves(mine, theirs) {
28514
+ const etags = { ...mine, ...theirs };
28515
+ for (const key2 of sourcesThisTabMovedOn) etags[key2] = mine[key2];
28516
+ sourcesThisTabMovedOn.clear();
28517
+ return etags;
28518
+ }
28510
28519
  function mergedIndex() {
28511
28520
  const mine = loadIndex();
28512
28521
  const theirs = savedIndex() ?? { etags: {}, caches: {} };
@@ -28514,7 +28523,7 @@ function mergedIndex() {
28514
28523
  const later = dropped.has(name) ? void 0 : laterOf(mine.caches[name], entry3);
28515
28524
  if (later) mine.caches[name] = later;
28516
28525
  }
28517
- mine.etags = { ...theirs.etags, ...mine.etags };
28526
+ mine.etags = savedEtagsButThisTabsMoves(mine.etags, theirs.etags);
28518
28527
  dropped.clear();
28519
28528
  return mine;
28520
28529
  }
@@ -28546,6 +28555,7 @@ var rememberVersion = (stored) => quietly(async () => {
28546
28555
  const saved2 = loadIndex();
28547
28556
  if (saved2.etags[key2] === stored.etag) return;
28548
28557
  saved2.etags[key2] = stored.etag;
28558
+ sourcesThisTabMovedOn.add(key2);
28549
28559
  saveIndexSoon();
28550
28560
  const keep = await cacheNameOf(stored);
28551
28561
  for (const name of await caches.keys()) {
@@ -32136,9 +32146,14 @@ var givenUp = false;
32136
32146
  var changing = () => reloading || reloadRequested || scriptWrites > 0;
32137
32147
  var noteIdle = () => {
32138
32148
  if (!changing()) givenUp = false;
32149
+ globalThis.document?.documentElement.toggleAttribute(
32150
+ "data-preview-changing",
32151
+ isPreviewChanging()
32152
+ );
32139
32153
  };
32140
32154
  function giveUpOnPreviewChange() {
32141
32155
  givenUp = changing();
32156
+ noteIdle();
32142
32157
  }
32143
32158
  function setPreviewReloading(next) {
32144
32159
  reloading = next;
@@ -32147,6 +32162,7 @@ function setPreviewReloading(next) {
32147
32162
  }
32148
32163
  function requestPreviewReload() {
32149
32164
  reloadRequested = true;
32165
+ noteIdle();
32150
32166
  }
32151
32167
  function previewReloadBegun() {
32152
32168
  reloadRequested = false;
@@ -32154,6 +32170,7 @@ function previewReloadBegun() {
32154
32170
  }
32155
32171
  async function whileScriptWrites(write) {
32156
32172
  scriptWrites += 1;
32173
+ noteIdle();
32157
32174
  try {
32158
32175
  return await write();
32159
32176
  } finally {
@@ -88861,8 +88878,8 @@ function useEditHistoryActions({
88861
88878
  forceReloadSdkSession
88862
88879
  ]
88863
88880
  );
88864
- const undo = useCallback153(() => apply("undo"), [apply]);
88865
- const redo = useCallback153(() => apply("redo"), [apply]);
88881
+ const undo = useCallback153(() => whileScriptWrites(() => apply("undo")), [apply]);
88882
+ const redo = useCallback153(() => whileScriptWrites(() => apply("redo")), [apply]);
88866
88883
  return useMemo76(() => ({ undo, redo }), [undo, redo]);
88867
88884
  }
88868
88885
  function fromShown(files, shown3) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/studio",
3
- "version": "0.8.213",
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.213",
64
- "@hyperframes/player": "0.8.213",
65
- "@hyperframes/parsers": "0.8.213",
66
- "@hyperframes/sdk": "0.8.213",
67
- "@hyperframes/shader-transitions": "0.8.213",
68
- "@hyperframes/studio-server": "0.8.213"
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.213"
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
 
@@ -154,5 +154,32 @@ describe("stored thumbnails", () => {
154
154
  const saved = JSON.parse(localStorage.getItem("hf-thumbnails-index")!);
155
155
  expect(Object.keys(saved.caches)).toContain("hf-thumbnails:other:tab");
156
156
  expect(Object.keys(saved.caches)).toHaveLength(2);
157
+ expect(Object.values(saved.etags)).toEqual(['"two"']);
158
+ });
159
+
160
+ it("keep a newer version another tab saw of a source this tab only read at start", async () => {
161
+ await rememberVersion(v1);
162
+ await storeFrame(v1, "cover 1x1 0", 0, jpeg());
163
+ await vi.waitFor(() => expect(localStorage.getItem("hf-thumbnails-index")).toContain("bytes"), {
164
+ timeout: 3000,
165
+ });
166
+ resetStoredThumbnailsForTests();
167
+ // a new session reads the index, then another tab moves the source on to v2
168
+ await storeFrame({ source: "/other.mp4", etag: '"1"' }, "cover 1x1 0", 0, jpeg());
169
+ const other = JSON.parse(localStorage.getItem("hf-thumbnails-index")!);
170
+ const key = Object.keys(other.etags).find((k) => other.etags[k] === '"one"')!;
171
+ other.etags[key] = '"two"';
172
+ localStorage.setItem("hf-thumbnails-index", JSON.stringify(other));
173
+ await storeFrame({ source: "/other.mp4", etag: '"1"' }, "cover 1x1 1", 1, jpeg());
174
+
175
+ // this tab's save is the one that adds /other.mp4's cache to the index
176
+ await vi.waitFor(
177
+ () =>
178
+ expect(
179
+ Object.keys(JSON.parse(localStorage.getItem("hf-thumbnails-index")!).caches),
180
+ ).toHaveLength(2),
181
+ { timeout: 3000 },
182
+ );
183
+ expect(JSON.parse(localStorage.getItem("hf-thumbnails-index")!).etags[key]).toBe('"two"');
157
184
  });
158
185
  });
@@ -24,6 +24,7 @@ interface Index {
24
24
  let index: Index | undefined;
25
25
  // caches this tab dropped since its last save, which another tab's older snapshot must not bring back
26
26
  const dropped = new Set<string>();
27
+ const sourcesThisTabMovedOn = new Set<string>();
27
28
  let saveTimer: ReturnType<typeof setTimeout> | undefined;
28
29
  let warned = false;
29
30
 
@@ -72,6 +73,13 @@ function laterOf(own: CacheEntry | undefined, theirs: CacheEntry): CacheEntry |
72
73
  return { usedAt: theirs.usedAt, bytes: Math.max(theirs.bytes, own?.bytes ?? 0) };
73
74
  }
74
75
 
76
+ function savedEtagsButThisTabsMoves(mine: Index["etags"], theirs: Index["etags"]): Index["etags"] {
77
+ const etags = { ...mine, ...theirs };
78
+ for (const key of sourcesThisTabMovedOn) etags[key] = mine[key]!;
79
+ sourcesThisTabMovedOn.clear();
80
+ return etags;
81
+ }
82
+
75
83
  /** This tab's index with what other tabs saved since: each cache at its latest use, none this tab dropped. */
76
84
  function mergedIndex(): Index {
77
85
  const mine = loadIndex();
@@ -80,7 +88,7 @@ function mergedIndex(): Index {
80
88
  const later = dropped.has(name) ? undefined : laterOf(mine.caches[name], entry);
81
89
  if (later) mine.caches[name] = later;
82
90
  }
83
- mine.etags = { ...theirs.etags, ...mine.etags };
91
+ mine.etags = savedEtagsButThisTabsMoves(mine.etags, theirs.etags);
84
92
  dropped.clear();
85
93
  return mine;
86
94
  }
@@ -122,6 +130,7 @@ export const rememberVersion = (stored: StoredSource) =>
122
130
  const saved = loadIndex();
123
131
  if (saved.etags[key] === stored.etag) return;
124
132
  saved.etags[key] = stored.etag;
133
+ sourcesThisTabMovedOn.add(key);
125
134
  saveIndexSoon();
126
135
  const keep = await cacheNameOf(stored);
127
136
  for (const name of await caches.keys()) {
@@ -209,4 +218,6 @@ export function resetStoredThumbnailsForTests(): void {
209
218
  saveTimer = undefined;
210
219
  index = undefined;
211
220
  warned = false;
221
+ dropped.clear();
222
+ sourcesThisTabMovedOn.clear();
212
223
  }
@@ -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
  /**