@hyperframes/studio 0.8.205 → 0.8.206

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/studio",
3
- "version": "0.8.205",
3
+ "version": "0.8.206",
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.205",
64
- "@hyperframes/parsers": "0.8.205",
65
- "@hyperframes/sdk": "0.8.205",
66
- "@hyperframes/player": "0.8.205",
67
- "@hyperframes/shader-transitions": "0.8.205",
68
- "@hyperframes/studio-server": "0.8.205"
63
+ "@hyperframes/core": "0.8.206",
64
+ "@hyperframes/player": "0.8.206",
65
+ "@hyperframes/sdk": "0.8.206",
66
+ "@hyperframes/shader-transitions": "0.8.206",
67
+ "@hyperframes/studio-server": "0.8.206",
68
+ "@hyperframes/parsers": "0.8.206"
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.205"
85
+ "@hyperframes/producer": "0.8.206"
86
86
  },
87
87
  "peerDependencies": {
88
88
  "react": "19",
@@ -0,0 +1,69 @@
1
+ // @vitest-environment happy-dom
2
+ import { act } from "react";
3
+ import { createRoot, type Root } from "react-dom/client";
4
+ import { afterEach, describe, expect, it } from "vitest";
5
+ import { MediaPreview } from "./MediaPreview";
6
+
7
+ (globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
8
+
9
+ let root: Root | null = null;
10
+ let host: HTMLDivElement | null = null;
11
+
12
+ afterEach(() => {
13
+ if (root) act(() => root?.unmount());
14
+ root = null;
15
+ host = null;
16
+ document.body.replaceChildren();
17
+ });
18
+
19
+ async function renderPreview(projectId: string, filePath: string): Promise<HTMLDivElement> {
20
+ if (!root) {
21
+ host = document.createElement("div");
22
+ document.body.append(host);
23
+ root = createRoot(host);
24
+ }
25
+ await act(async () => {
26
+ root?.render(<MediaPreview projectId={projectId} filePath={filePath} />);
27
+ });
28
+ return host as HTMLDivElement;
29
+ }
30
+
31
+ describe("MediaPreview", () => {
32
+ it("retries a repaired file after visiting another media source", async () => {
33
+ const host = await renderPreview("test", "broken.png");
34
+ const failedImage = host.querySelector("img");
35
+ expect(failedImage).not.toBeNull();
36
+
37
+ await act(async () => {
38
+ failedImage?.dispatchEvent(new Event("error"));
39
+ });
40
+ expect(host.textContent).toContain("Couldn't load this file");
41
+
42
+ await renderPreview("test", "healthy.png");
43
+ expect(host.querySelector("img")?.getAttribute("src")).toContain("healthy.png");
44
+
45
+ await renderPreview("test", "broken.png");
46
+ expect(host.querySelector("img")?.getAttribute("src")).toContain("broken.png");
47
+ });
48
+
49
+ it("resets failure state when the project changes, but preserves a current failure", async () => {
50
+ const host = await renderPreview("first", "broken.png");
51
+ const image = host.querySelector("img");
52
+ await act(async () => {
53
+ image?.dispatchEvent(new Event("error"));
54
+ });
55
+ expect(host.textContent).toContain("Couldn't load this file");
56
+
57
+ await renderPreview("second", "broken.png");
58
+ expect(host.querySelector("img")?.getAttribute("src")).toContain("/second/preview/broken.png");
59
+
60
+ const secondImage = host.querySelector("img");
61
+ await act(async () => {
62
+ secondImage?.dispatchEvent(new Event("error"));
63
+ });
64
+ expect(host.textContent).toContain("Couldn't load this file");
65
+
66
+ await renderPreview("second", "broken.png");
67
+ expect(host.querySelector("img")).toBeNull();
68
+ });
69
+ });
@@ -1,5 +1,5 @@
1
1
  import { buildProjectApiPath } from "../utils/projectRouting";
2
- import { useState } from "react";
2
+ import { useEffect, useState } from "react";
3
3
  import { IMAGE_EXT, VIDEO_EXT, AUDIO_EXT } from "../utils/mediaTypes";
4
4
  import { encodeUrlPath } from "@hyperframes/parsers";
5
5
 
@@ -32,10 +32,15 @@ function MediaErrorPanel({ name, filePath }: { name: string; filePath: string })
32
32
  export function MediaPreview({ projectId, filePath }: { projectId: string; filePath: string }) {
33
33
  const serveUrl = buildProjectApiPath(projectId, `/preview/${encodeUrlPath(filePath)}`);
34
34
  const name = filePath.split("/").pop() ?? filePath;
35
- // Keyed by path so switching to another file clears a previous failure.
36
- const [failedPath, setFailedPath] = useState<string | null>(null);
37
- const failed = failedPath === filePath;
38
- const setFailed = () => setFailedPath(filePath);
35
+ const [failure, setFailure] = useState<{ source: string; failed: boolean }>({
36
+ source: serveUrl,
37
+ failed: false,
38
+ });
39
+ useEffect(() => {
40
+ setFailure({ source: serveUrl, failed: false });
41
+ }, [serveUrl]);
42
+ const failed = failure.source === serveUrl && failure.failed;
43
+ const setFailed = () => setFailure({ source: serveUrl, failed: true });
39
44
 
40
45
  if (failed) return <MediaErrorPanel name={name} filePath={filePath} />;
41
46
 
@@ -148,6 +148,54 @@ describe("collectDomEditLayerItems incremental rebuild", () => {
148
148
  });
149
149
  });
150
150
 
151
+ it("queries the document for no selector when a walk meets elements it has not seen", () => {
152
+ const root = mountPreview(12);
153
+ const boxes = Array.from(root.querySelectorAll<HTMLElement>(".box"));
154
+ // The scenes a scrub has not reached yet: hidden, so no identity is read for them.
155
+ for (const box of boxes.slice(6)) box.style.display = "none";
156
+ const cache = createDomEditLayerWalkCache();
157
+ const observer = new MutationObserver(() => {});
158
+ observer.observe(document.documentElement, DOM_EDIT_LAYER_OBSERVER_INIT);
159
+ try {
160
+ collectDomEditLayerItems(root, opts, undefined, cache);
161
+ for (const box of boxes.slice(6)) box.style.display = "";
162
+ cache.ingest(observer.takeRecords());
163
+
164
+ const real = document.querySelectorAll.bind(document);
165
+ let queries = 0;
166
+ Object.defineProperty(document, "querySelectorAll", {
167
+ configurable: true,
168
+ value: (selector: string) => {
169
+ queries += 1;
170
+ return real(selector);
171
+ },
172
+ });
173
+ let kept: DomEditLayerItem[];
174
+ try {
175
+ kept = collectDomEditLayerItems(root, opts, undefined, cache);
176
+ } finally {
177
+ delete (document as Partial<Document>).querySelectorAll;
178
+ }
179
+ // The revealed cards are in the kept index for their selector.
180
+ expect(queries).toBe(0);
181
+ expect(shape(kept)).toEqual(shape(collectDomEditLayerItems(root, opts)));
182
+ } finally {
183
+ observer.disconnect();
184
+ }
185
+ });
186
+
187
+ it("builds the selector index again once a node is added", () => {
188
+ withWarmWalk(6, ({ root, cache, observer }) => {
189
+ const added = document.createElement("div");
190
+ added.className = "box";
191
+ root.insertBefore(added, root.firstElementChild);
192
+ cache.ingest(observer.takeRecords());
193
+
194
+ const kept = collectDomEditLayerItems(root, opts, undefined, cache);
195
+ expect(shape(kept)).toEqual(shape(collectDomEditLayerItems(root, opts)));
196
+ });
197
+ });
198
+
151
199
  /**
152
200
  * The equivalence half, and the one that would catch a wrong optimisation
153
201
  * rather than a missing one. Every mutation KIND the invalidation reasons
@@ -47,6 +47,7 @@ import {
47
47
  resolveDomLayerIdentity,
48
48
  } from "./domEditingElement";
49
49
  import type { DomEditSelection } from "./domEditingTypes";
50
+ import type { KeptIndexes } from "../../utils/sourceScopedSelectorIndex";
50
51
 
51
52
  /** How an element is addressed. Survives style writes; see `readIdentity`. */
52
53
  export type DomEditLayerIdentity = Pick<
@@ -160,16 +161,20 @@ export interface DomEditLayerWalkCache {
160
161
  ingest(records: MutationRecord[]): void;
161
162
  /** Forget every entry — the fallback for anything not attributable. */
162
163
  invalidateAll(): void;
164
+ /** Selector occurrence indexes, kept across walks and dropped with `identities`, which derive from them. */
165
+ readonly selectorIndex: KeptIndexes;
163
166
  }
164
167
 
165
168
  export function createDomEditLayerWalkCache(): DomEditLayerWalkCache {
166
169
  let presence = new WeakMap<HTMLElement, PresenceMemo>();
167
170
  let identities = new WeakMap<HTMLElement, IdentityMemo>();
168
171
  let scope: string | null = null;
172
+ const selectorIndex: KeptIndexes = new Map();
169
173
 
170
174
  const invalidateAll = () => {
171
175
  presence = new WeakMap();
172
176
  identities = new WeakMap();
177
+ selectorIndex.clear();
173
178
  };
174
179
 
175
180
  const drop = (el: HTMLElement | null) => {
@@ -262,6 +267,7 @@ export function createDomEditLayerWalkCache(): DomEditLayerWalkCache {
262
267
  }
263
268
  },
264
269
  invalidateAll,
270
+ selectorIndex,
265
271
  };
266
272
  }
267
273
 
@@ -487,10 +487,11 @@ export function collectDomEditLayerItems(
487
487
  // card or tile class. The walk is one synchronous read of a document it does
488
488
  // not mutate, so one index per selector serves the whole of it. The pass lives
489
489
  // here rather than in each caller because this function owns the loop.
490
- withSelectorIndexPass(root.ownerDocument, () => {
490
+ const walkRoots = () => {
491
491
  // Drilled into a group → show only its members; otherwise the whole tree.
492
492
  for (const el of groupScopedLayerRoots(root, options.activeGroupElement ?? null)) visit(el, 0);
493
- });
493
+ };
494
+ withSelectorIndexPass(root.ownerDocument, walkRoots, cache?.selectorIndex);
494
495
  return items;
495
496
  }
496
497
 
@@ -0,0 +1,22 @@
1
+ // @vitest-environment happy-dom
2
+
3
+ import { afterEach, describe, expect, it } from "vitest";
4
+ import { PromptPreviewModal } from "./PromptPreviewModal";
5
+ import { cleanupMounted, mountHost } from "../ui/mountHost.testHelpers";
6
+
7
+ afterEach(cleanupMounted);
8
+
9
+ describe("PromptPreviewModal", () => {
10
+ it("gives the prompt editor a stable accessible name", () => {
11
+ const prompt = "Change the title";
12
+ const title = "Example";
13
+ const host = mountHost(<PromptPreviewModal title={title} prompt={prompt} onClose={() => {}} />);
14
+ const dialog = host.querySelector('[role="dialog"]');
15
+ const textarea = host.querySelector("textarea");
16
+
17
+ expect(dialog?.getAttribute("aria-label")).toBe("Ask agent: Example");
18
+ expect(textarea?.getAttribute("aria-label")).toBe("Prompt");
19
+ expect(textarea?.getAttribute("aria-label")).not.toBe(prompt);
20
+ expect(textarea?.getAttribute("aria-label")).not.toBe(dialog?.getAttribute("aria-label"));
21
+ });
22
+ });
@@ -91,6 +91,7 @@ export function PromptPreviewModal({
91
91
  </p>
92
92
  <textarea
93
93
  ref={textareaRef}
94
+ aria-label="Prompt"
94
95
  value={value}
95
96
  onChange={(e) => setValue(e.target.value)}
96
97
  onKeyDown={(e) => {
@@ -23,6 +23,40 @@ describe("preview state messages", () => {
23
23
  });
24
24
  });
25
25
 
26
+ describe("preview state messages while a scrub posts them", () => {
27
+ it("re-reads the preview for missing compositions at most every 500 ms", () => {
28
+ vi.useFakeTimers();
29
+ try {
30
+ vi.setSystemTime(10_000);
31
+ const enrich = vi.fn();
32
+ const handle = createPreviewMessageHandler({
33
+ iframeRef: { current: null },
34
+ processTimelineMessageRef: { current: vi.fn() },
35
+ enrichMissingCompositionsRef: { current: enrich },
36
+ lastTimelineMessageRef: { current: 0 },
37
+ getAdapter: () => null,
38
+ syncTimelineElements: vi.fn(),
39
+ });
40
+ const state = () =>
41
+ handle(
42
+ new MessageEvent("message", {
43
+ data: { source: "hf-preview", type: "state", isPlaying: false },
44
+ }),
45
+ );
46
+ state();
47
+ vi.advanceTimersByTime(100);
48
+ state();
49
+ state();
50
+ expect(enrich).toHaveBeenCalledTimes(1);
51
+ vi.advanceTimersByTime(500);
52
+ state();
53
+ expect(enrich).toHaveBeenCalledTimes(2);
54
+ } finally {
55
+ vi.useRealTimers();
56
+ }
57
+ });
58
+ });
59
+
26
60
  describe("preview quality messages", () => {
27
61
  function routeMessage(data: unknown, frame?: { postMessage: (message: unknown) => void }) {
28
62
  const iframe = frame ? ({ contentWindow: frame } as unknown as HTMLIFrameElement) : null;
@@ -69,15 +69,24 @@ function acceptedPreviewMessage(
69
69
  return acceptStudioRuntimeMessage(data) ? data : null;
70
70
  }
71
71
 
72
+ /** Whether enrichment is due: no timeline message and no enrichment of ours for 500 ms. Marks it run. */
73
+ function enrichDue(lastTimelineMessage: number, enriched: { at: number }): boolean {
74
+ const now = Date.now();
75
+ if (now - lastTimelineMessage <= 500 || now - enriched.at <= 500) return false;
76
+ enriched.at = now;
77
+ return true;
78
+ }
79
+
72
80
  /**
73
81
  * A `state` tick doubles as a recovery hook: if the store still has no
74
82
  * elements, read the manifest straight off the iframe, and if no `timeline`
75
- * message has arrived recently, re-run enrichment.
83
+ * message has arrived recently, re-run enrichment (at most every 500 ms: it queries the whole document).
76
84
  */
77
85
  function handleStateMessage(
78
86
  deps: PreviewMessageRouterDeps,
79
87
  iframe: HTMLIFrameElement | null,
80
88
  playingHoldsClipListPosts: boolean,
89
+ enriched: { at: number },
81
90
  ): void {
82
91
  try {
83
92
  if (usePlayerStore.getState().elements.length === 0) {
@@ -86,7 +95,7 @@ function handleStateMessage(
86
95
  deps.processTimelineMessageRef.current(manifest);
87
96
  }
88
97
  }
89
- if (!playingHoldsClipListPosts && Date.now() - deps.lastTimelineMessageRef.current > 500) {
98
+ if (!playingHoldsClipListPosts && enrichDue(deps.lastTimelineMessageRef.current, enriched)) {
90
99
  deps.enrichMissingCompositionsRef.current();
91
100
  }
92
101
  } catch {}
@@ -135,11 +144,13 @@ function applyStoreReport(data: PreviewMessage): boolean {
135
144
  export function createPreviewMessageHandler(
136
145
  deps: PreviewMessageRouterDeps,
137
146
  ): (e: MessageEvent) => void {
147
+ const enriched = { at: 0 };
138
148
  return (e: MessageEvent) => {
139
149
  const iframe = deps.iframeRef.current;
140
150
  const data = acceptedPreviewMessage(e, iframe);
141
151
  if (!data) return;
142
- if (data.type === "state") return handleStateMessage(deps, iframe, data.isPlaying === true);
152
+ if (data.type === "state")
153
+ return handleStateMessage(deps, iframe, data.isPlaying === true, enriched);
143
154
  if (applyStoreReport(data)) return;
144
155
  if (data.type === "ready") {
145
156
  const level = usePlayerStore.getState().previewQuality;
@@ -9,6 +9,7 @@
9
9
  /** Every element matching one selector, mapped to the source file it belongs to
10
10
  * and its occurrence index within that file. One document query fills it. */
11
11
  type SelectorOccurrences = Map<Element, { scope: string; index: number }>;
12
+ export type KeptIndexes = Map<Document, Map<string, SelectorOccurrences>>;
12
13
 
13
14
  interface SelectorIndexPass {
14
15
  doc: Document;
@@ -33,9 +34,11 @@ let activePass: SelectorIndexPass | null = null;
33
34
  * (the resolver may be a fresh closure per call, as long as it answers the
34
35
  * same). Outside a pass the index is per-call, exactly as before.
35
36
  */
36
- export function withSelectorIndexPass<T>(doc: Document, run: () => T): T {
37
+ export function withSelectorIndexPass<T>(doc: Document, run: () => T, kept?: KeptIndexes): T {
37
38
  const previous = activePass;
38
- activePass = { doc, bySelector: new Map() };
39
+ const bySelector = kept?.get(doc) ?? new Map();
40
+ kept?.set(doc, bySelector);
41
+ activePass = { doc, bySelector };
39
42
  try {
40
43
  return run();
41
44
  } finally {