@hyperframes/studio 0.9.46 → 0.9.47

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.
Files changed (34) hide show
  1. package/dist/assets/{hyperframes-player-CjQNefFs.js → hyperframes-player-DTdMXCCs.js} +1 -1
  2. package/dist/assets/{index-B85NqQ6A.js → index-CdtV6F8j.js} +121 -121
  3. package/dist/assets/index-DA5GM2Mj.js +469 -0
  4. package/dist/assets/pausedVideoDecoder-B4OsoiOL.js +1 -0
  5. package/dist/{chunk-FQ3VRKMC.js → chunk-5ZHKYODQ.js} +1 -0
  6. package/dist/index.d.ts +2 -2
  7. package/dist/index.html +1 -1
  8. package/dist/index.js +569 -534
  9. package/dist/{keys-CaWcxUST.d.ts → keys-B163OjLN.d.ts} +1 -0
  10. package/dist/keys.d.ts +1 -1
  11. package/dist/keys.js +1 -1
  12. package/package.json +9 -9
  13. package/src/captions/hooks/useCaptionSync.test.ts +45 -0
  14. package/src/captions/hooks/useCaptionSync.ts +8 -3
  15. package/src/hooks/gsapMutationClient.ts +6 -2
  16. package/src/hooks/useDomEditCommitsHelpers.test.ts +16 -0
  17. package/src/hooks/useDomEditCommitsHelpers.ts +3 -1
  18. package/src/hooks/useElementLifecycleOps.ts +1 -0
  19. package/src/hooks/useFreezeFrame.test.ts +9 -0
  20. package/src/hooks/useFreezeFrame.ts +3 -1
  21. package/src/hooks/useGroupCommits.ts +3 -0
  22. package/src/hooks/useTimelineDeleteOps.test.tsx +26 -0
  23. package/src/hooks/useTimelineDeleteOps.ts +3 -1
  24. package/src/player/components/ShortcutsPanel.test.tsx +75 -0
  25. package/src/player/components/ShortcutsPanel.tsx +20 -4
  26. package/src/player/components/studioKeyDefaults.ts +1 -0
  27. package/src/player/components/studioShortcuts.ts +1 -0
  28. package/src/player/lib/mediabunnyHevcSps.test.ts +169 -0
  29. package/src/utils/studioSaveDiagnostics.test.ts +10 -0
  30. package/src/utils/studioSaveDiagnostics.ts +10 -0
  31. package/src/utils/timelineCompositionInsert.ts +3 -1
  32. package/dist/assets/codec-D3GU4v7H.js +0 -314
  33. package/dist/assets/index-B7N7k0rf.js +0 -150
  34. package/dist/assets/pausedVideoDecoder-CPaoO7Pl.js +0 -1
@@ -39,6 +39,7 @@ declare const DEFAULT_STUDIO_KEYS: {
39
39
  snap: string;
40
40
  grid: string;
41
41
  timelineSnap: string;
42
+ shortcuts: string;
42
43
  playPause: string;
43
44
  frameBack: string;
44
45
  frameForward: string;
package/dist/keys.d.ts CHANGED
@@ -1 +1 @@
1
- export { C as Combo, b as ComboEvent, D as DEFAULT_STUDIO_KEYS, a as StudioKeyAction, S as StudioKeys, m as matchCombo, p as parseCombo } from './keys-CaWcxUST.js';
1
+ export { C as Combo, b as ComboEvent, D as DEFAULT_STUDIO_KEYS, a as StudioKeyAction, S as StudioKeys, m as matchCombo, p as parseCombo } from './keys-B163OjLN.js';
package/dist/keys.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  DEFAULT_STUDIO_KEYS,
3
3
  matchCombo,
4
4
  parseCombo
5
- } from "./chunk-FQ3VRKMC.js";
5
+ } from "./chunk-5ZHKYODQ.js";
6
6
  import "./chunk-MLKGABMK.js";
7
7
  export {
8
8
  DEFAULT_STUDIO_KEYS,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/studio",
3
- "version": "0.9.46",
3
+ "version": "0.9.47",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -63,13 +63,13 @@
63
63
  "cn": "0.2.4",
64
64
  "dockview-react": "8.3.1",
65
65
  "gsap": "^3.13.0",
66
- "mediabunny": "^1.65.2",
67
- "@hyperframes/core": "0.9.46",
68
- "@hyperframes/parsers": "0.9.46",
69
- "@hyperframes/shader-transitions": "0.9.46",
70
- "@hyperframes/player": "0.9.46",
71
- "@hyperframes/studio-server": "0.9.46",
72
- "@hyperframes/sdk": "0.9.46"
66
+ "mediabunny": "^1.66.0",
67
+ "@hyperframes/parsers": "0.9.47",
68
+ "@hyperframes/sdk": "0.9.47",
69
+ "@hyperframes/player": "0.9.47",
70
+ "@hyperframes/studio-server": "0.9.47",
71
+ "@hyperframes/core": "0.9.47",
72
+ "@hyperframes/shader-transitions": "0.9.47"
73
73
  },
74
74
  "devDependencies": {
75
75
  "@tailwindcss/vite": "^4.3.3",
@@ -86,7 +86,7 @@
86
86
  "vite": "^6.4.5",
87
87
  "vitest": "^4.1.12",
88
88
  "zustand": "^5.0.0",
89
- "@hyperframes/producer": "0.9.46"
89
+ "@hyperframes/producer": "0.9.47"
90
90
  },
91
91
  "peerDependencies": {
92
92
  "react": "19",
@@ -0,0 +1,45 @@
1
+ // @vitest-environment happy-dom
2
+ import { act, createElement } from "react";
3
+ import { createRoot } from "react-dom/client";
4
+ import { afterEach, describe, expect, it, vi } from "vitest";
5
+ import { useCaptionStore } from "../store";
6
+ import type { CaptionModel } from "../types";
7
+ import { useCaptionSync } from "./useCaptionSync";
8
+
9
+ afterEach(() => vi.unstubAllGlobals());
10
+
11
+ function Harness() {
12
+ useCaptionSync("p");
13
+ return null;
14
+ }
15
+
16
+ describe("useCaptionSync", () => {
17
+ it.each([
18
+ [
19
+ { why: "permission" },
20
+ "caption-overrides.json can't be changed: it is read-only or protected. Check its permissions, then try again.",
21
+ ],
22
+ [{ error: "boom" }, "Caption changes couldn't be saved"],
23
+ ])("says why a refused save failed: %o", async (answer, words) => {
24
+ vi.stubGlobal(
25
+ "fetch",
26
+ vi.fn(async () => new Response(JSON.stringify(answer), { status: 403 })),
27
+ );
28
+ const root = createRoot(document.createElement("div"));
29
+ await act(async () => root.render(createElement(Harness)));
30
+ const model = { groupOrder: [], groups: new Map(), segments: new Map() };
31
+ useCaptionStore.setState({
32
+ model: model as unknown as CaptionModel,
33
+ sourceFilePath: "index.html",
34
+ });
35
+
36
+ await act(async () => {
37
+ useCaptionStore.getState().retrySave?.();
38
+ await vi.waitFor(() => expect(useCaptionStore.getState().syncError).not.toBeNull());
39
+ });
40
+
41
+ expect(useCaptionStore.getState().syncError).toBe(words);
42
+ await act(async () => root.unmount());
43
+ useCaptionStore.setState({ model: null, sourceFilePath: null, syncError: null });
44
+ });
45
+ });
@@ -6,6 +6,7 @@ import { trackEvent } from "../../telemetry/client";
6
6
  import type { CaptionStyle } from "../types";
7
7
  import { studioWriteHeaders } from "../../utils/studioFileVersion";
8
8
  import { studioApiFetch } from "../../utils/studioApiFetch";
9
+ import { heldFileWordsOf } from "../../utils/studioSaveDiagnostics";
9
10
 
10
11
  interface CaptionOverrideEntry {
11
12
  wordId?: string;
@@ -93,6 +94,7 @@ export function useCaptionSync(projectId: string | null) {
93
94
 
94
95
  const seqAtSave = editSeqRef.current;
95
96
  const overrides = buildOverrides(state.model);
97
+ let held: string | null = null;
96
98
 
97
99
  studioApiFetch(
98
100
  buildProjectApiPath(pid, `/files/${encodeURIComponent("caption-overrides.json")}`),
@@ -102,8 +104,11 @@ export function useCaptionSync(projectId: string | null) {
102
104
  body: JSON.stringify(overrides, null, 2),
103
105
  },
104
106
  )
105
- .then((res) => {
106
- if (!res.ok) throw new Error(`HTTP ${res.status}`);
107
+ .then(async (res) => {
108
+ if (!res.ok) {
109
+ held = await heldFileWordsOf(res, "caption-overrides.json");
110
+ throw new Error(`HTTP ${res.status}`);
111
+ }
107
112
  // A newer edit may have re-armed the debounce while this PUT was in
108
113
  // flight — its beforeunload/unmount flush still needs pending=true.
109
114
  if (editSeqRef.current === seqAtSave) pendingRef.current = false;
@@ -114,7 +119,7 @@ export function useCaptionSync(projectId: string | null) {
114
119
  // Caption auto-save is a data-loss path: surface it to the user, not
115
120
  // just telemetry. pendingRef stays true so beforeunload still warns.
116
121
  trackEvent("studio_caption_autosave_failed", { error: String(error) });
117
- useCaptionStore.getState().setSyncError("Caption changes couldn't be saved");
122
+ useCaptionStore.getState().setSyncError(held ?? "Caption changes couldn't be saved");
118
123
  });
119
124
  }, []);
120
125
 
@@ -1,5 +1,6 @@
1
1
  import { studioWriteHeaders } from "../utils/studioFileVersion";
2
2
  import { studioApiFetch } from "../utils/studioApiFetch";
3
+ import { heldFileWordsOf } from "../utils/studioSaveDiagnostics";
3
4
 
4
5
  export class GsapPreviewConvergenceError extends Error {}
5
6
  export class GsapOwnershipProtocolError extends GsapPreviewConvergenceError {}
@@ -41,7 +42,9 @@ export async function rollbackOwnedMutation(
41
42
  },
42
43
  );
43
44
  if (!response.ok) {
44
- throw new Error(`Failed to restore ${targetPath}`);
45
+ throw new Error(
46
+ (await heldFileWordsOf(response, targetPath)) ?? `Failed to restore ${targetPath}`,
47
+ );
45
48
  }
46
49
  const result = (await response.json()) as { restored?: unknown; conflict?: unknown };
47
50
  if (result.restored === true && result.conflict === false) return "restored";
@@ -121,9 +124,10 @@ async function postOwnedGsapMutation(
121
124
  cause: error,
122
125
  });
123
126
  }
127
+ const held = response.ok ? null : await heldFileWordsOf(response, filePath);
124
128
  const payload: unknown = await response.json().catch(() => null);
125
129
  if (!response.ok) {
126
- throw new GsapPreviewConvergenceError(readMutationError(payload, fallback));
130
+ throw new GsapPreviewConvergenceError(held ?? readMutationError(payload, fallback));
127
131
  }
128
132
  return readMutationStatus(payload);
129
133
  }
@@ -82,6 +82,22 @@ describe("assignGsapTargetAutoIdIfNeeded", () => {
82
82
  expect(showToast).toHaveBeenCalledWith("Couldn't save edit: target not found", "error");
83
83
  });
84
84
 
85
+ it("names the file and why when the file is read-only", async () => {
86
+ stubPatch(
87
+ new Response(JSON.stringify({ error: "permission denied", why: "permission" }), {
88
+ status: 403,
89
+ headers: { "content-type": "application/json" },
90
+ }),
91
+ );
92
+ const { result, showToast } = assign();
93
+
94
+ await expect(result).resolves.toBeNull();
95
+ expect(showToast).toHaveBeenCalledWith(
96
+ "index.html can't be changed: it is read-only or protected. Check its permissions, then try again.",
97
+ "error",
98
+ );
99
+ });
100
+
85
101
  it("is null with a plain toast when the refusal has no JSON reason", async () => {
86
102
  stubPatch(new Response("boom", { status: 500, headers: { "content-type": "text/plain" } }));
87
103
  const { result, showToast } = assign();
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  createStudioSaveHttpError,
3
+ heldFileWordsOf,
3
4
  StudioSaveHttpError,
4
5
  trackStudioSaveFailure,
5
6
  } from "../utils/studioSaveDiagnostics";
@@ -195,7 +196,8 @@ export async function postPatchElement(
195
196
  },
196
197
  );
197
198
  if (!response.ok) {
198
- showToast(formatPatchRejectionMessage(await readErrorResponseBody(response)), "error");
199
+ const held = await heldFileWordsOf(response, targetPath);
200
+ showToast(held ?? formatPatchRejectionMessage(await readErrorResponseBody(response)), "error");
199
201
  throw await createStudioSaveHttpError(response, `Failed to patch ${targetPath}`, {
200
202
  alreadyToasted: true,
201
203
  });
@@ -172,6 +172,7 @@ export function useElementLifecycleOps({
172
172
  throw await createStudioSaveHttpError(
173
173
  removeResponse,
174
174
  `Failed to delete element from ${targetPath}`,
175
+ { path: targetPath },
175
176
  );
176
177
  }
177
178
  const removeData = (await removeResponse.json()) as {
@@ -57,6 +57,15 @@ describe("requestFreezeFrame", () => {
57
57
  requestFreezeFrame({ projectId: "p", path: "index.html", element, playhead: 7 }),
58
58
  ).rejects.toThrow("Move the playhead inside a video clip to freeze");
59
59
  });
60
+
61
+ it("names the file and why when the file is read-only", async () => {
62
+ stubFetch({ status: 403, body: { error: "permission denied", why: "permission" } });
63
+ await expect(
64
+ requestFreezeFrame({ projectId: "p", path: "scenes/intro.html", element, playhead: 7 }),
65
+ ).rejects.toThrow(
66
+ "intro.html can't be changed: it is read-only or protected. Check its permissions, then try again.",
67
+ );
68
+ });
60
69
  });
61
70
 
62
71
  describe("useFreezeFrame", () => {
@@ -7,6 +7,7 @@ import { markStudioWriteToken } from "../utils/studioFileVersion";
7
7
  import { serializeStudioFileMutations } from "../utils/studioFileMutationCoordinator";
8
8
  import type { RecordEditInput } from "../utils/studioFileHistory";
9
9
  import { studioApiFetch } from "../utils/studioApiFetch";
10
+ import { heldFileWordsOf } from "../utils/studioSaveDiagnostics";
10
11
 
11
12
  type ProjectFileWriter = (path: string, content: string, expectedContent?: string) => Promise<void>;
12
13
 
@@ -73,9 +74,10 @@ export async function requestFreezeFrame(input: {
73
74
  }),
74
75
  },
75
76
  );
77
+ const held = response.ok ? null : await heldFileWordsOf(response, input.path);
76
78
  const body: unknown = await response.json().catch(() => null);
77
79
  if (!response.ok || !isFreezeFrameResponse(body)) {
78
- throw new Error(errorOf(body) ?? `Freeze frame failed (${response.status})`);
80
+ throw new Error(held ?? errorOf(body) ?? `Freeze frame failed (${response.status})`);
79
81
  }
80
82
  return body;
81
83
  }
@@ -17,6 +17,7 @@ import {
17
17
  } from "../utils/studioHelpers";
18
18
  import type { TimelineElement } from "../player";
19
19
  import { studioApiFetch } from "../utils/studioApiFetch";
20
+ import { heldFileWordsOf } from "../utils/studioSaveDiagnostics";
20
21
 
21
22
  interface UseGroupCommitsParams extends DomEditCommitBaseParams {
22
23
  /** Resync the SDK session after a server-side write (the wrapper/unwrap changes
@@ -142,6 +143,8 @@ async function commitStructuralMutation(
142
143
  },
143
144
  );
144
145
  if (!mutateResponse.ok) {
146
+ const held = await heldFileWordsOf(mutateResponse, targetPath);
147
+ if (held) throw new Error(held);
145
148
  const errBody = (await mutateResponse.json().catch(() => null)) as {
146
149
  error?: string;
147
150
  } | null;
@@ -184,6 +184,32 @@ describe("useTimelineDeleteOps: ripple undo label", () => {
184
184
  ]);
185
185
  });
186
186
 
187
+ it.each([
188
+ [
189
+ 403,
190
+ "permission",
191
+ "index.html can't be changed: it is read-only or protected. Check its permissions, then try again.",
192
+ ],
193
+ [423, "busy", "index.html is open in another program. Close it there, then try again."],
194
+ ])("a delete the server refuses with %i names the file and why", async (status, why, words) => {
195
+ vi.stubGlobal(
196
+ "fetch",
197
+ vi.fn(async (input: RequestInfo | URL) =>
198
+ String(input).includes("/file-mutations/remove-elements/")
199
+ ? new Response(JSON.stringify({ error: "refused", why }), { status })
200
+ : new Response(JSON.stringify({ content: html }), { status: 200 }),
201
+ ),
202
+ );
203
+ const showToast = vi.fn();
204
+ const { b, getHook } = mountDeleteHarness({ handleTimelineGroupMove: vi.fn(), showToast });
205
+
206
+ await act(async () => {
207
+ await getHook().handleTimelineElementDelete(b);
208
+ });
209
+
210
+ expect(showToast.mock.calls.map(([message]) => message)).toEqual([words]);
211
+ });
212
+
187
213
  it("shows exactly one toast when a ripple fails to persist after a committed delete", async () => {
188
214
  const handleTimelineGroupMove = vi.fn().mockRejectedValue(new Error("persist failed"));
189
215
  const showToast = vi.fn();
@@ -26,6 +26,7 @@ import type {
26
26
  } from "./useTimelineGroupEditing";
27
27
  import { studioApiFetch } from "../utils/studioApiFetch";
28
28
  import { countOf } from "../utils/countOf";
29
+ import { heldFileWordsOf } from "../utils/studioSaveDiagnostics";
29
30
 
30
31
  /** Apply already-resolved ripple changes to the surviving elements for the
31
32
  * optimistic store update after a delete. Pure — no IO. */
@@ -141,7 +142,8 @@ export function useTimelineDeleteOps({
141
142
  );
142
143
  if (!removeResponse.ok) {
143
144
  throw new Error(
144
- `Failed to delete ${countOf(sameFile.length, "clip")} from ${targetPath}`,
145
+ (await heldFileWordsOf(removeResponse, targetPath)) ??
146
+ `Failed to delete ${countOf(sameFile.length, "clip")} from ${targetPath}`,
145
147
  );
146
148
  }
147
149
  const removeData = (await removeResponse.json()) as { content?: string };
@@ -58,6 +58,20 @@ function panelOf(trigger: HTMLButtonElement): HTMLElement {
58
58
  return document.getElementById(trigger.getAttribute("aria-controls")!)!;
59
59
  }
60
60
 
61
+ function pressQuestionMark(target: Element): KeyboardEvent {
62
+ const event = new KeyboardEvent("keydown", {
63
+ key: "?",
64
+ code: "Slash",
65
+ shiftKey: true,
66
+ bubbles: true,
67
+ cancelable: true,
68
+ });
69
+ act(() => {
70
+ target.dispatchEvent(event);
71
+ });
72
+ return event;
73
+ }
74
+
61
75
  describe("ShortcutsPanel", () => {
62
76
  it.each(["page", "button", "panel"] as const)(
63
77
  "closes with Escape from the %s-focused position",
@@ -93,6 +107,67 @@ describe("ShortcutsPanel", () => {
93
107
  },
94
108
  );
95
109
 
110
+ it("opens with ? and closes with ? again or Escape", () => {
111
+ const { trigger } = renderPanel();
112
+
113
+ pressQuestionMark(document.body);
114
+ expect(trigger.getAttribute("aria-expanded")).toBe("true");
115
+ expect(panelOf(trigger).textContent).toContain("Show / hide this panel");
116
+
117
+ pressQuestionMark(document.activeElement ?? document.body);
118
+ expect(trigger.getAttribute("aria-expanded")).toBe("false");
119
+
120
+ pressQuestionMark(document.body);
121
+ expect(trigger.getAttribute("aria-expanded")).toBe("true");
122
+ act(() => {
123
+ document.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }));
124
+ });
125
+ expect(trigger.getAttribute("aria-expanded")).toBe("false");
126
+ });
127
+
128
+ it("does not show the button's tooltip when ? opens the panel", async () => {
129
+ const { trigger } = renderPanel();
130
+
131
+ pressQuestionMark(document.body);
132
+ await act(async () => {
133
+ await new Promise((resolve) => setTimeout(resolve, 0));
134
+ });
135
+
136
+ expect(document.querySelector('[role="tooltip"]')).toBeNull();
137
+ expect(trigger.getAttribute("aria-describedby")).toBeNull();
138
+ });
139
+
140
+ it.each([
141
+ ["an input", () => document.createElement("input")],
142
+ ["a textarea", () => document.createElement("textarea")],
143
+ [
144
+ "a contenteditable",
145
+ () => {
146
+ const editable = document.createElement("div");
147
+ editable.contentEditable = "true";
148
+ return editable;
149
+ },
150
+ ],
151
+ ])("leaves ? to %s", (_, createField) => {
152
+ const field = createField();
153
+ document.body.append(field);
154
+ const { trigger } = renderPanel();
155
+
156
+ const event = pressQuestionMark(field);
157
+
158
+ expect(trigger.getAttribute("aria-expanded")).toBe("false");
159
+ expect(event.defaultPrevented).toBe(false);
160
+ });
161
+
162
+ it("leaves ? to the panel's own frame input while open", () => {
163
+ const { trigger } = renderPanel();
164
+ openPanel(trigger);
165
+
166
+ pressQuestionMark(document.querySelector<HTMLInputElement>('[aria-label="Jump to frame"]')!);
167
+
168
+ expect(trigger.getAttribute("aria-expanded")).toBe("true");
169
+ });
170
+
96
171
  it("closes on an outside press whose pointerdown a canvas gesture prevented", () => {
97
172
  const preventDefault = (event: Event) => event.preventDefault();
98
173
  document.addEventListener("pointerdown", preventDefault, true);
@@ -1,10 +1,11 @@
1
- import { useState, useCallback, useRef, memo } from "react";
1
+ import { useState, useCallback, useEffect, useRef, memo } from "react";
2
2
  import { formatTime, frameToSeconds } from "../lib/time";
3
3
  import { Popover, Tooltip } from "../../components/ui";
4
4
  import { flatActive, flatIdle } from "../../components/timelineToolbarStyles";
5
5
  import { usePlayerStore } from "../store/playerStore";
6
6
  import { useCompositionFps } from "../../utils/linkedClipPreferences";
7
- import { useShortcutSections, type ShortcutSection } from "./studioShortcuts";
7
+ import { matchesKey, useShortcutSections, type ShortcutSection } from "./studioShortcuts";
8
+ import { isTypingTarget } from "../../utils/typingTarget";
8
9
 
9
10
  interface ShortcutsPanelProps {
10
11
  disabled: boolean;
@@ -20,6 +21,21 @@ interface ShortcutsPanelProps {
20
21
  /** Stays above its button, shrinking to the room there, rather than flipping down over the timeline. */
21
22
  const STAY_ABOVE = { side: "none", align: "shift", fallbackAxisSide: "none" } as const;
22
23
 
24
+ function useShortcutsOpen() {
25
+ const [open, setOpen] = useState(false);
26
+ useEffect(() => {
27
+ const onKeyDown = (e: KeyboardEvent) => {
28
+ if (e.defaultPrevented || e.repeat || isTypingTarget(e.target)) return;
29
+ if (!matchesKey(e, "shortcuts")) return;
30
+ e.preventDefault();
31
+ setOpen((wasOpen) => !wasOpen);
32
+ };
33
+ document.addEventListener("keydown", onKeyDown);
34
+ return () => document.removeEventListener("keydown", onKeyDown);
35
+ }, []);
36
+ return [open, setOpen] as const;
37
+ }
38
+
23
39
  export const ShortcutsPanel = memo(function ShortcutsPanel({
24
40
  disabled,
25
41
  duration,
@@ -31,7 +47,7 @@ export const ShortcutsPanel = memo(function ShortcutsPanel({
31
47
  sections: hostSections,
32
48
  }: ShortcutsPanelProps) {
33
49
  const sections = useShortcutSections(hostSections);
34
- const [showShortcuts, setShowShortcuts] = useState(false);
50
+ const [showShortcuts, setShowShortcuts] = useShortcutsOpen();
35
51
  const [jumpFrame, setJumpFrame] = useState("");
36
52
  const compositionFps = useCompositionFps();
37
53
  // Focus lands on the scrolling body, not the frame input, so keyboard users can scroll and read it.
@@ -62,7 +78,7 @@ export const ShortcutsPanel = memo(function ShortcutsPanel({
62
78
  );
63
79
 
64
80
  return (
65
- <Tooltip label="Shortcuts and tools">
81
+ <Tooltip label="Shortcuts and tools" disabled={showShortcuts}>
66
82
  <Popover
67
83
  open={showShortcuts}
68
84
  onOpenChange={setShowShortcuts}
@@ -22,6 +22,7 @@ export const DEFAULT_STUDIO_KEYS = {
22
22
  snap: "s",
23
23
  grid: "g",
24
24
  timelineSnap: "n",
25
+ shortcuts: "?",
25
26
  playPause: "Space",
26
27
  frameBack: "ArrowLeft",
27
28
  frameForward: "ArrowRight",
@@ -189,6 +189,7 @@ export function buildShortcutSections(keys: StudioKeys): readonly ShortcutSectio
189
189
  hints: [
190
190
  { key: k("tabCompositions"), label: "Compositions tab" },
191
191
  { key: k("tabAssets"), label: "Assets tab" },
192
+ { key: k("shortcuts"), label: "Show / hide this panel" },
192
193
  ],
193
194
  },
194
195
  {
@@ -0,0 +1,169 @@
1
+ import { afterEach, describe, expect, it, vi } from "vitest";
2
+ import {
3
+ BufferSource,
4
+ BufferTarget,
5
+ EncodedPacket,
6
+ EncodedVideoPacketSource,
7
+ Input,
8
+ MP4,
9
+ Mp4OutputFormat,
10
+ Output,
11
+ } from "mediabunny";
12
+
13
+ class Bits {
14
+ private bits: number[] = [];
15
+ u(value: number, width: number) {
16
+ for (let i = width - 1; i >= 0; i--) this.bits.push((value >>> i) & 1);
17
+ return this;
18
+ }
19
+ ue(value: number) {
20
+ const width = Math.floor(Math.log2(value + 1));
21
+ return this.u(0, width).u(value + 1, width + 1);
22
+ }
23
+ rbsp(): number[] {
24
+ this.u(1, 1);
25
+ while (this.bits.length % 8) this.bits.push(0);
26
+ const bytes: number[] = [];
27
+ for (let i = 0; i < this.bits.length; i += 8) {
28
+ bytes.push(this.bits.slice(i, i + 8).reduce((byte, bit) => (byte << 1) | bit, 0));
29
+ }
30
+ return bytes;
31
+ }
32
+ }
33
+
34
+ function withEmulationPrevention(rbsp: number[]): number[] {
35
+ const out: number[] = [];
36
+ let zeros = 0;
37
+ for (const byte of rbsp) {
38
+ if (zeros >= 2 && byte <= 3) {
39
+ out.push(3);
40
+ zeros = 0;
41
+ }
42
+ out.push(byte);
43
+ zeros = byte === 0 ? zeros + 1 : 0;
44
+ }
45
+ return out;
46
+ }
47
+
48
+ /** A 64x64 SPS with one long-term reference picture and 4:3 pixels, the shape phone HEVC carries. */
49
+ function spsWithLongTermRefs(): number[] {
50
+ const b = new Bits()
51
+ .u(0, 4) // sps_video_parameter_set_id
52
+ .u(0, 3) // sps_max_sub_layers_minus1
53
+ .u(1, 1) // sps_temporal_id_nesting_flag
54
+ .u(0, 2)
55
+ .u(0, 1)
56
+ .u(1, 5) // Main profile
57
+ .u(0x60000000, 32)
58
+ .u(0b1001, 4)
59
+ .u(0, 32)
60
+ .u(0, 12)
61
+ .u(93, 8) // level 3.1
62
+ .ue(0) // sps_seq_parameter_set_id
63
+ .ue(1) // chroma_format_idc 4:2:0
64
+ .ue(64)
65
+ .ue(64)
66
+ .u(0, 1) // conformance_window_flag
67
+ .ue(0)
68
+ .ue(0)
69
+ .ue(4) // log2_max_pic_order_cnt_lsb_minus4: POC LSBs are 8 bits
70
+ .u(1, 1)
71
+ .ue(4)
72
+ .ue(2)
73
+ .ue(0)
74
+ .ue(0)
75
+ .ue(3)
76
+ .ue(0)
77
+ .ue(3)
78
+ .ue(0)
79
+ .ue(0)
80
+ .u(0, 1) // scaling_list_enabled_flag
81
+ .u(0, 1)
82
+ .u(0, 1)
83
+ .u(0, 1) // pcm_enabled_flag
84
+ .ue(0) // num_short_term_ref_pic_sets
85
+ .u(1, 1) // long_term_ref_pics_present_flag
86
+ .ue(1) // num_long_term_ref_pics_sps
87
+ .u(0, 8) // lt_ref_pic_poc_lsb_sps[0]: fixed-width, 8 bits here
88
+ .u(1, 1)
89
+ .u(1, 1)
90
+ .u(1, 1)
91
+ .u(1, 1) // vui_parameters_present_flag
92
+ .u(1, 1) // aspect_ratio_info_present_flag
93
+ .u(255, 8) // Extended_SAR
94
+ .u(4, 16)
95
+ .u(3, 16)
96
+ .u(0, 9) // the rest of the VUI absent
97
+ .u(0, 1); // sps_extension_present_flag
98
+ return [0x42, 0x01, ...withEmulationPrevention(b.rbsp())];
99
+ }
100
+
101
+ function hvcC(sps: number[]): Uint8Array {
102
+ return new Uint8Array([
103
+ 1,
104
+ 0x01,
105
+ 0x60,
106
+ 0,
107
+ 0,
108
+ 0,
109
+ 0x90,
110
+ 0,
111
+ 0,
112
+ 0,
113
+ 0,
114
+ 0,
115
+ 93,
116
+ 0xf0,
117
+ 0,
118
+ 0xfc,
119
+ 0xfd,
120
+ 0xf8,
121
+ 0xf8,
122
+ 0,
123
+ 0,
124
+ 0x0f,
125
+ 1,
126
+ 0x80 | 33,
127
+ 0,
128
+ 1,
129
+ sps.length >> 8,
130
+ sps.length & 0xff,
131
+ ...sps,
132
+ ]);
133
+ }
134
+
135
+ async function anamorphicHevcMp4(): Promise<ArrayBuffer> {
136
+ const output = new Output({ format: new Mp4OutputFormat(), target: new BufferTarget() });
137
+ const video = new EncodedVideoPacketSource("hevc");
138
+ output.addVideoTrack(video);
139
+ await output.start();
140
+ await video.add(new EncodedPacket(new Uint8Array(16), "key", 0, 1 / 30), {
141
+ decoderConfig: {
142
+ codec: "hvc1.1.6.L93.90",
143
+ codedWidth: 64,
144
+ codedHeight: 64,
145
+ description: hvcC(spsWithLongTermRefs()),
146
+ },
147
+ });
148
+ await output.finalize();
149
+ return output.target.buffer!;
150
+ }
151
+
152
+ describe("the HEVC SPS reader studio ships", () => {
153
+ afterEach(() => vi.restoreAllMocks());
154
+
155
+ it("keeps the pixel aspect ratio of HEVC that lists long-term reference pictures", async () => {
156
+ const errors = vi.spyOn(console, "error").mockImplementation(() => {});
157
+ const input = new Input({
158
+ source: new BufferSource(await anamorphicHevcMp4()),
159
+ formats: [MP4],
160
+ });
161
+ const track = await input.getPrimaryVideoTrack();
162
+
163
+ expect([await track!.getSquarePixelWidth(), await track!.getSquarePixelHeight()]).toEqual([
164
+ 85, 64,
165
+ ]);
166
+ expect(errors).not.toHaveBeenCalled();
167
+ input.dispose();
168
+ });
169
+ });