@hyperframes/studio 0.8.51 → 0.8.52

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 (99) hide show
  1. package/dist/assets/{hyperframes-player-Cn_PpHqP.js → hyperframes-player-I5YRzB02.js} +1 -1
  2. package/dist/assets/{index-Clrb11lj.js → index-BTAfgesM.js} +1 -1
  3. package/dist/assets/index-CxAu_Okg.css +1 -0
  4. package/dist/assets/index-DocJlW2v.js +376 -0
  5. package/dist/assets/{index-CPS3Cvj8.js → index-Du5x7KUR.js} +1 -1
  6. package/dist/index.d.ts +401 -7
  7. package/dist/index.html +2 -2
  8. package/dist/index.js +6545 -5869
  9. package/dist/index.js.map +1 -1
  10. package/package.json +9 -7
  11. package/src/App.tsx +3 -2
  12. package/src/captions/components/CaptionOverlay.sender.test.tsx +52 -0
  13. package/src/captions/components/CaptionOverlay.tsx +8 -4
  14. package/src/components/EditorShell.tsx +4 -0
  15. package/src/components/RightPanelTabs.test.tsx +151 -0
  16. package/src/components/RightPanelTabs.tsx +59 -0
  17. package/src/components/StudioHeader.dom.test.tsx +181 -0
  18. package/src/components/StudioHeader.tsx +109 -149
  19. package/src/components/StudioRightPanel.tsx +47 -35
  20. package/src/components/TimelineHistoryButtons.dom.test.tsx +117 -0
  21. package/src/components/TimelineHistoryButtons.tsx +54 -0
  22. package/src/components/TimelineToolbar.test.tsx +8 -0
  23. package/src/components/TimelineToolbar.tsx +3 -7
  24. package/src/components/dock/Dock.test.tsx +84 -16
  25. package/src/components/dock/Dock.tsx +19 -2
  26. package/src/components/dock/dock.css +5 -0
  27. package/src/components/dock/dockAccessibility.test.ts +166 -0
  28. package/src/components/dock/dockAccessibility.ts +98 -0
  29. package/src/components/dock/dockLayout.test.ts +134 -0
  30. package/src/components/dock/dockLayout.ts +53 -6
  31. package/src/components/dock/dockTestHarness.ts +11 -0
  32. package/src/components/editor/LayersPanel.test.ts +97 -1
  33. package/src/components/editor/LayersPanel.tsx +4 -2
  34. package/src/components/editor/PreviewGuides.tsx +1 -1
  35. package/src/components/editor/TopologyLens.test.tsx +28 -0
  36. package/src/components/editor/TopologyLens.tsx +3 -1
  37. package/src/components/editor/useColorGradingController.test.ts +38 -0
  38. package/src/components/editor/useColorGradingController.ts +9 -1
  39. package/src/components/editor/useColorGradingPreviews.test.ts +76 -0
  40. package/src/components/editor/useColorGradingPreviews.ts +11 -1
  41. package/src/components/editor/usePreviewCompositionRect.test.tsx +95 -0
  42. package/src/components/editor/usePreviewCompositionRect.ts +21 -0
  43. package/src/components/nle/NLEPreview.tsx +1 -1
  44. package/src/components/nle/PreviewPane.tsx +1 -1
  45. package/src/components/pointerTargetSize.test.tsx +8 -0
  46. package/src/components/renders/RenderQueue.tsx +1 -1
  47. package/src/components/timelineToolbarStyles.ts +5 -0
  48. package/src/components/ui/Button.test.tsx +222 -30
  49. package/src/components/ui/Button.tsx +88 -125
  50. package/src/components/ui/IconButton.tsx +38 -0
  51. package/src/components/ui/Input.tsx +115 -0
  52. package/src/components/ui/Menu.test.tsx +374 -0
  53. package/src/components/ui/Menu.tsx +213 -0
  54. package/src/components/ui/NumberField.tsx +122 -0
  55. package/src/components/ui/Popover.tsx +74 -0
  56. package/src/components/ui/Select.tsx +100 -0
  57. package/src/components/ui/Slider.tsx +153 -0
  58. package/src/components/ui/Tabs.test.tsx +98 -0
  59. package/src/components/ui/Tabs.tsx +71 -0
  60. package/src/components/ui/Toggle.tsx +63 -0
  61. package/src/components/ui/Tooltip.test.tsx +110 -0
  62. package/src/components/ui/Tooltip.tsx +38 -112
  63. package/src/components/ui/cn.test.ts +30 -0
  64. package/src/components/ui/cn.ts +25 -0
  65. package/src/components/ui/index.ts +29 -2
  66. package/src/components/ui/mountHost.testHelpers.ts +24 -0
  67. package/src/components/ui/valueControls.test.tsx +524 -0
  68. package/src/hooks/useAppHotkeys.ts +20 -79
  69. package/src/hooks/useCaptionDetection.sender.test.tsx +46 -0
  70. package/src/hooks/useCaptionDetection.ts +3 -1
  71. package/src/hooks/useEditHistoryActions.test.tsx +90 -0
  72. package/src/hooks/useEditHistoryActions.ts +106 -0
  73. package/src/hooks/useServerConnection.hashProject.test.tsx +94 -0
  74. package/src/hooks/useServerConnection.ts +43 -10
  75. package/src/index.ts +51 -0
  76. package/src/player/components/AutomationSelectionMenu.tsx +1 -1
  77. package/src/player/components/TimelineCanvas.tsx +4 -4
  78. package/src/player/components/TimelineClip.tsx +0 -1
  79. package/src/player/lib/playbackShortcuts.ts +2 -0
  80. package/src/player/store/previewIframeStore.notify.test.tsx +75 -0
  81. package/src/player/store/previewIframeStore.test.tsx +29 -0
  82. package/src/player/store/previewIframeStore.ts +25 -0
  83. package/src/renderQueueExports.test.tsx +58 -0
  84. package/src/styles/classCandidates.test.ts +105 -0
  85. package/src/styles/classCandidates.ts +281 -0
  86. package/src/styles/hex-baseline.json +84 -0
  87. package/src/styles/hexRatchet.test.ts +201 -0
  88. package/src/styles/styleSources.test.ts +20 -0
  89. package/src/styles/styleSources.ts +47 -0
  90. package/src/styles/theme.css +30 -0
  91. package/src/styles/theme.test.ts +2 -15
  92. package/src/styles/tokenGate.test.ts +109 -0
  93. package/src/utils/sourcePatcher.ts +1 -1
  94. package/src/utils/studioHelpers.test.ts +18 -0
  95. package/src/utils/studioHelpers.ts +11 -1
  96. package/src/utils/typingTarget.ts +4 -0
  97. package/dist/assets/index-C05SNrvY.js +0 -360
  98. package/dist/assets/index-DUR9qzQM.css +0 -1
  99. package/src/components/PanelTabButton.tsx +0 -31
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/studio",
3
- "version": "0.8.51",
3
+ "version": "0.8.52",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -30,6 +30,7 @@
30
30
  "access": "public"
31
31
  },
32
32
  "dependencies": {
33
+ "@base-ui/react": "1.7.0",
33
34
  "@codemirror/autocomplete": "^6.20.1",
34
35
  "@codemirror/commands": "^6.10.3",
35
36
  "@codemirror/lang-css": "^6.3.1",
@@ -45,14 +46,15 @@
45
46
  "@phosphor-icons/react": "^2.1.10",
46
47
  "@tanstack/react-virtual": "^3.14.6",
47
48
  "bpm-detective": "^2.0.5",
49
+ "cn": "0.2.4",
48
50
  "dockview-react": "8.3.1",
49
51
  "gsap": "^3.13.0",
50
52
  "mediabunny": "^1.45.3",
51
- "@hyperframes/core": "0.8.51",
52
- "@hyperframes/player": "0.8.51",
53
- "@hyperframes/studio-server": "0.8.51",
54
- "@hyperframes/sdk": "0.8.51",
55
- "@hyperframes/parsers": "0.8.51"
53
+ "@hyperframes/core": "0.8.52",
54
+ "@hyperframes/player": "0.8.52",
55
+ "@hyperframes/sdk": "0.8.52",
56
+ "@hyperframes/parsers": "0.8.52",
57
+ "@hyperframes/studio-server": "0.8.52"
56
58
  },
57
59
  "devDependencies": {
58
60
  "@tailwindcss/vite": "^4.3.3",
@@ -68,7 +70,7 @@
68
70
  "vite": "^6.4.2",
69
71
  "vitest": "^4.1.11",
70
72
  "zustand": "^5.0.0",
71
- "@hyperframes/producer": "0.8.51"
73
+ "@hyperframes/producer": "0.8.52"
72
74
  },
73
75
  "peerDependencies": {
74
76
  "react": "19",
package/src/App.tsx CHANGED
@@ -1,3 +1,4 @@
1
+ import { useOwnPreviewIframe, usePreviewIframeStore } from "./player/store/previewIframeStore";
1
2
  import { buildProjectApiPath } from "./utils/projectRouting";
2
3
  import { useState, useCallback, useRef, useMemo, useLayoutEffect } from "react";
3
4
  import type { LeftSidebarHandle, SidebarTab } from "./components/sidebar/LeftSidebar";
@@ -68,7 +69,7 @@ export function StudioApp() {
68
69
  const initialUrlStateRef = useRef(readStudioUrlStateFromWindow());
69
70
  useStudioSessionStart(projectId, resolving, waitingForServer);
70
71
  const [compIdToSrc, setCompIdToSrc] = useState<Map<string, string>>(new Map());
71
- const [previewIframe, setPreviewIframe] = useState<HTMLIFrameElement | null>(null);
72
+ const previewIframe = useOwnPreviewIframe();
72
73
  const [compositionLoading, setCompositionLoading] = useState(true);
73
74
  const [refreshKey, setRefreshKey] = useState(0);
74
75
  const [previewDocumentVersion, refreshPreviewDocumentVersion] = usePreviewDocumentVersion();
@@ -359,7 +360,7 @@ export function StudioApp() {
359
360
  const handlePreviewIframeRef = useCallback(
360
361
  (iframe: HTMLIFrameElement | null) => {
361
362
  previewIframeRef.current = iframe;
362
- setPreviewIframe(iframe);
363
+ usePreviewIframeStore.getState().setIframe(iframe);
363
364
  appHotkeys.syncPreviewHotkeys(iframe);
364
365
  resetConsoleErrors();
365
366
  refreshPreviewDocumentVersion();
@@ -4,6 +4,7 @@ import { createRoot } from "react-dom/client";
4
4
  import { expect, it, vi } from "vitest";
5
5
  import { CaptionOverlay } from "./CaptionOverlay";
6
6
  import { useCaptionStore } from "../store";
7
+ import { usePreviewIframeStore } from "../../player/store/previewIframeStore";
7
8
 
8
9
  Reflect.set(globalThis, "IS_REACT_ACT_ENVIRONMENT", true);
9
10
 
@@ -45,3 +46,54 @@ it("only schedules caption layout for messages from its preview", () => {
45
46
  vi.unstubAllGlobals();
46
47
  }
47
48
  });
49
+
50
+ it("observes and accepts messages from the promoted iframe, not the old one", () => {
51
+ const host = document.createElement("div");
52
+ const a = document.createElement("iframe");
53
+ const b = document.createElement("iframe");
54
+ document.body.append(host, a, b);
55
+ const ref = { current: a };
56
+ const root = createRoot(host);
57
+ const schedule = vi.fn(() => 1);
58
+ const observed: Element[] = [];
59
+ vi.stubGlobal("requestAnimationFrame", schedule);
60
+ vi.stubGlobal("cancelAnimationFrame", vi.fn());
61
+ vi.stubGlobal(
62
+ "ResizeObserver",
63
+ class {
64
+ observe(el: Element) {
65
+ observed.push(el);
66
+ }
67
+ disconnect() {}
68
+ },
69
+ );
70
+ useCaptionStore.getState().setEditMode(true);
71
+ const send = (source: MessageEventSource | null) =>
72
+ act(() => {
73
+ window.dispatchEvent(new MessageEvent("message", { source, data: { source: "hf-preview" } }));
74
+ });
75
+ try {
76
+ act(() => usePreviewIframeStore.getState().setIframe(a));
77
+ act(() => root.render(<CaptionOverlay iframeRef={ref} />));
78
+ expect(observed).toContain(a);
79
+ expect(observed).not.toContain(b);
80
+ act(() => {
81
+ ref.current = b;
82
+ usePreviewIframeStore.getState().setIframe(b);
83
+ });
84
+ expect(observed).toContain(b);
85
+ schedule.mockClear();
86
+ send(a.contentWindow);
87
+ expect(schedule).not.toHaveBeenCalled();
88
+ send(b.contentWindow);
89
+ expect(schedule).toHaveBeenCalledOnce();
90
+ } finally {
91
+ act(() => root.unmount());
92
+ usePreviewIframeStore.setState({ iframe: null });
93
+ useCaptionStore.getState().reset();
94
+ host.remove();
95
+ a.remove();
96
+ b.remove();
97
+ vi.unstubAllGlobals();
98
+ }
99
+ });
@@ -1,7 +1,7 @@
1
- import { memo, useState, useCallback, useRef } from "react";
1
+ import { memo, useEffect, useState, useCallback, useRef } from "react";
2
+ import { useLivePreviewIframe } from "../../player/store/previewIframeStore";
2
3
  import { useCaptionStore } from "../store";
3
4
  import { usePlayerStore } from "../../player";
4
- import { useMountEffect } from "../../hooks/useMountEffect";
5
5
  import { shouldHandleCaptionNudgeKey, isEditableEventTarget } from "../keyboard";
6
6
  import {
7
7
  readWordBoxes,
@@ -32,6 +32,7 @@ function syncToStore(segmentId: string, el: HTMLElement, iframeWin: Window) {
32
32
 
33
33
  export const CaptionOverlay = memo(function CaptionOverlay({ iframeRef }: CaptionOverlayProps) {
34
34
  const isEditMode = useCaptionStore((s) => s.isEditMode);
35
+ const livePreviewIframe = useLivePreviewIframe();
35
36
  const model = useCaptionStore((s) => s.model);
36
37
  const selectedSegmentIds = useCaptionStore((s) => s.selectedSegmentIds);
37
38
  const selectSegment = useCaptionStore((s) => s.selectSegment);
@@ -81,7 +82,9 @@ export const CaptionOverlay = memo(function CaptionOverlay({ iframeRef }: Captio
81
82
  | null
82
83
  >(null);
83
84
 
84
- useMountEffect(() => {
85
+ // The observer and message filter bind to the live iframe element, which a promoted reload replaces.
86
+ // eslint-disable-next-line no-restricted-syntax
87
+ useEffect(() => {
85
88
  if (!isEditMode) return;
86
89
 
87
90
  // Let undo/redo (useAppHotkeys) reapply restored models to this iframe.
@@ -240,7 +243,8 @@ export const CaptionOverlay = memo(function CaptionOverlay({ iframeRef }: Captio
240
243
  window.removeEventListener("keydown", handleKeyDown);
241
244
  cancelDragRef.current = null;
242
245
  };
243
- });
246
+ // eslint-disable-next-line react-hooks/exhaustive-deps
247
+ }, [livePreviewIframe]);
244
248
 
245
249
  const getCssScale = useCallback(() => {
246
250
  const iframe = iframeRef.current;
@@ -65,6 +65,10 @@ export interface EditorShellProps extends TimelineEditCallbackDeps {
65
65
  isGestureRecording?: boolean;
66
66
  recordingState?: GestureRecordingState;
67
67
  onToggleRecording?: () => void;
68
+ /**
69
+ * Host layer over the preview, positioned with `usePreviewCompositionRect`. Hidden in
70
+ * fullscreen and during a block preview; below the selection overlay past z-index 10.
71
+ */
68
72
  gestureOverlay?: ReactNode;
69
73
  }
70
74
 
@@ -0,0 +1,151 @@
1
+ // @vitest-environment happy-dom
2
+
3
+ /**
4
+ * The strip's keyboard behaviour, which tab reads as selected, and how the hotkey
5
+ * filters classify the elements (KTD13). The arrow-key tests are new behaviour, not a port.
6
+ */
7
+ import React, { act } from "react";
8
+ import { createRoot, type Root } from "react-dom/client";
9
+ import { afterEach, expect, it, vi } from "vitest";
10
+ import { RightPanelTabs, type RightPanelTabDescriptor } from "./RightPanelTabs";
11
+ import { isTypingTarget } from "../utils/typingTarget";
12
+ import { shouldIgnorePlaybackShortcutTarget } from "../player/lib/playbackShortcuts";
13
+
14
+ (globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
15
+
16
+ const IDS = ["design", "layers", "renders", "variables"];
17
+
18
+ let mounted: { root: Root; host: HTMLElement } | null = null;
19
+
20
+ afterEach(() => {
21
+ if (!mounted) return;
22
+ const { root, host } = mounted;
23
+ mounted = null;
24
+ act(() => root.unmount());
25
+ host.remove();
26
+ });
27
+
28
+ /** The harness owns the active state too, so a selection moves as it does in the real panel. */
29
+ function mount(
30
+ initialActive: string[],
31
+ activateOnFocus = true,
32
+ ): {
33
+ host: HTMLElement;
34
+ selections: ReturnType<typeof vi.fn>;
35
+ } {
36
+ const selections = vi.fn();
37
+
38
+ function Harness() {
39
+ const [active, setActive] = React.useState(initialActive);
40
+ const tabs: RightPanelTabDescriptor[] = IDS.map((id) => ({
41
+ id,
42
+ label: id,
43
+ tooltip: `${id} tooltip`,
44
+ active: active.includes(id),
45
+ onSelect: () => {
46
+ selections(id);
47
+ setActive([id]);
48
+ },
49
+ }));
50
+ return <RightPanelTabs tabs={tabs} activateOnFocus={activateOnFocus} />;
51
+ }
52
+
53
+ const host = document.createElement("div");
54
+ document.body.append(host);
55
+ const root = createRoot(host);
56
+ mounted = { root, host };
57
+ act(() => root.render(<Harness />));
58
+ return { host, selections };
59
+ }
60
+
61
+ function tab(host: HTMLElement, id: string): HTMLElement {
62
+ const el = host.querySelector<HTMLElement>(`[data-tab-id="${id}"]`);
63
+ if (!el) throw new Error(`no tab for ${id}`);
64
+ return el;
65
+ }
66
+
67
+ function selected(host: HTMLElement): string | null {
68
+ return (
69
+ host.querySelector('[role="tab"][aria-selected="true"]')?.getAttribute("data-tab-id") ?? null
70
+ );
71
+ }
72
+
73
+ /** Base UI moves the roving tabindex synchronously and the focus one task later. */
74
+ async function arrow(key: string): Promise<void> {
75
+ const target = document.activeElement ?? document.body;
76
+ act(() => {
77
+ target.dispatchEvent(new KeyboardEvent("keydown", { key, bubbles: true, composed: true }));
78
+ });
79
+ await act(async () => {
80
+ await new Promise((resolve) => setTimeout(resolve, 0));
81
+ });
82
+ }
83
+
84
+ it("moves from Design to Layers with ArrowRight and asks the panel to switch", async () => {
85
+ const { host, selections } = mount(["design"]);
86
+ act(() => tab(host, "design").focus());
87
+
88
+ await arrow("ArrowRight");
89
+
90
+ expect(document.activeElement).toBe(tab(host, "layers"));
91
+ expect(selections).toHaveBeenCalledWith("layers");
92
+ });
93
+
94
+ it("only moves focus on an arrow key when selection would toggle a pane", async () => {
95
+ const { host, selections } = mount(["design"], false);
96
+ act(() => tab(host, "design").focus());
97
+
98
+ await arrow("ArrowRight");
99
+
100
+ expect(document.activeElement).toBe(tab(host, "layers"));
101
+ expect(selections).not.toHaveBeenCalled();
102
+ });
103
+
104
+ it("jumps to the first and last tab with Home and End", async () => {
105
+ const { host, selections } = mount(["design"]);
106
+ act(() => tab(host, "design").focus());
107
+
108
+ await arrow("End");
109
+ expect(document.activeElement).toBe(tab(host, "variables"));
110
+ expect(selections).toHaveBeenLastCalledWith("variables");
111
+
112
+ await arrow("Home");
113
+ expect(document.activeElement).toBe(tab(host, "design"));
114
+ expect(selections).toHaveBeenLastCalledWith("design");
115
+ });
116
+
117
+ it("selects the tab whose content is on screen", () => {
118
+ const { host } = mount(["renders"]);
119
+
120
+ expect(selected(host)).toBe("renders");
121
+ });
122
+
123
+ it("leaves every tab unselected when the panel shows something the strip has no tab for", () => {
124
+ // Block params take over the panel body without a tab of their own. The old
125
+ // buttons all read unpressed in that state; nothing should read selected now.
126
+ const { host } = mount([]);
127
+
128
+ expect(selected(host)).toBe(null);
129
+ });
130
+
131
+ it("keeps a second open pane looking open in the legacy split inspector", () => {
132
+ // Design and Layers render together there. Only one tab can carry
133
+ // aria-selected, so the other has to keep the selected look or the strip
134
+ // would claim a pane is closed while it is on screen.
135
+ const { host } = mount(["design", "layers"]);
136
+
137
+ expect(selected(host)).toBe("design");
138
+ expect(tab(host, "layers").className).toContain("bg-hover");
139
+ });
140
+
141
+ it("classifies its tabs for the hotkey filters exactly as the old buttons did (KTD13)", () => {
142
+ // The old strip rendered plain <button>s: not a typing target, and claimed by
143
+ // the playback filter through its `button` selector. Base UI's tab is a
144
+ // <button> too, so both verdicts have to be unchanged.
145
+ const { host } = mount(["design"]);
146
+ const el = tab(host, "design");
147
+
148
+ expect(el.tagName).toBe("BUTTON");
149
+ expect(isTypingTarget(el)).toBe(false);
150
+ expect(shouldIgnorePlaybackShortcutTarget(el)).toBe(true);
151
+ });
@@ -0,0 +1,59 @@
1
+ /**
2
+ * The inspector tab strip on the shared Tabs primitive. The selected tab is derived from the
3
+ * panel's state; in the legacy split inspector two can be open, only one holds `aria-selected`.
4
+ */
5
+
6
+ import { Tab, Tabs, TabsList, Tooltip, cn } from "./ui";
7
+
8
+ export interface RightPanelTabDescriptor {
9
+ /** Stable id, also the `data-tab-id` attribute the strip is queried by. */
10
+ id: string;
11
+ label: string;
12
+ tooltip: string;
13
+ /** Whether this tab's content is on screen right now. */
14
+ active: boolean;
15
+ /** Run when the strip moves to this tab, by click or by arrow key. */
16
+ onSelect: () => void;
17
+ }
18
+
19
+ /** The look `aria-selected` gives the selected tab, for a second open pane. */
20
+ const SELECTED_LOOK = "bg-hover text-text-0";
21
+
22
+ export function RightPanelTabs({
23
+ tabs,
24
+ activateOnFocus = true,
25
+ }: {
26
+ tabs: readonly RightPanelTabDescriptor[];
27
+ /** False when `onSelect` toggles a pane, so an arrow key only moves focus. */
28
+ activateOnFocus?: boolean;
29
+ }) {
30
+ // `null` when the layout holds a tab this strip does not show (block params),
31
+ // which leaves every tab unselected, exactly as the old buttons did.
32
+ const value = tabs.find((tab) => tab.active)?.id ?? null;
33
+
34
+ return (
35
+ <Tabs
36
+ value={value}
37
+ onValueChange={(next) => {
38
+ tabs.find((tab) => tab.id === next)?.onSelect();
39
+ }}
40
+ >
41
+ <TabsList
42
+ aria-label="Inspector panels"
43
+ activateOnFocus={activateOnFocus}
44
+ className="flex min-w-0 items-center gap-1 overflow-hidden rounded-none border-b border-border-strong bg-transparent px-3 py-2"
45
+ >
46
+ {tabs.map((tab) => (
47
+ <Tooltip key={tab.id} label={tab.tooltip} side="bottom">
48
+ <Tab
49
+ value={tab.id}
50
+ className={cn("h-ctl-lg rounded-lg px-3 font-medium", tab.active && SELECTED_LOOK)}
51
+ >
52
+ {tab.label}
53
+ </Tab>
54
+ </Tooltip>
55
+ ))}
56
+ </TabsList>
57
+ </Tabs>
58
+ );
59
+ }
@@ -0,0 +1,181 @@
1
+ // @vitest-environment happy-dom
2
+
3
+ /**
4
+ * The header on the shared primitives: Capture and Inspector grouped, Export separate,
5
+ * hotkey filters unchanged (KTD13). Contexts are mocked, not provided.
6
+ */
7
+ import React, { act } from "react";
8
+ import { createRoot, type Root } from "react-dom/client";
9
+ import { afterEach, beforeEach, expect, it, vi } from "vitest";
10
+ import { buttonSizes, buttonVariants } from "./ui";
11
+ import { isTypingTarget } from "../utils/typingTarget";
12
+ import { shouldIgnorePlaybackShortcutTarget } from "../player/lib/playbackShortcuts";
13
+
14
+ (globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
15
+
16
+ const editHistory = {
17
+ canUndo: false,
18
+ canRedo: false,
19
+ undoLabel: undefined as string | undefined,
20
+ redoLabel: undefined as string | undefined,
21
+ };
22
+ const renderQueue = { isRendering: false, ffmpegMissing: false };
23
+
24
+ vi.mock("../contexts/StudioContext", () => ({
25
+ useStudioShellContext: () => ({
26
+ projectId: "demo",
27
+ editHistory,
28
+ handleUndo: vi.fn(),
29
+ handleRedo: vi.fn(),
30
+ renderQueue,
31
+ }),
32
+ }));
33
+
34
+ vi.mock("../contexts/PanelLayoutContext", () => ({
35
+ usePanelLayoutContext: () => ({
36
+ effectiveRightCollapsed: false,
37
+ setRightCollapsed: vi.fn(),
38
+ setRightPanelTab: vi.fn(),
39
+ }),
40
+ }));
41
+
42
+ vi.mock("../utils/studioTelemetry", () => ({ trackStudioEvent: vi.fn() }));
43
+
44
+ const { StudioHeader } = await import("./StudioHeader");
45
+
46
+ let mounted: { root: Root; host: HTMLElement } | null = null;
47
+
48
+ beforeEach(() => {
49
+ editHistory.canUndo = false;
50
+ editHistory.canRedo = false;
51
+ editHistory.undoLabel = undefined;
52
+ editHistory.redoLabel = undefined;
53
+ renderQueue.isRendering = false;
54
+ });
55
+
56
+ afterEach(() => {
57
+ if (!mounted) return;
58
+ const { root, host } = mounted;
59
+ mounted = null;
60
+ act(() => root.unmount());
61
+ host.remove();
62
+ });
63
+
64
+ function mount(props: { inspectorButtonActive?: boolean } = {}): HTMLElement {
65
+ const host = document.createElement("div");
66
+ document.body.append(host);
67
+ const root = createRoot(host);
68
+ mounted = { root, host };
69
+ act(() =>
70
+ root.render(
71
+ <StudioHeader
72
+ captureFrameHref="blob:frame"
73
+ captureFrameFilename="frame.png"
74
+ handleCaptureFrameClick={vi.fn()}
75
+ refreshCaptureFrameTime={vi.fn()}
76
+ inspectorButtonActive={props.inspectorButtonActive ?? false}
77
+ inspectorPanelActive={false}
78
+ />,
79
+ ),
80
+ );
81
+ return host;
82
+ }
83
+
84
+ function query(host: HTMLElement, selector: string): HTMLElement {
85
+ const el = host.querySelector<HTMLElement>(selector);
86
+ if (!el) throw new Error(`not rendered: ${selector}`);
87
+ return el;
88
+ }
89
+
90
+ /** Every class the recipe asks for, on the element the header rendered. */
91
+ function expectRecipe(el: HTMLElement, ...recipes: string[]): void {
92
+ const applied = new Set(el.className.split(/\s+/));
93
+ for (const recipe of recipes) {
94
+ for (const token of recipe.split(/\s+/)) {
95
+ expect(applied, `${token} missing from: ${el.className}`).toContain(token);
96
+ }
97
+ }
98
+ }
99
+
100
+ it("renders Export as the shared primary Button at the medium size", () => {
101
+ const host = mount();
102
+
103
+ expectRecipe(
104
+ query(host, '[data-testid="header-export"]'),
105
+ buttonVariants.primary,
106
+ buttonSizes.md,
107
+ );
108
+ });
109
+
110
+ it("no longer renders Undo or Redo in the header", () => {
111
+ const host = mount();
112
+
113
+ expect(host.querySelector('[aria-label="Undo"]')).toBeNull();
114
+ expect(host.querySelector('[aria-label="Redo"]')).toBeNull();
115
+ });
116
+
117
+ it("groups Capture and Inspector in one bordered segment, Export outside it", () => {
118
+ const host = mount();
119
+ const group = query(host, '[aria-label="Capture current frame"]').closest(".divide-x");
120
+
121
+ expect(group?.contains(query(host, '[aria-label="Inspector"]'))).toBe(true);
122
+ expect(group?.contains(query(host, '[data-testid="header-export"]'))).toBe(false);
123
+ expect(group).not.toBeNull();
124
+ });
125
+
126
+ it("drops the Capture label below 1000px but keeps its accessible name", () => {
127
+ const host = mount();
128
+ const capture = query(host, '[aria-label="Capture current frame"]');
129
+
130
+ expect(query(capture, "span").className).toContain("max-[1000px]:hidden");
131
+ });
132
+
133
+ /** The bare token, not a `hover:`/`data-[…]:`-prefixed variant of it. */
134
+ function hasToken(className: string, token: string): boolean {
135
+ return className.split(/\s+/).includes(token);
136
+ }
137
+
138
+ it("shows Inspector pressed and filled only when on", () => {
139
+ const host = mount({ inspectorButtonActive: true });
140
+ const on = query(host, '[aria-label="Inspector"]');
141
+ expect(on.getAttribute("aria-pressed")).toBe("true");
142
+ expect(hasToken(on.className, "text-accent")).toBe(true);
143
+ expect(hasToken(on.className, "bg-hover")).toBe(true);
144
+ act(() => mounted?.root.unmount());
145
+ mounted?.host.remove();
146
+ mounted = null;
147
+
148
+ const off = query(mount(), '[aria-label="Inspector"]');
149
+ expect(off.getAttribute("aria-pressed")).toBe("false");
150
+ expect(hasToken(off.className, "text-accent")).toBe(false);
151
+ expect(hasToken(off.className, "bg-hover")).toBe(false);
152
+ });
153
+
154
+ it("keeps Capture a real download link rather than a button", () => {
155
+ // `download` is what saves the frame. A Button here would render a <button>
156
+ // and the control would quietly stop downloading anything.
157
+ const host = mount();
158
+ const capture = query(host, '[aria-label="Capture current frame"]');
159
+
160
+ expect(capture.tagName).toBe("A");
161
+ expect(capture.getAttribute("download")).toBe("frame.png");
162
+ // h-full replaces the md height: the group's own h-ctl sets the shared control height.
163
+ expectRecipe(capture, "px-3", "text-step-12");
164
+ });
165
+
166
+ it("classifies the new header controls for the hotkey filters as the old ones were (KTD13)", () => {
167
+ // Every one of these was a <button> or an <a href> before the sweep: never a
168
+ // typing target, always claimed by the playback filter. A primitive that
169
+ // rendered a different element would leak or swallow hotkeys in silence.
170
+ const host = mount();
171
+ const controls = [
172
+ query(host, '[data-testid="header-export"]'),
173
+ query(host, '[aria-label="Inspector"]'),
174
+ query(host, '[aria-label="Capture current frame"]'),
175
+ ];
176
+
177
+ for (const el of controls) {
178
+ expect(isTypingTarget(el), el.getAttribute("aria-label") ?? el.tagName).toBe(false);
179
+ expect(shouldIgnorePlaybackShortcutTarget(el), el.tagName).toBe(true);
180
+ }
181
+ });